Search in sources :

Example 1 with User

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);
    }
}
Also used : User(com.ds.retl.dal.entity.User) UserInterfaceErrorException(com.ds.retl.exception.UserInterfaceErrorException) EntityAccessException(org.mx.dal.exception.EntityAccessException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) EntityInstantiationException(org.mx.dal.exception.EntityInstantiationException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with User

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);
    }
}
Also used : User(com.ds.retl.dal.entity.User) UserInterfaceErrorException(com.ds.retl.exception.UserInterfaceErrorException) EntityAccessException(org.mx.dal.exception.EntityAccessException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with User

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);
    }
}
Also used : User(com.ds.retl.dal.entity.User) UserVO(com.ds.retl.rest.vo.user.UserVO) PaginationDataVO(org.mx.rest.vo.PaginationDataVO) DataVO(org.mx.rest.vo.DataVO) UserInterfaceErrorException(com.ds.retl.exception.UserInterfaceErrorException)

Example 4 with User

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);
    }
}
Also used : User(com.ds.retl.dal.entity.User) UserInterfaceErrorException(com.ds.retl.exception.UserInterfaceErrorException) EntityAccessException(org.mx.dal.exception.EntityAccessException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with User

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);
    }
}
Also used : User(com.ds.retl.dal.entity.User) UserInterfaceErrorException(com.ds.retl.exception.UserInterfaceErrorException) EntityAccessException(org.mx.dal.exception.EntityAccessException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

User (com.ds.retl.dal.entity.User)7 UserInterfaceErrorException (com.ds.retl.exception.UserInterfaceErrorException)7 EntityAccessException (org.mx.dal.exception.EntityAccessException)5 Transactional (org.springframework.transaction.annotation.Transactional)4 UserVO (com.ds.retl.rest.vo.user.UserVO)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3 DataVO (org.mx.rest.vo.DataVO)3 PaginationDataVO (org.mx.rest.vo.PaginationDataVO)3 EntityInstantiationException (org.mx.dal.exception.EntityInstantiationException)1