use of com.ds.retl.dal.entity.User in project main by JohnPeng739.
the class UserManageServiceImpl method initUser.
/**
* {@inheritDoc}
*
* @see UserManageService#initUser()
*/
@Transactional
@Override
public User initUser() throws UserInterfaceErrorException {
String userCode = "ds110";
try {
User user = accessor.getByCode(userCode, User.class);
if (user == null) {
user = EntityFactory.createEntity(User.class);
user.setCode("ds110");
}
try {
user.setPassword(DigestUtils.md5("edmund110119"));
} catch (NoSuchAlgorithmException ex) {
throw new UserInterfaceErrorException(UserInterfaceErrors.USER_PASSWORD_DISGEST_FAIL);
}
user.setName("RETL管理员");
user.setRoles("manager");
return saveUser(user);
} catch (EntityInstantiationException | EntityAccessException ex) {
throw new UserInterfaceErrorException(UserInterfaceErrors.DB_OPERATE_FAIL);
}
}
use of com.ds.retl.dal.entity.User in project main by JohnPeng739.
the class UserManageServiceImpl method logout.
/**
* {@inheritDoc}
*
* @see UserManageService#logout(String)
*/
@Transactional
@Override
public void logout(String userCode) throws UserInterfaceErrorException {
try {
User user = accessor.getByCode(userCode, User.class);
if (user == null) {
throw new UserInterfaceErrorException(UserInterfaceErrors.USER_NOT_FOUND);
}
user.setOnline(false);
accessor.save(user);
logService.writeLog(String.format("用户[%s]成功注销退出系统。", userCode));
} catch (EntityAccessException ex) {
throw new UserInterfaceErrorException(UserInterfaceErrors.DB_OPERATE_FAIL);
}
}
use of com.ds.retl.dal.entity.User in project main by JohnPeng739.
the class UserManageResource method initUser.
/**
* 初始化用户
*
* @return 初始化的管理员用户
*/
@Path("init")
@GET
public DataVO<UserVO> initUser() {
try {
sessionDataStore.setCurrentUserCode("SYSTEM");
User user = userManageService.initUser();
UserVO userVO = new UserVO();
UserVO.transform(user, userVO);
sessionDataStore.removeCurrentUserCode();
return new DataVO<>(userVO);
} catch (UserInterfaceErrorException ex) {
return new DataVO<>(ex);
}
}
use of com.ds.retl.dal.entity.User in project main by JohnPeng739.
the class UserManageServiceImpl method changePassword.
/**
* {@inheritDoc}
*
* @see UserManageService#changePassword(String, String, String)
*/
@Transactional
@Override
public User changePassword(String userCode, String oldPassword, String newPassword) throws UserInterfaceErrorException {
try {
User user = accessor.getByCode(userCode, User.class);
if (user == null) {
throw new UserInterfaceErrorException(UserInterfaceErrors.USER_NOT_FOUND);
}
try {
String digestPwd = DigestUtils.md5(oldPassword);
if (!digestPwd.equals(user.getPassword())) {
throw new UserInterfaceErrorException(UserInterfaceErrors.USER_PASSWORD_UNMATCH);
}
digestPwd = DigestUtils.md5(newPassword);
user.setPassword(digestPwd);
user = accessor.save(user);
logService.writeLog(String.format("成功修改了用户[%s]的密码。", userCode));
return user;
} catch (NoSuchAlgorithmException ex) {
throw new UserInterfaceErrorException(UserInterfaceErrors.USER_PASSWORD_DISGEST_FAIL);
}
} catch (EntityAccessException ex) {
throw new UserInterfaceErrorException(UserInterfaceErrors.DB_OPERATE_FAIL);
}
}
use of com.ds.retl.dal.entity.User in project main by JohnPeng739.
the class UserManageServiceImpl method login.
/**
* {@inheritDoc}
*
* @see UserManageService#login(String, String)
*/
@Transactional
@Override
public User login(String userCode, String password) throws UserInterfaceErrorException {
try {
User user = accessor.getByCode(userCode, User.class);
if (user == null) {
throw new UserInterfaceErrorException(UserInterfaceErrors.USER_NOT_FOUND);
}
try {
String digestPwd = DigestUtils.md5(password);
if (digestPwd.equals(user.getPassword())) {
// 写入登录成功的日志
user.setOnline(true);
user = accessor.save(user);
logService.writeLog(String.format("用户[%s]成功登录进入系统。", userCode));
return user;
} else {
throw new UserInterfaceErrorException(UserInterfaceErrors.USER_PASSWORD_UNMATCH);
}
} catch (NoSuchAlgorithmException ex) {
throw new UserInterfaceErrorException(UserInterfaceErrors.USER_PASSWORD_DISGEST_FAIL);
}
} catch (EntityAccessException ex) {
throw new UserInterfaceErrorException(UserInterfaceErrors.DB_OPERATE_FAIL);
}
}
Aggregations