123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- /*
- * *************************************************
- * Copyright (c) 2018 QMTH. All Rights Reserved.
- * Created by Deason on 2018-07-16 17:50:31.
- * *************************************************
- */
- package cn.com.qmth.examcloud.app.controller;
- import cn.com.qmth.examcloud.app.model.LoginInfo;
- import cn.com.qmth.examcloud.app.model.LoginType;
- import cn.com.qmth.examcloud.app.model.Result;
- import cn.com.qmth.examcloud.app.model.UserInfo;
- import cn.com.qmth.examcloud.app.service.BaseInfoService;
- import cn.com.qmth.examcloud.app.service.UserAuthService;
- import io.swagger.annotations.Api;
- import io.swagger.annotations.ApiOperation;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.web.bind.annotation.*;
- import static cn.com.qmth.examcloud.app.model.Constants.PARAM_APP_KEY;
- import static cn.com.qmth.examcloud.app.model.Constants.PARAM_APP_TOKEN;
- /**
- * 认证中心相关接口
- *
- * @version v1.0
- * @author: fengdesheng
- * @since: 2018/7/16
- */
- @RestController
- @RequestMapping("${$rmp}/v2")
- @Api(tags = "认证中心相关接口")
- public class UserAuthRestController {
- private final static Logger log = LoggerFactory.getLogger(UserAuthRestController.class);
- @Autowired
- private UserAuthService userAuthService;
- @Autowired
- private BaseInfoService baseInfoService;
- @ApiOperation(value = "登录接口", notes = "参数accountType值说明:学生身份证号类型=STUDENT_IDENTITY_NUMBER,学生学号类型=STUDENT_CODE,学生手机号类型=STUDENT_PHONE")
- @RequestMapping(value = "/user/login", method = {RequestMethod.GET, RequestMethod.POST})
- public Result<UserInfo> login(@RequestParam String account, @RequestParam String password, @RequestParam String accountType, @RequestParam(required = false) Long rootOrgId,
- @RequestParam(required = false) String domain, @RequestHeader String deviceId) throws Exception {
- LoginInfo loginInfo = new LoginInfo(account, password, accountType, rootOrgId, domain, deviceId, null);
- Result<UserInfo> result = userAuthService.login(loginInfo);
- if (result.isSuccess() && result.getData() != null) {
- //登录成功后缓存Token信息
- UserInfo userInfo = result.getData();
- loginInfo.setUserName(userInfo.getDisplayName());
- loginInfo.setKey(userInfo.getKey());
- loginInfo.setToken(userInfo.getToken());
- loginInfo.setAppToken(userInfo.getToken());
- userAuthService.cacheLoginInfo(loginInfo, userInfo.getKey());
- log.info(String.format("key:%s token:%s", userInfo.getKey(), userInfo.getToken()));
- }
- return result;
- }
- @ApiOperation(value = "验证码接口", notes = "参数accountType值说明:学生身份证号类型=STUDENT_IDENTITY_NUMBER,学生学号类型=STUDENT_CODE,学生手机号类型=STUDENT_PHONE")
- @RequestMapping(value = "/user/verify", method = {RequestMethod.GET, RequestMethod.POST})
- public Result<UserInfo> verifyLogin(@RequestParam String account, @RequestParam String smsCode, @RequestParam(required = false) Long rootOrgId,
- @RequestParam(required = false) String domain, @RequestHeader String deviceId) throws Exception {
- LoginInfo loginInfo = new LoginInfo(account, null, LoginType.STUDENT_PHONE.name(), rootOrgId, domain, deviceId, smsCode);
- Result<UserInfo> result = userAuthService.login(loginInfo);
- if (result.isSuccess() && result.getData() != null) {
- //登录成功后缓存Token信息
- UserInfo userInfo = result.getData();
- loginInfo.setUserName(userInfo.getDisplayName());
- loginInfo.setToken(userInfo.getToken());
- loginInfo.setKey(userInfo.getKey());
- loginInfo.setAppToken(userInfo.getToken());
- userAuthService.cacheLoginInfo(loginInfo, userInfo.getKey());
- log.info(String.format("key:%s token:%s", userInfo.getKey(), userInfo.getToken()));
- }
- return result;
- }
- @ApiOperation(value = "登出接口")
- @RequestMapping(value = "/user/logout", method = {RequestMethod.GET, RequestMethod.POST})
- public Result logout(@RequestHeader(name = PARAM_APP_KEY) String key, @RequestHeader(name = PARAM_APP_TOKEN) String token) throws Exception {
- return userAuthService.logout(key, token);
- }
- @ApiOperation(value = "获取用户信息接口")
- @RequestMapping(value = "/user/info", method = {RequestMethod.GET, RequestMethod.POST})
- public Result getUserInfo(@RequestHeader(name = PARAM_APP_KEY) String key, @RequestHeader(name = PARAM_APP_TOKEN) String token) throws Exception {
- //return userAuthService.getUserInfo(key, token);
- return baseInfoService.getStudentInfo(key, token);
- }
- @ApiOperation(value = "修改密码接口")
- @RequestMapping(value = "/user/update/password", method = {RequestMethod.GET, RequestMethod.POST})
- public Result updatePassword(@RequestHeader(name = PARAM_APP_KEY) String key, @RequestHeader(name = PARAM_APP_TOKEN) String token, @RequestParam Long studentId, @RequestParam String password,
- @RequestParam String newPassword) throws Exception {
- return userAuthService.updateStudentPassword(key, token, studentId, password, newPassword);
- }
- @ApiOperation(value = "重置密码接口")
- @RequestMapping(value = "/user/reset/password", method = {RequestMethod.GET, RequestMethod.POST})
- public Result updateNewPassword(@RequestHeader(name = PARAM_APP_KEY) String key, @RequestHeader(name = PARAM_APP_TOKEN) String token, @RequestParam String newPassword) throws Exception {
- return userAuthService.resetStudentPassword(key, token, newPassword);
- }
- @ApiOperation(value = "保存用户绑定的手机号接口")
- @RequestMapping(value = "/user/binding/phone", method = {RequestMethod.GET, RequestMethod.POST})
- public Result userBindingPhone(@RequestHeader(name = PARAM_APP_KEY) String key, @RequestHeader(name = PARAM_APP_TOKEN) String token, @RequestParam String phone, @RequestParam String code) throws Exception {
- return userAuthService.userBindingPhone(key, token, phone, code);
- }
- }
|