Search in sources :

Example 26 with TestUser

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

the class AccountAction method loginWithVcode.

@AuthPassport(validate = false)
@RequestMapping(value = "loginWithVcode", method = RequestMethod.POST)
@ResponseBody
public Map<String, Object> loginWithVcode(HttpServletRequest request, @RequestBody JSONObject json) {
    Map<String, Object> ret = new HashMap<String, Object>();
    String vcode = json.getString("vcode");
    TestUser user = accountService.resetPasswordPers(vcode, null);
    if (user != null) {
        UserVo userVo = userService.genVo(user);
        request.getSession().setAttribute(Constant.HTTP_SESSION_USER_KEY, userVo);
        ret.put("profile", 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)

Example 27 with TestUser

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

the class AccountAction method login.

@AuthPassport(validate = false)
@RequestMapping(value = "login", method = RequestMethod.POST)
@ResponseBody
public Map<String, Object> login(HttpServletRequest request, @RequestBody JSONObject json) {
    Map<String, Object> ret = new HashMap<String, Object>();
    String email = json.getString("email");
    String password = json.getString("password");
    boolean rememberMe = json.getBoolean("rememberMe") != null ? json.getBoolean("rememberMe") : false;
    TestUser user = accountService.loginPers(email, password, rememberMe);
    if (user != null) {
        UserVo userVo = userService.genVo(user);
        request.getSession().setAttribute(Constant.HTTP_SESSION_USER_KEY, userVo);
        ret.put("profile", 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)

Example 28 with TestUser

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

the class UserServiceImpl method invitePers.

@Override
public TestUser invitePers(UserVo userVo, UserVo newUserVo, List<RelationOrgGroupUserVo> relations) {
    Long orgId = userVo.getDefaultOrgId();
    Long prjId = userVo.getDefaultPrjId();
    String prjName = userVo.getDefaultPrjName();
    TestUser existUser = accountService.getByEmail(newUserVo.getEmail());
    boolean isNew;
    TestUser userPo;
    if (existUser != null) {
        isNew = false;
        userPo = existUser;
    } else {
        isNew = true;
        userPo = new TestUser();
        userPo.setDefaultOrgId(orgId);
        userPo.setName(newUserVo.getName());
        userPo.setPhone(newUserVo.getPhone());
        userPo.setEmail(newUserVo.getEmail());
        userPo.setDisabled(newUserVo.getDisabled());
        userPo.setAvatar("upload/sample/user/avatar.png");
        userPo.setDefaultOrgId(userVo.getDefaultOrgId());
        userPo.setDefaultPrjId(userVo.getDefaultPrjId());
        userPo.setName(newUserVo.getName());
        saveOrUpdate(userPo);
    }
    TestOrg org = (TestOrg) get(TestOrg.class, orgId);
    if (!contains(org.getUserSet(), userPo.getId())) {
        // 不在组里
        org.getUserSet().add(userPo);
        saveOrUpdate(org);
        projectService.getHistoryPers(orgId, userPo.getId(), prjId, prjName);
        orgGroupUserService.saveRelations(relations);
        String sys = PropertyConfig.getConfig("sys.name");
        Map<String, String> map = new HashMap<String, String>();
        map.put("user", userPo.getName() + "(" + userPo.getEmail() + ")");
        map.put("name", userPo.getName());
        map.put("sys", sys);
        String url;
        if (isNew) {
            TestVerifyCode verifyCode = accountService.genVerifyCodePers(userPo.getId());
            url = PropertyConfig.getConfig("url.reset.password") + "/" + verifyCode.getCode();
        } else {
            url = PropertyConfig.getConfig("url.login");
        }
        map.put("url", url);
        mailService.sendTemplateMail("来自[" + sys + "]的邀请", "invite-user.ftl", newUserVo.getEmail(), map);
        return userPo;
    } else {
        return null;
    }
}
Also used : TestVerifyCode(com.ngtesting.platform.entity.TestVerifyCode) TestUser(com.ngtesting.platform.entity.TestUser) TestOrg(com.ngtesting.platform.entity.TestOrg)

Example 29 with TestUser

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

the class UserServiceImpl method remove.

@Override
public boolean remove(Long userId, Long orgId) {
    TestUser po = (TestUser) get(TestUser.class, userId);
    po.setDeleted(true);
    saveOrUpdate(po);
    return true;
}
Also used : TestUser(com.ngtesting.platform.entity.TestUser)

Example 30 with TestUser

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

the class UserServiceImpl method genVos.

@Override
public List<UserVo> genVos(List<TestUser> pos) {
    List<UserVo> vos = new LinkedList<UserVo>();
    for (TestUser po : pos) {
        UserVo vo = genVo(po);
        vos.add(vo);
    }
    return vos;
}
Also used : UserVo(com.ngtesting.platform.vo.UserVo) RelationOrgGroupUserVo(com.ngtesting.platform.vo.RelationOrgGroupUserVo) TestUser(com.ngtesting.platform.entity.TestUser)

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