1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package com.hack23.cia.web.impl.ui.application.views.common.pagemode;
20
21 import org.apache.commons.lang3.StringUtils;
22 import org.springframework.security.access.annotation.Secured;
23 import org.springframework.stereotype.Component;
24
25 import com.ejt.vaadin.loginform.DefaultVerticalLoginForm;
26 import com.hack23.cia.model.internal.application.system.impl.ApplicationEventGroup;
27 import com.hack23.cia.service.api.action.application.LoginRequest;
28 import com.hack23.cia.web.impl.ui.application.action.ApplicationAction;
29 import com.hack23.cia.web.impl.ui.application.action.ViewAction;
30 import com.hack23.cia.web.impl.ui.application.views.common.viewnames.ApplicationPageMode;
31 import com.hack23.cia.web.impl.ui.application.views.common.viewnames.CommonsViews;
32 import com.hack23.cia.web.impl.ui.application.views.pageclicklistener.ApplicationLoginListener;
33 import com.vaadin.data.fieldgroup.BeanFieldGroup;
34 import com.vaadin.data.util.BeanItem;
35 import com.vaadin.server.FontAwesome;
36 import com.vaadin.ui.Field;
37 import com.vaadin.ui.Layout;
38 import com.vaadin.ui.MenuBar;
39 import com.vaadin.ui.Panel;
40 import com.vaadin.ui.VerticalLayout;
41
42
43
44
45 @Component
46 public final class MainViewLoginPageModContentFactoryImpl extends AbstractPageModContentFactoryImpl {
47
48
49 private static final String CITIZEN_INTELLIGENCE_AGENCY_MAIN = "Citizen Intelligence Agency::Main";
50
51
52 public static final String NAME = CommonsViews.MAIN_VIEW_NAME;
53
54
55
56
57 public MainViewLoginPageModContentFactoryImpl() {
58 super();
59 }
60
61 @Override
62 public boolean matches(final String page, final String parameters) {
63 return NAME.equals(page)
64 && (!StringUtils.isEmpty(parameters) && parameters.contains(ApplicationPageMode.LOGIN.toString()));
65 }
66
67 @Secured({ "ROLE_ANONYMOUS" })
68 @Override
69 public Layout createContent(final String parameters, final MenuBar menuBar, final Panel panel) {
70 final VerticalLayout content = createPanelContent();
71 final String pageId = getPageId(parameters);
72
73 panel.setCaption(CITIZEN_INTELLIGENCE_AGENCY_MAIN);
74
75 getMenuItemFactory().createMainPageMenuBar(menuBar);
76
77 final DefaultVerticalLoginForm loginForm = new EmailPasswordLoginForm();
78 final LoginRequest loginRequest = new LoginRequest();
79 loginRequest.setOtpCode("");
80 loginForm.addLoginListener(new ApplicationLoginListener(loginRequest));
81 loginForm.setId(ApplicationAction.LOGIN.toString());
82 loginForm.setIcon(FontAwesome.SIGN_IN);
83
84 final BeanFieldGroup<LoginRequest> fieldGroup = new BeanFieldGroup<>(LoginRequest.class);
85 fieldGroup.setItemDataSource(new BeanItem<>(loginRequest));
86 fieldGroup.setReadOnly(true);
87 fieldGroup.setBuffered(false);
88 final Field<?> buildAndBind = fieldGroup.buildAndBind("otpCode");
89 buildAndBind.setReadOnly(false);
90 content.addComponent(buildAndBind);
91
92 content.addComponent(loginForm);
93
94 panel.setCaption(CITIZEN_INTELLIGENCE_AGENCY_MAIN);
95 getPageActionEventHelper().createPageEvent(ViewAction.VISIT_MAIN_VIEW, ApplicationEventGroup.USER,
96 CommonsViews.MAIN_VIEW_NAME, parameters, pageId);
97
98
99 return content;
100
101 }
102
103 }