Search in sources :

Example 96 with AuthPassport

use of com.ngtesting.platform.util.AuthPassport 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 97 with AuthPassport

use of com.ngtesting.platform.util.AuthPassport 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)

Example 98 with AuthPassport

use of com.ngtesting.platform.util.AuthPassport 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 99 with AuthPassport

use of com.ngtesting.platform.util.AuthPassport 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 100 with AuthPassport

use of com.ngtesting.platform.util.AuthPassport in project ngtesting-platform by aaronchen2k.

the class SystemInterceptor method preHandle.

@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
    if (Constant.WEB_ROOT == null) {
        Constant.WEB_ROOT = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath() + "/";
    }
    if (Constant.WORK_DIR == null) {
        Constant.WORK_DIR = request.getSession().getServletContext().getRealPath("/");
        ;
    }
    if (handler.getClass().isAssignableFrom(HandlerMethod.class)) {
        // 方法上是否有身份验证注解
        AuthPassport authPassport = ((HandlerMethod) handler).getMethodAnnotation(AuthPassport.class);
        // 声明不验证权限
        if (authPassport != null && authPassport.validate() == false) {
            return true;
        }
        // 已经登录
        if (request.getSession().getAttribute(Constant.HTTP_SESSION_USER_KEY) != null || request.getSession().getAttribute(Constant.HTTP_SESSION_USER_KEY) != null) {
            return true;
        }
        // 根据不同package处理不同身份认证逻辑
        String packageName = ((HandlerMethod) handler).getBeanType().getPackage().getName();
        String token = request.getHeader("token");
        if (token == null) {
            token = request.getParameter("token");
        }
        // client请求鉴权
        if (packageName.startsWith(Constant.API_PACKAGE_FOR_CLIENT)) {
            if (StringUtils.isNotBlank(token)) {
                // 登录验证
                AccountService accountService = SpringContextHolder.getBean(AccountService.class);
                UserService userService = SpringContextHolder.getBean(UserService.class);
                TestUser user = accountService.getByToken(token.trim());
                UserVo userVo = userService.genVo(user);
                if (user != null) {
                    request.getSession().setAttribute(Constant.HTTP_SESSION_USER_KEY, userVo);
                    return true;
                }
            }
            Map<String, Object> result = new HashMap<String, Object>();
            result.put("code", RespCode.NOT_LOGIN.getCode());
            result.put("msg", "not login");
            WebUtils.renderJson(response, JSON.toJSONString(result));
            return false;
        }
    }
    return true;
}
Also used : UserVo(com.ngtesting.platform.vo.UserVo) UserService(com.ngtesting.platform.service.UserService) HashMap(java.util.HashMap) AccountService(com.ngtesting.platform.service.AccountService) TestUser(com.ngtesting.platform.entity.TestUser) HandlerMethod(org.springframework.web.method.HandlerMethod) AuthPassport(com.ngtesting.platform.util.AuthPassport)

Aggregations

AuthPassport (com.ngtesting.platform.util.AuthPassport)100 HashMap (java.util.HashMap)100 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)99 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)99 JSONObject (com.alibaba.fastjson.JSONObject)98 UserVo (com.ngtesting.platform.vo.UserVo)78 TestUser (com.ngtesting.platform.entity.TestUser)12 List (java.util.List)12 TestCase (com.ngtesting.platform.entity.TestCase)6 CasePriorityVo (com.ngtesting.platform.vo.CasePriorityVo)5 CaseTypeVo (com.ngtesting.platform.vo.CaseTypeVo)5 TestProject (com.ngtesting.platform.entity.TestProject)4 TestRun (com.ngtesting.platform.entity.TestRun)4 TestSuite (com.ngtesting.platform.entity.TestSuite)4 CustomFieldVo (com.ngtesting.platform.vo.CustomFieldVo)4 OrgGroupVo (com.ngtesting.platform.vo.OrgGroupVo)4 Page (com.ngtesting.platform.vo.Page)4 TestCaseInRunVo (com.ngtesting.platform.vo.TestCaseInRunVo)4 TestRunVo (com.ngtesting.platform.vo.TestRunVo)4 TestSuiteVo (com.ngtesting.platform.vo.TestSuiteVo)4