BrightSide Workbench Full Report + Source Code
PasswordControl.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2019 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.auth;
20 
21 import java.io.IOException;
22 import org.turro.string.Strings;
23 import org.turro.elephant.TemplateControl;
24 import org.turro.elephant.context.Application;
25 import org.turro.elephant.web.ElContext;
26 import org.turro.elephant.zkoss.ZkossElephant;
27 import org.turro.i18n.I_;
28 import org.turro.plugin.contacts.IContact;
29 import org.turro.sso.SSO;
30 import org.turro.util.PasswordStrength;
31 import org.zkoss.zk.ui.Executions;
32 import org.zkoss.zk.ui.event.InputEvent;
33 import org.zkoss.zk.ui.select.annotation.Listen;
34 import org.zkoss.zk.ui.select.annotation.Wire;
35 import org.zkoss.zk.ui.util.Clients;
36 import org.zkoss.zul.Progressmeter;
37 import org.zkoss.zul.Textbox;
38 
43 public class PasswordControl extends TemplateControl {
44 
45  private String redir;
46 
47  @Wire("#password")
48  private Textbox password;
49 
50  @Wire("#repeatpass")
51  private Textbox repeatpass;
52 
53  @Wire("#strength")
54  private Progressmeter strength;
55 
56  @Listen("onChanging = #password")
57  public void onChangingPassword(InputEvent evt) throws IOException {
58  strength.setValue(PasswordStrength.checkStrength(evt.getValue()));
59  }
60 
61  @Listen("onClick = #change")
62  public void onChange() {
63  if(!Strings.isBlank(password.getValue()) && password.getValue().equals(repeatpass.getValue())) {
65  contact.setPassword(password.getText(), repeatpass.getText());
66  contact.applyChanges();
67  if(!SSO.hasSSO() && "true".equals(ZkossElephant.getCookieValue("xp_storepass"))) {
68  ZkossElephant.encryptCookie("xp_pass", password.getText(), "/", 365*24*60*60);
69  }
71  } else {
72  Clients.showNotification(I_.get("Values had to be equal"));
73  }
74  }
75 
76  @Override
77  public void doFinally() {
78  redir = Executions.getCurrent().getParameter("redir");
79  if(Strings.isBlank(redir)) {
81  }
82  }
83 
84 }
void onChangingPassword(InputEvent evt)
static String getCookieValue(String name)
abstract void sendRedirect(String uri)
static void encryptCookie(String name, String value, String path, int age)
abstract HttpServletRequest getHttpServletRequest()
static String extractPath(String path)
Definition: ElContext.java:574
static String get(String msg)
Definition: I_.java:41
static boolean hasSSO()
Definition: SSO.java:34
void setPassword(String newValue, String repeatValue)