return "";
}
public String updatePassword() throws ObjectExistsException {
VisitBean visitBean = (VisitBean) FacesContext.getCurrentInstance().getApplication().createValueBinding(VisitBean.BEAN_REF).getValue(FacesContext.getCurrentInstance());
this.username = visitBean.getCredentials().getUsername();
if (!password.equals(passwordVerify)) {
ResourceBundleUtil bundleUtil = ResourceBundleUtil.getInstance();
FacesMessage message = new FacesMessage( bundleUtil.getMessage("password_notEqual") );
FacesContext context = FacesContext.getCurrentInstance();
context.addMessage(this.passwordComponent.getClientId(context), message);
return "";
}
if (password.length() < 6) {
ResourceBundleUtil bundleUtil = ResourceBundleUtil.getInstance();
FacesMessage message = new FacesMessage( bundleUtil.getMessage("password_tooShort") );
FacesContext context = FacesContext.getCurrentInstance();
context.addMessage(this.passwordComponent.getClientId(context), message);
return "";
}
if (!UserDao.createInstance().exists(this.username, this.oldPassword)) {
ResourceBundleUtil bundleUtil = ResourceBundleUtil.getInstance();
FacesMessage message = new FacesMessage( bundleUtil.getMessage("authentication_failed") );
FacesContext context = FacesContext.getCurrentInstance();
context.addMessage(null , message);
return "";
}
UserDao userDao = UserDao.createInstance();
User updatedUser = new UserImpl();
updatedUser.setUsername(this.username);
updatedUser.setPassword(this.password);
userDao.update(updatedUser);
visitBean.setCredentials(new CredentialsWrapper(this.username, this.password));
ResourceBundleUtil bundleUtil = ResourceBundleUtil.getInstance();
FacesMessage message = new FacesMessage( bundleUtil.getMessage("user_updated") );
FacesContext context = FacesContext.getCurrentInstance();
context.addMessage(null, message);