ref #7995 using updateStatusAndDate to set the registration status
[cdm-vaadin.git] / src / main / java / eu / etaxonomy / cdm / vaadin / view / LoginViewBean.java
1 /**
2 * Copyright (C) 2017 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
8 */
9 package eu.etaxonomy.cdm.vaadin.view;
10
11 import org.vaadin.spring.events.EventScope;
12
13 import com.vaadin.event.ShortcutAction.KeyCode;
14 import com.vaadin.navigator.View;
15 import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent;
16 import com.vaadin.spring.annotation.SpringView;
17 import com.vaadin.ui.Alignment;
18 import com.vaadin.ui.Button.ClickEvent;
19 import com.vaadin.ui.VerticalLayout;
20 import com.vaadin.ui.themes.ValoTheme;
21
22 import eu.etaxonomy.cdm.vaadin.component.LoginDialog;
23 import eu.etaxonomy.cdm.vaadin.event.AuthenticationAttemptEvent;
24 import eu.etaxonomy.cdm.vaadin.event.PasswordRevoveryEvent;
25 import eu.etaxonomy.cdm.vaadin.event.RegisterNewUserEvent;
26 import eu.etaxonomy.vaadin.mvp.AbstractView;
27 import eu.etaxonomy.vaadin.ui.navigation.NavigationEvent;
28
29 /**
30 * @author a.kohlbecker
31 * @since Apr 25, 2017
32 *
33 */
34 @SpringView(name=LoginViewBean.NAME)
35 public class LoginViewBean extends AbstractView<LoginPresenter> implements LoginView, View {
36
37 private static final long serialVersionUID = 8527714663738364972L;
38
39 public static final String NAME = "login";
40
41 private LoginDialog loginDialog = new LoginDialog();
42
43 public LoginViewBean() {
44 super();
45 }
46
47 @Override
48 protected void initContent() {
49 VerticalLayout root = new VerticalLayout();
50 root.setSizeFull();
51 root.addComponent(loginDialog);
52 root.setMargin(true);
53 root.setComponentAlignment(loginDialog, Alignment.MIDDLE_CENTER);
54 setCompositionRoot(root);
55
56 loginDialog.getLoginButton().addClickListener(e -> handleLoginClick(e));
57 loginDialog.getLoginButton().setClickShortcut(KeyCode.ENTER);
58 loginDialog.getRegisterButton().addClickListener(e -> getViewEventBus().publish(EventScope.UI, this, new RegisterNewUserEvent(e)));
59 loginDialog.getSendOnetimeLogin().addClickListener(e -> getViewEventBus().publish(EventScope.UI, this, new PasswordRevoveryEvent(e)));
60 // NOTE: null viewName will be replaced by the default view name in NavigationManagerBean
61 loginDialog.getCancelLoginButton().addClickListener(e -> getViewEventBus().publish(EventScope.UI, this, new NavigationEvent(null)));
62 loginDialog.getCancelRegistrationButton().addClickListener(e -> getViewEventBus().publish(EventScope.UI, this, new NavigationEvent(null)));
63 }
64
65 /**
66 * @param e
67 */
68 private void handleLoginClick(ClickEvent e) {
69 getViewEventBus().publish(EventScope.UI, this, new AuthenticationAttemptEvent(e, loginDialog.getUserName().getValue()));
70 }
71
72 @Override
73 public LoginDialog getLoginDialog(){
74 return loginDialog;
75 }
76
77 /**
78 * {@inheritDoc}
79 */
80 @Override
81 // TODO pull up to AbstractView and let AbstractView implement View?
82 public void enter(ViewChangeEvent event) {
83 getPresenter().onViewEnter();
84 }
85
86 @Override
87 public void showErrorMessage(String text){
88 loginDialog.getMessageLabel().setVisible(true);
89 loginDialog.getMessageLabel().setStyleName(ValoTheme.BUTTON_TINY + " " + ValoTheme.LABEL_FAILURE);
90 loginDialog.getMessageLabel().setValue(text);
91 }
92
93
94 @Override
95 public void clearMessage(){
96 loginDialog.getMessageLabel().setVisible(false);
97 loginDialog.getMessageLabel().setStyleName("");
98 loginDialog.getMessageLabel().setValue("");
99 }
100 }