Search in sources :

Example 6 with TestVerifyCode

use of com.ngtesting.platform.entity.TestVerifyCode 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)

Aggregations

TestVerifyCode (com.ngtesting.platform.entity.TestVerifyCode)6 TestUser (com.ngtesting.platform.entity.TestUser)5 Date (java.util.Date)3 JSONObject (com.alibaba.fastjson.JSONObject)2 AuthPassport (com.ngtesting.platform.util.AuthPassport)2 HashMap (java.util.HashMap)2 List (java.util.List)2 DetachedCriteria (org.hibernate.criterion.DetachedCriteria)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)2 TestOrg (com.ngtesting.platform.entity.TestOrg)1