Skip to content

Commit

Permalink
LoginPage. Easy login for Dev and ProfilePage (#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 15, 2023
1 parent a495f7a commit 57ec50c
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/main/java/pm/axe/ui/pages/user/ProfilePage.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import pm.axe.users.AccountType;

import java.util.List;
import java.util.Objects;
import java.util.Optional;

@SpringComponent
Expand All @@ -52,7 +53,11 @@ public class ProfilePage extends AxeCompactLayout implements BeforeEnterObserver
@Override
public void beforeEnter(BeforeEnterEvent event) {
if (event.isRefreshEvent()) return;
boundUserOrGoToLogin(event);
boundUserIfAny();
if (Objects.isNull(user)) {
event.forwardTo(LoginPage.class);
return;
}
confirmedAccounts = getConfirmedAccountsFor(user);

if (!pageAlreadyInitialized) {
Expand All @@ -73,7 +78,7 @@ private void initPage() {
Button editUsernameButton = new Button("Edit");
Button saveUsernameButton = new Button("Save");
FlexLayout usernameLayout = new FlexLayout(username, editUsernameButton);
usernameLayout.setAlignItems(FlexComponent.Alignment.CENTER);
usernameLayout.setAlignItems(FlexComponent.Alignment.BASELINE);
usernameLayout.setJustifyContentMode(FlexComponent.JustifyContentMode.AROUND);
//TODO replace with methods and fix button replace login - see MyLinksPage
editUsernameButton.addClickListener(e -> {
Expand All @@ -91,7 +96,7 @@ private void initPage() {

Button saveEmailButton = new Button("Save");
FlexLayout emailLayout = new FlexLayout(emailField, saveEmailButton);
emailLayout.setAlignItems(FlexComponent.Alignment.CENTER);
emailLayout.setAlignItems(Alignment.BASELINE);
emailLayout.setJustifyContentMode(FlexComponent.JustifyContentMode.AROUND);

//how Axe use email details
Expand Down Expand Up @@ -143,16 +148,12 @@ private void initPage() {
secondSeparator, tfaDetails);
}

private void boundUserOrGoToLogin(BeforeEnterEvent event) {
private void boundUserIfAny() {
Optional<AxeSession> axeSession = AxeSession.getCurrent();
if (axeSession.isPresent()) {
if (axeSession.get().hasUser()) {
user = axeSession.get().getUser();
} else {
event.forwardTo(Endpoint.UI.LOGIN_PAGE);
}
} else {
event.forwardTo(LoginPage.class);
}
}

Expand Down

0 comments on commit 57ec50c

Please sign in to comment.