BrightSide Workbench Full Report + Source Code
SignInFromListComposer.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2015 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 package org.turro.signin;
20 
21 import java.io.IOException;
22 import java.util.logging.Level;
23 import java.util.logging.Logger;
24 import org.turro.action.Contacts;
25 import org.turro.auth.Authentication;
26 import org.turro.command.Command;
27 import org.turro.elephant.context.ElephantContext;
28 import org.turro.elephant.zkoss.Modal;
29 import org.turro.log.SystemLogType;
30 import org.turro.log.SystemLogger;
31 import org.turro.plugin.contacts.IContact;
32 import org.zkoss.lang.Strings;
33 import org.zkoss.zk.ui.Component;
34 import org.zkoss.zk.ui.Executions;
35 import org.zkoss.zk.ui.event.Event;
36 import org.zkoss.zk.ui.event.InputEvent;
37 import org.zkoss.zk.ui.select.SelectorComposer;
38 import org.zkoss.zk.ui.select.annotation.Listen;
39 import org.zkoss.zk.ui.select.annotation.Wire;
40 import org.zkoss.zul.A;
41 import org.zkoss.zul.Listbox;
42 import org.zkoss.zul.Panel;
43 import org.zkoss.zul.Textbox;
44 
49 @Deprecated
50 public class SignInFromListComposer extends SelectorComposer<Component> {
51 
52  private String onSignin, onSignout;
53 
54  @Wire("#signinform")
55  private Panel siginform;
56 
57  @Wire("#contacts")
58  private Listbox contacts;
59 
60  @Wire("#password")
61  private Textbox password;
62 
63  @Wire("#signoutform")
64  private Panel signoutform;
65 
66  @Wire("#profile")
67  private A profile;
68 
69  @Listen("onChanging = #user")
70  public void onChangingUser(InputEvent evt) throws IOException {
71  }
72 
73  @Listen("onOK = #signinform; onClick = #signin")
74  public void onSigIn() {
75  if(Strings.isBlank(password.getText())) {
76  password.setFocus(true);
77  } else {
78  IContact contact = Contacts.getContact(contacts.getSelectedItem().getValue());
79  try {
80  Authentication.doLogin(contact.getEmail(), password.getText(), onSignin, null);
81  } catch (IOException ex) {
82  Logger.getLogger(SignInComposer.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
83  }
84  }
85  }
86 
87  @Listen("onClick = #signout")
88  public void onSigOut() {
89  try {
90  Authentication.doLogout(onSignout);
91  } catch (IOException ex) {
92  Logger.getLogger(SignInComposer.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(null), ex);
93  }
94  }
95 
96  @Listen("onClick = #profile")
97  public void onProfile(Event event) throws IOException, InterruptedException {
98  SystemLogger.getInstance().doLog(SystemLogType.LOG_INFO, "/log/profile", null, null);
99  Modal.doModal("/WEB-INF/_zul/www/profile.zul", (Command) null);
100  }
101 
102  @Override
103  public void doFinally() throws Exception {
104  super.doFinally();
105  IContact contact = Authentication.getIContact();
106  onSignin = Executions.getCurrent().getParameter("onSignin");
107  onSignout = Executions.getCurrent().getParameter("onSignout");
108  if(contact == null || !contact.isValid()) {
109  siginform.setVisible(true);
110  contacts.setFocus(true);
111  } else {
112  signoutform.setVisible(true);
113  }
114  }
115 
116 }
static IContact getContact(Object object)
Definition: Contacts.java:109
static void doLogout(String redir)
static void doLogin(String login, String pass, String redir, Object extra)
static int doModal(String file)
Definition: Modal.java:38
static ISystemLogger getInstance()
void doLog(SystemLogType type, Object entity, String comment, Serializable data)