Search in sources :

Example 21 with TestUser

use of com.ngtesting.platform.entity.TestUser in project ngtesting-platform by aaronchen2k.

the class UserAction method get.

@AuthPassport(validate = true)
@RequestMapping(value = "get", method = RequestMethod.POST)
@ResponseBody
public Map<String, Object> get(HttpServletRequest request, @RequestBody JSONObject json) {
    Map<String, Object> ret = new HashMap<String, Object>();
    UserVo userVo = (UserVo) request.getSession().getAttribute(Constant.HTTP_SESSION_USER_KEY);
    Long orgId = userVo.getDefaultOrgId();
    Long userId = json.getLong("id");
    List<RelationOrgGroupUserVo> relations = orgGroupUserService.listRelationsByUser(orgId, userId);
    if (userId == null) {
        ret.put("user", new UserVo());
        ret.put("relations", relations);
        ret.put("code", Constant.RespCode.SUCCESS.getCode());
        return ret;
    }
    TestUser po = (TestUser) userService.get(TestUser.class, Long.valueOf(userId));
    UserVo vo = userService.genVo(po);
    ret.put("user", vo);
    ret.put("relations", relations);
    ret.put("code", Constant.RespCode.SUCCESS.getCode());
    return ret;
}
Also used : HashMap(java.util.HashMap) JSONObject(com.alibaba.fastjson.JSONObject) TestUser(com.ngtesting.platform.entity.TestUser) AuthPassport(com.ngtesting.platform.util.AuthPassport) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 22 with TestUser

use of com.ngtesting.platform.entity.TestUser in project ngtesting-platform by aaronchen2k.

the class UserAction method setLeftSize.

@AuthPassport(validate = true)
@RequestMapping(value = "setLeftSize", method = RequestMethod.POST)
@ResponseBody
public Map<String, Object> setLeftSize(HttpServletRequest request, @RequestBody JSONObject json) {
    Map<String, Object> ret = new HashMap<String, Object>();
    UserVo userVo = (UserVo) request.getSession().getAttribute(Constant.HTTP_SESSION_USER_KEY);
    Integer left = json.getInteger("left");
    TestUser user = accountService.setLeftSizePers(userVo.getId(), left);
    userVo = userService.genVo(user);
    request.getSession().setAttribute(Constant.HTTP_SESSION_USER_KEY, userVo);
    ret.put("data", userVo);
    ret.put("code", Constant.RespCode.SUCCESS.getCode());
    return ret;
}
Also used : HashMap(java.util.HashMap) JSONObject(com.alibaba.fastjson.JSONObject) TestUser(com.ngtesting.platform.entity.TestUser) AuthPassport(com.ngtesting.platform.util.AuthPassport) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 23 with TestUser

use of com.ngtesting.platform.entity.TestUser in project ngtesting-platform by aaronchen2k.

the class AccountAction method forgotPassword.

@AuthPassport(validate = false)
@RequestMapping(value = "forgotPassword", method = RequestMethod.POST)
@ResponseBody
public Map<String, Object> forgotPassword(HttpServletRequest request, @RequestBody JSONObject json) {
    Map<String, Object> ret = new HashMap<String, Object>();
    String email = json.getString("email");
    TestUser user = accountService.getByEmail(email);
    if (user == null) {
        ret.put("code", RespCode.BIZ_FAIL.getCode());
        ret.put("msg", "用户不存在");
        return ret;
    }
    TestVerifyCode verifyCode = accountService.genVerifyCodePers(user.getId());
    if (verifyCode != null) {
        String sys = PropertyConfig.getConfig("sys.name");
        Map<String, String> map = new HashMap<String, String>();
        map.put("name", user.getName());
        map.put("vcode", verifyCode.getCode());
        map.put("url", PropertyConfig.getConfig("url.reset.password"));
        mailService.sendTemplateMail("[\"" + sys + "\"]忘记密码", "forgot-password.ftl", user.getEmail(), map);
        ret.put("data", verifyCode);
        ret.put("code", RespCode.SUCCESS.getCode());
    } else {
        ret.put("code", RespCode.BIZ_FAIL.getCode());
        ret.put("msg", "用户不存在");
    }
    return ret;
}
Also used : HashMap(java.util.HashMap) TestVerifyCode(com.ngtesting.platform.entity.TestVerifyCode) JSONObject(com.alibaba.fastjson.JSONObject) TestUser(com.ngtesting.platform.entity.TestUser) AuthPassport(com.ngtesting.platform.util.AuthPassport) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 24 with TestUser

