Dialog na změnu hesla
							parent
							
								
									3718e4c088
								
							
						
					
					
						commit
						0926b36fa8
					
				@ -1,14 +1,16 @@
 | 
			
		||||
package info.bukova.isspst.services.users;
 | 
			
		||||
 | 
			
		||||
import org.springframework.security.core.userdetails.UserDetailsService;
 | 
			
		||||
 | 
			
		||||
import info.bukova.isspst.data.User;
 | 
			
		||||
import info.bukova.isspst.services.Service;
 | 
			
		||||
 | 
			
		||||
import org.springframework.security.core.userdetails.UserDetailsService;
 | 
			
		||||
 | 
			
		||||
public interface UserService extends UserDetailsService, Service<User> {
 | 
			
		||||
	
 | 
			
		||||
	public void setPassword(User user, String password);
 | 
			
		||||
	public boolean hasRole(User user, String authority);
 | 
			
		||||
	public void saveWithPwd(User user, String password);
 | 
			
		||||
	public User getCurrent();
 | 
			
		||||
	public String encodePassword(User user, String plain);
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -0,0 +1,83 @@
 | 
			
		||||
package info.bukova.isspst.ui.users;
 | 
			
		||||
 | 
			
		||||
import info.bukova.isspst.data.User;
 | 
			
		||||
import info.bukova.isspst.services.users.UserService;
 | 
			
		||||
 | 
			
		||||
import org.zkoss.bind.annotation.BindingParam;
 | 
			
		||||
import org.zkoss.bind.annotation.Command;
 | 
			
		||||
import org.zkoss.bind.annotation.Init;
 | 
			
		||||
import org.zkoss.zk.ui.select.annotation.WireVariable;
 | 
			
		||||
import org.zkoss.zul.Messagebox;
 | 
			
		||||
import org.zkoss.zul.Window;
 | 
			
		||||
 | 
			
		||||
public class PasswdVM {
 | 
			
		||||
	
 | 
			
		||||
	private String oldPw;
 | 
			
		||||
	private String newPw;
 | 
			
		||||
	private String retPw;
 | 
			
		||||
	private User user;
 | 
			
		||||
	@WireVariable
 | 
			
		||||
	private UserService userService;
 | 
			
		||||
	
 | 
			
		||||
	@Init
 | 
			
		||||
	public void init() {
 | 
			
		||||
		user = userService.getCurrent();
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	@Command
 | 
			
		||||
	public void save(@BindingParam("window") Window window) {
 | 
			
		||||
		if (!canSave()) {
 | 
			
		||||
			return;
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		userService.saveWithPwd(user, newPw);
 | 
			
		||||
		Messagebox.show("Heslo bylo změněno", "Změna hesla", Messagebox.OK, Messagebox.INFORMATION);
 | 
			
		||||
		window.detach();
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	private boolean canSave() {
 | 
			
		||||
		if (!user.getPassword().equals(userService.encodePassword(user, oldPw))) {
 | 
			
		||||
			Messagebox.show("Špatné staré heslo", "Chyba", Messagebox.OK, Messagebox.ERROR);
 | 
			
		||||
			return false;
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		if (newPw == null || newPw.isEmpty()) {
 | 
			
		||||
			Messagebox.show("Zadejte nové heslo", "Chyba", Messagebox.OK, Messagebox.ERROR);
 | 
			
		||||
			return false;
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		if (!newPw.equals(retPw)) {
 | 
			
		||||
			Messagebox.show("Nasouhlasí nová hesla", "Chyba", Messagebox.OK, Messagebox.ERROR);
 | 
			
		||||
			return false;
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		return true;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public String getOldPw() {
 | 
			
		||||
		return oldPw;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public void setOldPw(String oldPw) {
 | 
			
		||||
		this.oldPw = oldPw;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public String getNewPw() {
 | 
			
		||||
		return newPw;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public void setNewPw(String newPw) {
 | 
			
		||||
		this.newPw = newPw;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public String getRetPw() {
 | 
			
		||||
		return retPw;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public void setRetPw(String retPw) {
 | 
			
		||||
		this.retPw = retPw;
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@ -0,0 +1,22 @@
 | 
			
		||||
<?page title="Změnit heslo" contentType="text/html;charset=UTF-8"?>
 | 
			
		||||
<zk>
 | 
			
		||||
<?variable-resolver class="org.zkoss.zkplus.spring.DelegatingVariableResolver"?>
 | 
			
		||||
 | 
			
		||||
<window id="passwd" title="Změnit heslo" border="normal" closable="true" width="350px"
 | 
			
		||||
	apply="org.zkoss.bind.BindComposer"
 | 
			
		||||
	viewModel="@id('vm') @init('info.bukova.isspst.ui.users.PasswdVM')">
 | 
			
		||||
	<style src="/app/form.css"/>
 | 
			
		||||
	<grid>
 | 
			
		||||
		<columns>
 | 
			
		||||
			<column hflex="min"/>
 | 
			
		||||
			<column/>
 | 
			
		||||
		</columns>
 | 
			
		||||
		<rows>
 | 
			
		||||
			<row><label value="Staré heslo:"/><textbox type="password" value="@bind(vm.oldPw)"/></row>
 | 
			
		||||
			<row><label value="Nové heslo:"/><textbox type="password" value="@bind(vm.newPw)"/></row>
 | 
			
		||||
			<row><label value="Nové heslo znovu:"/><textbox type="password" value="@bind(vm.retPw)"/></row>
 | 
			
		||||
		</rows>
 | 
			
		||||
	</grid>
 | 
			
		||||
	<button image="/img/save.png" label="Uložit" onClick="@command('save', window=passwd)" sclass="nicebutton" /><button image="~./zul/img/misc/drag-disallow.png" label="Zrušit" onClick="passwd.detach()" sclass="nicebutton"/>
 | 
			
		||||
</window>
 | 
			
		||||
</zk>
 | 
			
		||||
					Loading…
					
					
				
		Reference in New Issue