Search in sources :

Example 11 with User

use of com.hfut.entity.User in project Workload by amoxu.

the class UserServiceImpl method register.

@Override
public boolean register(User user) throws Exception {
    System.out.println("user register:" + user.getUser() + " " + user.getPassword() + " " + user.getMail());
    if (StringUtils.isEmpty(user.getUser()) || StringUtils.isEmpty(user.getPassword())) {
        throw new CustomException("用户或密码不能为空!");
    } else if (StringUtils.isEmpty(user.getMail())) {
        throw new CustomException("邮箱不能为空!");
    } else if (user.getPassword().length() < 6) {
        throw new CustomException("密码过短!");
    }
    UserExample userExample = new UserExample();
    UserExample.Criteria criteria = userExample.createCriteria();
    criteria.andUserEqualTo(user.getUser());
    List<User> list = userMapper.selectByExample(userExample);
    if (list.size() != 0) {
        throw new CustomException("账号已存在!");
    }
    userExample = new UserExample();
    criteria = userExample.createCriteria();
    criteria.andMailEqualTo(user.getMail());
    list = userMapper.selectByExample(userExample);
    if (list.size() != 0) {
        throw new CustomException("邮箱已存在!");
    }
    int ret = userMapper.insert(user);
    if (ret > 0) {
        return true;
    } else {
        return false;
    }
}
Also used : User(com.hfut.entity.User) CustomException(com.hfut.exception.CustomException) UserExample(com.hfut.entity.UserExample)

Example 12 with User

use of com.hfut.entity.User in project Workload by amoxu.

the class UserServiceImpl method findByName.

/*   private SimpleMailMessage mailMessage;
    private JavaMailSender mailSender;*/
@Override
public User findByName(String name) throws Exception {
    UserExample userExample = new UserExample();
    UserExample.Criteria criteria = userExample.createCriteria();
    criteria.andUserEqualTo(name);
    List<User> list = userMapper.selectByExample(userExample);
    if (list.size() == 0) {
        return null;
    } else {
        return list.get(0);
    }
}
Also used : User(com.hfut.entity.User) UserExample(com.hfut.entity.UserExample)

Example 13 with User

use of com.hfut.entity.User in project Workload by amoxu.

the class UserServiceImpl method getList.

@Override
public List<User> getList(Integer page, Integer limit) throws Exception {
    UserExample example = new UserExample();
    example.setLimit(limit);
    if (page != 0) {
        page -= 1;
    }
    example.setOffset(page);
    List<User> list = userMapper.selectByExample(example);
    for (User user : list) {
        user.setPassword("*****");
        user.setAnswer("****");
    }
    return list;
}
Also used : User(com.hfut.entity.User) UserExample(com.hfut.entity.UserExample)

Example 14 with User

use of com.hfut.entity.User in project Workload by amoxu.

the class UserServiceImpl method getList.

@Override
public List<User> getList(int typeId, int page, int limit) throws Exception {
    UserExample example = new UserExample();
    UserExample.Criteria criteria = example.createCriteria();
    criteria.andLevelEqualTo(typeId);
    example.setLimit(limit);
    if (page != 0) {
        page -= 1;
    }
    example.setOffset(page);
    List<User> list = userMapper.selectByExample(example);
    for (User user : list) {
        user.setPassword("*****");
        user.setAnswer("****");
    }
    return list;
}
Also used : User(com.hfut.entity.User) UserExample(com.hfut.entity.UserExample)

Example 15 with User

use of com.hfut.entity.User in project Workload by amoxu.

the class loginRealm method doGetAuthenticationInfo.

/**
 * 在这个方法中,进行身份验证
 * login时调用
 */
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
    // 用户名
    String username = (String) token.getPrincipal();
    // 密码
    String password = new String((char[]) token.getCredentials());
    User userlogin = null;
    try {
        userlogin = userService.findByName(username);
    } catch (Exception e) {
        e.printStackTrace();
    }
    if (userlogin == null) {
        // 没有该用户名
        throw new UnknownAccountException();
    } else if (!password.equals(userlogin.getPassword())) {
        // 密码错误
        throw new IncorrectCredentialsException();
    }
    AuthenticationInfo aInfo = new SimpleAuthenticationInfo(username, password, getName());
    return aInfo;
}
Also used : User(com.hfut.entity.User) CustomException(com.hfut.exception.CustomException)

Aggregations

User (com.hfut.entity.User)15 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)8 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)8 Subject (org.apache.shiro.subject.Subject)7 AjaxResult (com.hfut.entity.AjaxResult)6 CustomException (com.hfut.exception.CustomException)6 UserExample (com.hfut.entity.UserExample)5 Session (org.apache.shiro.session.Session)4 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Date (java.util.Date)1 HashSet (java.util.HashSet)1 Random (java.util.Random)1 UsernamePasswordToken (org.apache.shiro.authc.UsernamePasswordToken)1 SimpleAuthorizationInfo (org.apache.shiro.authz.SimpleAuthorizationInfo)1 Test (org.junit.Test)1