use of com.ngtesting.platform.entity.TestUser in project ngtesting-platform by aaronchen2k.

the class AccountAction method register.

@AuthPassport(validate = false)
@RequestMapping(value = "register", method = RequestMethod.POST)
@ResponseBody
public Map<String, Object> register(HttpServletRequest request, @RequestBody JSONObject json) {
    Map<String, Object> ret = new HashMap<String, Object>();
    String name = json.getString("name");
    String phone = json.getString("phone");
    String email = json.getString("email");
    String password = json.getString("password");
    TestUser user = accountService.registerPers(name, email, phone, password);
    if (user != null) {
        orgService.createDefaultBasicDataPers(user);
        TestVerifyCode verifyCode = accountService.genVerifyCodePers(user.getId());
        String sys = PropertyConfig.getConfig("sys.name");
        Map<String, String> map = new HashMap<String, String>();
        map.put("name", user.getName());
        map.put("vcode", verifyCode.getCode());
        map.put("url", PropertyConfig.getConfig("url.login"));
        mailService.sendTemplateMail("[\"" + sys + "\"]注册成功", "register-success.ftl", user.getEmail(), map);
        ret.put("msg", "注册成功,请访问您的邮箱进行登录");
        ret.put("code", RespCode.SUCCESS.getCode());
    } else {
        ret.put("code", RespCode.BIZ_FAIL.getCode());
        ret.put("msg", "邮箱已存在");
    }
    return ret;
}
Also used : HashMap(java.util.HashMap) TestVerifyCode(com.ngtesting.platform.entity.TestVerifyCode) JSONObject(com.alibaba.fastjson.JSONObject) TestUser(com.ngtesting.platform.entity.TestUser) AuthPassport(com.ngtesting.platform.util.AuthPassport) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 25 with TestUser

use of com.ngtesting.platform.entity.TestUser in project ngtesting-platform by aaronchen2k.

the class AccountAction method resetPassword.

@AuthPassport(validate = false)
@RequestMapping(value = "resetPassword", method = RequestMethod.POST)
@ResponseBody
public Map<String, Object> resetPassword(HttpServletRequest request, @RequestBody JSONObject json) {
    Map<String, Object> ret = new HashMap<String, Object>();
    String verifyCode = json.getString("vcode");
    String password = json.getString("password");
    TestUser user = accountService.resetPasswordPers(verifyCode, password);
    if (user != null) {
        UserVo userVo = userService.genVo(user);
        request.getSession().setAttribute(Constant.HTTP_SESSION_USER_KEY, userVo);
        ret.put("token", user.getToken());
        ret.put("code", RespCode.SUCCESS.getCode());
    } else {
        ret.put("code", RespCode.BIZ_FAIL.getCode());
        ret.put("msg", "重置密码失败");
    }
    return ret;
}
Also used : UserVo(com.ngtesting.platform.vo.UserVo) HashMap(java.util.HashMap) JSONObject(com.alibaba.fastjson.JSONObject) TestUser(com.ngtesting.platform.entity.TestUser) AuthPassport(com.ngtesting.platform.util.AuthPassport) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

TestUser (com.ngtesting.platform.entity.TestUser)43 HashMap (java.util.HashMap)13 JSONObject (com.alibaba.fastjson.JSONObject)12 AuthPassport (com.ngtesting.platform.util.AuthPassport)12 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)12 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)12 UserVo (com.ngtesting.platform.vo.UserVo)9 List (java.util.List)9 DetachedCriteria (org.hibernate.criterion.DetachedCriteria)9 TestOrg (com.ngtesting.platform.entity.TestOrg)5 TestVerifyCode (com.ngtesting.platform.entity.TestVerifyCode)5 Date (java.util.Date)5 RelationOrgGroupUserVo (com.ngtesting.platform.vo.RelationOrgGroupUserVo)3 LinkedList (java.util.LinkedList)3 OrgVo (com.ngtesting.platform.vo.OrgVo)2 TestAlert (com.ngtesting.platform.entity.TestAlert)1 TestOrgGroup (com.ngtesting.platform.entity.TestOrgGroup)1 TestOrgRole (com.ngtesting.platform.entity.TestOrgRole)1 TestPlan (com.ngtesting.platform.entity.TestPlan)1 TestProject (com.ngtesting.platform.entity.TestProject)1