mirror of https://github.com/Rekoe/rk_svnadmin
密码修改同步
parent
0af14b3d52
commit
70acd84e73
|
@ -0,0 +1,16 @@
|
|||
package com.rekoe.domain;
|
||||
|
||||
public enum SVNRoleType {
|
||||
|
||||
admin("管理员"), small("普通");
|
||||
|
||||
public String display;
|
||||
|
||||
SVNRoleType(String display) {
|
||||
this.display = display;
|
||||
}
|
||||
|
||||
public String getDisplay() {
|
||||
return display;
|
||||
}
|
||||
}
|
|
@ -3,6 +3,7 @@ package com.rekoe.domain;
|
|||
import java.io.Serializable;
|
||||
|
||||
import org.nutz.dao.entity.annotation.Column;
|
||||
import org.nutz.dao.entity.annotation.Default;
|
||||
import org.nutz.dao.entity.annotation.Name;
|
||||
import org.nutz.dao.entity.annotation.Table;
|
||||
|
||||
|
@ -35,8 +36,9 @@ public class Usr implements Serializable {
|
|||
/**
|
||||
* 角色
|
||||
*/
|
||||
@Column
|
||||
private String role;
|
||||
@Column("svn_role_type")
|
||||
@Default("small")
|
||||
private SVNRoleType role;
|
||||
|
||||
@Column
|
||||
private String email;
|
||||
|
@ -94,18 +96,11 @@ public class Usr implements Serializable {
|
|||
this.psw = psw;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return 角色
|
||||
*/
|
||||
public String getRole() {
|
||||
public SVNRoleType getRole() {
|
||||
return role;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param role
|
||||
* 角色
|
||||
*/
|
||||
public void setRole(String role) {
|
||||
public void setRole(SVNRoleType role) {
|
||||
this.role = role;
|
||||
}
|
||||
|
||||
|
|
|
@ -9,11 +9,14 @@ import javax.servlet.http.HttpServletRequest;
|
|||
import org.apache.commons.lang3.RandomStringUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.shiro.authz.annotation.RequiresPermissions;
|
||||
import org.apache.shiro.crypto.SecureRandomNumberGenerator;
|
||||
import org.apache.shiro.crypto.hash.Sha256Hash;
|
||||
import org.nutz.aop.interceptor.async.Async;
|
||||
import org.nutz.dao.Chain;
|
||||
import org.nutz.dao.Cnd;
|
||||
import org.nutz.ioc.loader.annotation.Inject;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
import org.nutz.lang.Lang;
|
||||
import org.nutz.lang.Strings;
|
||||
import org.nutz.lang.random.R;
|
||||
import org.nutz.log.Log;
|
||||
|
@ -28,6 +31,8 @@ import com.rekoe.common.Message;
|
|||
import com.rekoe.common.page.Pagination;
|
||||
import com.rekoe.domain.Pj;
|
||||
import com.rekoe.domain.ProjectConfig;
|
||||
import com.rekoe.domain.SVNRoleType;
|
||||
import com.rekoe.domain.User;
|
||||
import com.rekoe.domain.Usr;
|
||||
import com.rekoe.module.BaseAction;
|
||||
import com.rekoe.service.EmailService;
|
||||
|
@ -35,6 +40,7 @@ import com.rekoe.service.ProjectConfigService;
|
|||
import com.rekoe.service.ProjectService;
|
||||
import com.rekoe.service.SvnService;
|
||||
import com.rekoe.service.SvnUserService;
|
||||
import com.rekoe.service.UserService;
|
||||
import com.rekoe.utils.EncryptUtil;
|
||||
|
||||
@IocBean
|
||||
|
@ -44,7 +50,8 @@ public class AdminSvnUserAct extends BaseAction {
|
|||
private final static Log log = Logs.get();
|
||||
|
||||
private static final char[] RANDOM_ARRY_CHAR = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".toCharArray();
|
||||
|
||||
@Inject
|
||||
private UserService userService;
|
||||
@Inject
|
||||
private SvnUserService svnUserService;
|
||||
|
||||
|
@ -80,6 +87,18 @@ public class AdminSvnUserAct extends BaseAction {
|
|||
boolean isEmail = Strings.isEmail(user.getEmail());
|
||||
if (isOk && isEmail) {
|
||||
user.setPsw(EncryptUtil.encrypt(R.UU64().substring(0, 10)));
|
||||
SVNRoleType role = user.getRole();
|
||||
switch (role) {
|
||||
case admin: {
|
||||
User u = userService.fetch(Cnd.where("name", "=", user.getUsr()));
|
||||
if (Lang.isEmpty(u)) {
|
||||
userService.initUser(user.getUsr(), user.getUsr(), "svn", Lang.getIP(req), false, user.getPsw());
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
svnUserService.insert(user);
|
||||
isOk = true;
|
||||
} else {
|
||||
|
@ -153,6 +172,9 @@ public class AdminSvnUserAct extends BaseAction {
|
|||
}
|
||||
String code = RandomStringUtils.random(7, RANDOM_ARRY_CHAR);
|
||||
svnUserService.update(Chain.make("psw", EncryptUtil.encrypt(code)), Cnd.where("usr", "=", usr));
|
||||
String salt = new SecureRandomNumberGenerator().nextBytes().toBase64();
|
||||
String pwd = new Sha256Hash(code, salt, 1024).toBase64();
|
||||
userService.update(Chain.make("salt", salt).add("password", pwd), Cnd.where("name", "=", usr));
|
||||
if (usr.equals(manager.getUsr())) {
|
||||
req.getSession().setAttribute("usr", svnUserService.fetch(Cnd.where("usr", "=", usr)));
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ import org.nutz.ioc.loader.annotation.IocBean;
|
|||
import org.nutz.lang.Lang;
|
||||
|
||||
import com.rekoe.domain.Pj;
|
||||
import com.rekoe.domain.SVNRoleType;
|
||||
import com.rekoe.domain.Usr;
|
||||
|
||||
/**
|
||||
|
@ -112,7 +113,7 @@ public class SvnUserService extends BaseService<Usr> {
|
|||
result.setUsr(rs.getString("usr"));
|
||||
result.setName(rs.getString("name"));
|
||||
result.setPsw(rs.getString("psw"));
|
||||
result.setRole(rs.getString("role"));
|
||||
result.setRole(SVNRoleType.valueOf(rs.getString("svn_role_type")));
|
||||
result.setEmail(rs.getString("email"));
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -119,6 +119,14 @@ public class UserService extends BaseService<User> {
|
|||
}
|
||||
|
||||
public User initUser(String name, String openid, String providerid, String addr) {
|
||||
return dao().insert(initUser(name, openid, providerid, addr, true));
|
||||
}
|
||||
|
||||
public User initUser(String name, String openid, String providerid, String addr, boolean locked) {
|
||||
return initUser(name, openid, providerid, addr, locked, R.UU32());
|
||||
}
|
||||
|
||||
public User initUser(String name, String openid, String providerid, String addr, boolean locked, String pwd) {
|
||||
User temp = dao().fetch(getEntityClass(), Cnd.where("name", "=", name));
|
||||
if (!Lang.isEmpty(temp)) {
|
||||
name += R.random(2, 5);
|
||||
|
@ -129,8 +137,11 @@ public class UserService extends BaseService<User> {
|
|||
user.setOpenid(openid);
|
||||
user.setProviderid(providerid);
|
||||
user.setRegisterIp(addr);
|
||||
user.setLocked(true);
|
||||
user.setLocked(locked);
|
||||
user.setSystem(false);
|
||||
String salt = new SecureRandomNumberGenerator().nextBytes().toBase64();
|
||||
user.setSalt(salt);
|
||||
user.setPassword(new Sha256Hash(pwd, salt, 1024).toBase64());
|
||||
return dao().insert(user);
|
||||
}
|
||||
|
||||
|
|
|
@ -12,6 +12,7 @@ import org.nutz.dao.sql.Sql;
|
|||
import org.nutz.dao.sql.SqlCallback;
|
||||
import org.nutz.ioc.loader.annotation.IocBean;
|
||||
|
||||
import com.rekoe.domain.SVNRoleType;
|
||||
import com.rekoe.domain.Usr;
|
||||
|
||||
/**
|
||||
|
@ -62,7 +63,7 @@ public class UsrService extends BaseService<Usr> {
|
|||
result.setUsr(rs.getString("usr"));
|
||||
result.setName(rs.getString("name"));
|
||||
result.setPsw(rs.getString("psw"));
|
||||
result.setRole(rs.getString("role"));
|
||||
result.setRole(SVNRoleType.valueOf(rs.getString("svn_role_type")));
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue