Search in sources :

Example 1 with User

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

the class FindPsw method getQuestion.

@RequestMapping(value = "/password/getQuestion", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE + ";charset=utf-8")
@ResponseBody
public String getQuestion(User user) throws Exception {
    Subject currentUser = SecurityUtils.getSubject();
    Session session = currentUser.getSession();
    if (session.getAttribute("rand") == null || !session.getAttribute("rand").toString().equalsIgnoreCase(user.getMail())) {
        return "{\"status\":1,\"msg\":\"请重新输入验证码!\"}";
    }
    User nUser = userService.findByName(user.getUser());
    if (nUser != null) {
        return "{\"status\":0,\"msg\":\"" + nUser.getQuestion() + "\"}";
    } else {
        return "{\"status\":1,\"msg\":\"请检查用户名!\"}";
    }
}
Also used : User(com.hfut.entity.User) Subject(org.apache.shiro.subject.Subject) Session(org.apache.shiro.session.Session) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 2 with User

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

the class FindPsw method resetPsw.

@RequestMapping(value = "/password/resetPsw", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE + ";charset=utf-8")
@ResponseBody
public String resetPsw(User user) throws Exception {
    Subject currentUser = SecurityUtils.getSubject();
    Session session = currentUser.getSession();
    if (session.getAttribute("rand") == null || !session.getAttribute("rand").toString().equalsIgnoreCase(user.getMail())) {
        return "{\"status\":1,\"msg\":\"请重新输入验证码!\"}";
    }
    String retErr = "{\"status\":1,\"msg\":\"请检查用户名!\"}";
    User nUser = userService.findByName(user.getUser());
    if (nUser != null) {
        if (nUser.getQuestion() != user.getQuestion()) {
            return retErr;
        }
        return "{\"status\":0,\"msg\":\"" + nUser.getQuestion() + "\"}";
    } else {
        return retErr;
    }
}
Also used : User(com.hfut.entity.User) Subject(org.apache.shiro.subject.Subject) Session(org.apache.shiro.session.Session) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 3 with User

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

the class RoleController method searchUser.

@RequestMapping(value = "/user/search", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE + ";charset=utf-8")
@ResponseBody
public String searchUser(@RequestParam(name = "s") String s, @RequestParam(name = "page") Integer page, @RequestParam(name = "limit") Integer limit) throws Exception {
    AjaxResult result = new AjaxResult();
    List<User> list = userService.selectLike(s, page, limit);
    result.setData(list);
    result.setCount(userService.countLike(s));
    result.ok();
    return result.toString();
}
Also used : AjaxResult(com.hfut.entity.AjaxResult) User(com.hfut.entity.User) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 4 with User

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

the class UserController method password.

@RequestMapping(value = "/user/password", produces = MediaType.APPLICATION_JSON_VALUE + ";charset=utf-8", method = { RequestMethod.POST })
@ResponseBody
public // 修改密码
String password(@RequestParam(name = "name") String name, @RequestParam(name = "oldPsw") String old, @RequestParam(name = "newPsw") String newpsw) throws Exception {
    Subject currentUser = SecurityUtils.getSubject();
    old = ToolKit.psw2pwd(old);
    newpsw = ToolKit.psw2pwd(newpsw);
    AjaxResult result = new AjaxResult();
    String username = currentUser.getPrincipal().toString();
    User user = userService.findByName(username);
    if (null == user || !username.equals(name)) {
        result.failed();
        result.setMsg("修改用户名与当前用户名不匹配。");
        return JSON.toJSONString(result);
    } else if (!user.getPassword().equals(old)) {
        result.failed();
        result.setMsg("旧密码不正确。");
        return JSON.toJSONString(result);
    }
    try {
        user.setPassword(newpsw);
        System.out.println(user);
        userService.alterPassword(user);
        result.ok();
        result.setMsg("修改成功,重新登录。");
        return JSON.toJSONString(result);
    } catch (Exception e) {
        throw new CustomException("请检查数据是否正确");
    }
}
Also used : AjaxResult(com.hfut.entity.AjaxResult) User(com.hfut.entity.User) CustomException(com.hfut.exception.CustomException) Subject(org.apache.shiro.subject.Subject) CustomException(com.hfut.exception.CustomException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 5 with User

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

the class loginRealm method doGetAuthorizationInfo.

/**
 * 获取身份信息,我们可以在这个方法中,从数据库获取该用户的权限和角色信息
 * 当调用权限验证时,就会调用此方法
 */
protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {
    String teacherName = (String) getAvailablePrincipal(principalCollection);
    com.hfut.entity.UserRole role = null;
    try {
        User userlogin = userService.findByName(teacherName);
        // 获取角色对象
        role = userRoleService.findByid(userlogin.getLevel());
    } catch (Exception e) {
        try {
            throw new CustomException("用户不存在或密码错误");
        } catch (CustomException e1) {
            e1.printStackTrace();
        }
    }
    // 通过用户名从数据库获取权限/角色信息
    SimpleAuthorizationInfo info = new SimpleAuthorizationInfo();
    Set<String> r = new HashSet<String>();
    if (role != null) {
        r.add(role.getName());
        info.setRoles(r);
    }
    return info;
}
Also used : User(com.hfut.entity.User) SimpleAuthorizationInfo(org.apache.shiro.authz.SimpleAuthorizationInfo) CustomException(com.hfut.exception.CustomException) CustomException(com.hfut.exception.CustomException) HashSet(java.util.HashSet)

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