Skip to content

Commit

Permalink
RegistrationPage (#998)
Browse files Browse the repository at this point in the history
Signed-off-by: Aleksandr Muravja <[email protected]>
  • Loading branch information
Aleksandr Muravja committed Jan 12, 2023
1 parent 5e06a01 commit 8d7d2f5
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 3 deletions.
8 changes: 6 additions & 2 deletions frontend/css/axe_form_styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
align-self: center;
}

.axe-form-subtitle {
padding-left: 1rem;
}
.space-after-submit-button {
width: 100%;
}
Expand All @@ -12,9 +15,10 @@
}

.axe-fields > * {
min-width: min(70vw, 300px);
min-width: 99%;
}

.space-after-fields {
max-width: min(70vw, 300px);
padding-left: 1rem;
max-width: 99%;
}
3 changes: 3 additions & 0 deletions frontend/css/registration_page.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.email-input {
min-width: 99%;
}
1 change: 0 additions & 1 deletion src/main/java/pm/axe/ui/layouts/AxeFormLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

@CssImport(value = "./css/axe_form_styles.css")
public class AxeFormLayout extends AxeBaseLayout {
protected static final String START_POINT = "1px";

private final VerticalLayout form = new VerticalLayout();
private final H2 formTitle = new H2();
Expand Down
118 changes: 118 additions & 0 deletions src/main/java/pm/axe/ui/pages/user/RegistrationPage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
package pm.axe.ui.pages.user;

import com.vaadin.flow.component.ClickEvent;
import com.vaadin.flow.component.button.Button;
import com.vaadin.flow.component.checkbox.Checkbox;
import com.vaadin.flow.component.dependency.CssImport;
import com.vaadin.flow.component.details.Details;
import com.vaadin.flow.component.html.Anchor;
import com.vaadin.flow.component.html.Label;
import com.vaadin.flow.component.html.Span;
import com.vaadin.flow.component.notification.Notification;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.component.textfield.EmailField;
import com.vaadin.flow.component.textfield.PasswordField;
import com.vaadin.flow.component.textfield.TextField;
import com.vaadin.flow.router.BeforeEnterEvent;
import com.vaadin.flow.router.BeforeEnterObserver;
import com.vaadin.flow.router.PageTitle;
import com.vaadin.flow.router.Route;
import com.vaadin.flow.spring.annotation.SpringComponent;
import com.vaadin.flow.spring.annotation.UIScope;
import lombok.RequiredArgsConstructor;
import pm.axe.Endpoint;
import pm.axe.ui.MainView;
import pm.axe.ui.layouts.AxeFormLayout;

@SpringComponent
@UIScope
@RequiredArgsConstructor
@CssImport(value = "./css/registration_page.css")
@Route(value = Endpoint.UI.REGISTRATION_PAGE, layout = MainView.class)
@PageTitle("Registration - Axe.pm")
public class RegistrationPage extends AxeFormLayout implements BeforeEnterObserver {

private final Span subTitleText = new Span();
private final Anchor subTitleLink = new Anchor();

private final TextField usernameEmailInput = new TextField();
private final PasswordField passwordInput = new PasswordField();

private final Details contactPointDetails = new Details();
private final EmailField emailField = new EmailField();

private final VerticalLayout tfaLayout = new VerticalLayout();
private final Label tfaLabel = new Label();
private final Checkbox tfaBox = new Checkbox();

private final Span tosNote = createLegalInfo();

private boolean pageAlreadyInitialized = false;

@Override
public void beforeEnter(BeforeEnterEvent beforeEnterEvent) {
if (beforeEnterEvent.isRefreshEvent()) return;
if (pageAlreadyInitialized) {
cleanInputs();
} else {
pageInit();
pageAlreadyInitialized = true;
}
}
private void pageInit() {
setCompactMode();
setFormTitle("Become Axe User");

subTitleText.setText("Already have an account? ");

subTitleLink.setText("Log in");
subTitleLink.setHref(Endpoint.UI.LOGIN_PAGE);

setFormSubTitle(subTitleText, subTitleLink);

usernameEmailInput.setLabel("Username/Email");
usernameEmailInput.setClearButtonVisible(true);
passwordInput.setLabel("Password");

emailField.setLabel("Email");
emailField.setClassName("email-input");
contactPointDetails.setSummaryText("Contact point (optional)");
contactPointDetails.setOpened(false);
contactPointDetails.addContent(emailField);

tfaBox.setId("tfaBox");
tfaBox.setLabel("Protect my account with additional one time codes");
tfaLabel.setText("Two-Factor Authentication (2FA)");
tfaLayout.setPadding(false);
tfaLayout.add(tfaLabel, tfaBox);

setFormFields(usernameEmailInput, passwordInput, contactPointDetails, tfaLayout);

setComponentsAfterFields(tosNote);
setSubmitButtonText("Sign up");

getSubmitButton().addClickListener(this::onRegister);
}

private void cleanInputs() {
usernameEmailInput.clear();
passwordInput.clear();
emailField.clear();
}

private void onRegister(final ClickEvent<Button> event) {
Notification.show("Not implemented yet");
}

private Span createLegalInfo() {
Span tosStart = new Span("By signing up, you accept our ");
Anchor linkToTerms = new Anchor();
//TODO correct location when ready
linkToTerms.setHref(Endpoint.UI.APP_INFO_PAGE);
linkToTerms.setText("Terms of Service");

Span tosEnd = new Span(".");

return new Span(tosStart, linkToTerms, tosEnd);
}
}

0 comments on commit 8d7d2f5

Please sign in to comment.