Search in sources :

Example 1 with TestVerifyCode

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

the class AccountServiceImpl method checkResetPassword.

@Override
public boolean checkResetPassword(String verifyCode) {
    DetachedCriteria dc = DetachedCriteria.forClass(TestVerifyCode.class);
    dc.add(Restrictions.eq("code", verifyCode));
    dc.add(Restrictions.ge("expireTime", new Date()));
    dc.add(Restrictions.ne("deleted", true));
    dc.add(Restrictions.ne("disabled", true));
    dc.addOrder(Order.desc("id"));
    List<TestVerifyCode> ls = (List<TestVerifyCode>) findAllByCriteria(dc);
    if (ls.size() < 1) {
        return false;
    } else {
        return true;
    }
}
Also used : TestVerifyCode(com.ngtesting.platform.entity.TestVerifyCode) DetachedCriteria(org.hibernate.criterion.DetachedCriteria) List(java.util.List) Date(java.util.Date)

Example 2 with TestVerifyCode

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

the class AccountServiceImpl method genVerifyCodePers.

@Override
public TestVerifyCode genVerifyCodePers(Long userId) {
    TestUser user = (TestUser) get(TestUser.class, userId);
    if (user == null) {
        return null;
    }
    TestVerifyCode po = new TestVerifyCode();
    String code = UUID.randomUUID().toString().replaceAll("-", "");
    Date now = new Date();
    po.setRefId(user.getId());
    po.setCode(code);
    po.setCreateTime(now);
    po.setExpireTime(new Date(now.getTime() + 10 * 60 * 1000));
    saveOrUpdate(po);
    return po;
}
Also used : TestVerifyCode(com.ngtesting.platform.entity.TestVerifyCode) TestUser(com.ngtesting.platform.entity.TestUser) Date(java.util.Date)

Example 3 with TestVerifyCode

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

the class AccountServiceImpl method resetPasswordPers.

@Override
public TestUser resetPasswordPers(String verifyCode, String password) {
    String newToken = null;
    DetachedCriteria dc = DetachedCriteria.forClass(TestVerifyCode.class);
    dc.add(Restrictions.eq("code", verifyCode));
    dc.add(Restrictions.ge("expireTime", new Date()));
    dc.add(Restrictions.ne("deleted", true));
    dc.add(Restrictions.ne("disabled", true));
    dc.addOrder(Order.desc("id"));
    List<TestVerifyCode> ls = (List<TestVerifyCode>) findAllByCriteria(dc);
    if (ls.size() < 1) {
        return null;
    }
    TestVerifyCode code = ls.get(0);
    code.setDeleted(true);
    saveOrUpdate(code);
    TestUser user = (TestUser) get(TestUser.class, code.getRefId());
    if (user == null) {
        return null;
    }
    newToken = UUID.randomUUID().toString();
    user.setToken(newToken);
    if (password != null) {
        user.setPassword(password);
    }
    user.setLastLoginTime(new Date());
    saveOrUpdate(user);
    return user;
}
Also used : TestVerifyCode(com.ngtesting.platform.entity.TestVerifyCode) DetachedCriteria(org.hibernate.criterion.DetachedCriteria) List(java.util.List) TestUser(com.ngtesting.platform.entity.TestUser) Date(java.util.Date)

Example 4 with TestVerifyCode

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

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

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