auth登录接口
parent
2445549869
commit
f2047d31fe
|
@ -2,6 +2,7 @@ package doctor.auth.controller;
|
||||||
|
|
||||||
import doctor.auth.service.HealthService;
|
import doctor.auth.service.HealthService;
|
||||||
import doctor.auth.vo.DoctorUserVo;
|
import doctor.auth.vo.DoctorUserVo;
|
||||||
|
import doctor.common.core.domain.HealthR;
|
||||||
import doctor.common.core.domain.R;
|
import doctor.common.core.domain.R;
|
||||||
import doctor.common.security.service.TokenService;
|
import doctor.common.security.service.TokenService;
|
||||||
import doctor.system.api.model.LoginUser;
|
import doctor.system.api.model.LoginUser;
|
||||||
|
@ -21,9 +22,13 @@ public class HealthController {
|
||||||
private HealthService healthService;
|
private HealthService healthService;
|
||||||
|
|
||||||
@PostMapping("/login")
|
@PostMapping("/login")
|
||||||
public R<?> login(@RequestParam String email,String pwd) {
|
public HealthR<?> login(@RequestParam String email, @RequestParam String pwd) {
|
||||||
DoctorUserVo userInfo = healthService.login(email,pwd);
|
DoctorUserVo userInfo = healthService.login(email,pwd);
|
||||||
return R.ok(userInfo);
|
if (userInfo!=null){
|
||||||
|
return HealthR.ok(userInfo);
|
||||||
|
}else {
|
||||||
|
return HealthR.fail();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -29,19 +29,22 @@ public class HealthService {
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
Map<String, Object> token = tokenService.createToken(data);
|
if (s.equals(data.getSysUser().getPassword())){
|
||||||
String accessToken = (String) token.get("access_token");
|
Map<String, Object> token = tokenService.createToken(data);
|
||||||
doctorUserVo.setSessionId(accessToken);
|
String accessToken = (String) token.get("access_token");
|
||||||
doctorUserVo.setEmail(data.getSysUser().getEmail());
|
doctorUserVo.setSessionId(accessToken);
|
||||||
doctorUserVo.setUserId(data.getSysUser().getUserId().intValue());
|
doctorUserVo.setEmail(data.getSysUser().getEmail());
|
||||||
doctorUserVo.setUserName(data.getSysUser().getUserName());
|
doctorUserVo.setUserId(data.getSysUser().getUserId().intValue());
|
||||||
doctorUserVo.setNickName(data.getSysUser().getNickName());
|
doctorUserVo.setUserName(data.getSysUser().getUserName());
|
||||||
doctorUserVo.setJiGuangPwd(s);
|
doctorUserVo.setNickName(data.getSysUser().getNickName());
|
||||||
if (data.getSysUser().getSex()=="男"){
|
doctorUserVo.setJiGuangPwd(s);
|
||||||
doctorUserVo.setSex(0);
|
if (data.getSysUser().getSex()=="男"){
|
||||||
}else {
|
doctorUserVo.setSex(0);
|
||||||
doctorUserVo.setSex(1);
|
}else {
|
||||||
|
doctorUserVo.setSex(1);
|
||||||
|
}
|
||||||
|
return doctorUserVo;
|
||||||
}
|
}
|
||||||
return doctorUserVo;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,135 @@
|
||||||
|
package doctor.common.core.constant;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通用常量信息
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
*/
|
||||||
|
public class HealthConstants
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* UTF-8 字符集
|
||||||
|
*/
|
||||||
|
public static final String UTF8 = "UTF-8";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GBK 字符集
|
||||||
|
*/
|
||||||
|
public static final String GBK = "GBK";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* www主域
|
||||||
|
*/
|
||||||
|
public static final String WWW = "www.";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* RMI 远程方法调用
|
||||||
|
*/
|
||||||
|
public static final String LOOKUP_RMI = "rmi:";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* LDAP 远程方法调用
|
||||||
|
*/
|
||||||
|
public static final String LOOKUP_LDAP = "ldap:";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* LDAPS 远程方法调用
|
||||||
|
*/
|
||||||
|
public static final String LOOKUP_LDAPS = "ldaps:";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* http请求
|
||||||
|
*/
|
||||||
|
public static final String HTTP = "http://";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* https请求
|
||||||
|
*/
|
||||||
|
public static final String HTTPS = "https://";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 成功标记
|
||||||
|
*/
|
||||||
|
public static final String SUCCESS = "0000";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 失败标记
|
||||||
|
*/
|
||||||
|
public static final String FAIL = "9999";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 登录成功状态
|
||||||
|
*/
|
||||||
|
public static final String LOGIN_SUCCESS_STATUS = "0";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 登录失败状态
|
||||||
|
*/
|
||||||
|
public static final String LOGIN_FAIL_STATUS = "1";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 登录成功
|
||||||
|
*/
|
||||||
|
public static final String LOGIN_SUCCESS = "Success";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 注销
|
||||||
|
*/
|
||||||
|
public static final String LOGOUT = "Logout";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 注册
|
||||||
|
*/
|
||||||
|
public static final String REGISTER = "Register";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 登录失败
|
||||||
|
*/
|
||||||
|
public static final String LOGIN_FAIL = "Error";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 当前记录起始索引
|
||||||
|
*/
|
||||||
|
public static final String PAGE_NUM = "pageNum";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 每页显示记录数
|
||||||
|
*/
|
||||||
|
public static final String PAGE_SIZE = "pageSize";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 排序列
|
||||||
|
*/
|
||||||
|
public static final String ORDER_BY_COLUMN = "orderByColumn";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 排序的方向 "desc" 或者 "asc".
|
||||||
|
*/
|
||||||
|
public static final String IS_ASC = "isAsc";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 验证码有效期(分钟)
|
||||||
|
*/
|
||||||
|
public static final long CAPTCHA_EXPIRATION = 2;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 资源映射路径 前缀
|
||||||
|
*/
|
||||||
|
public static final String RESOURCE_PREFIX = "/profile";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 自动识别json对象白名单配置(仅允许解析的包名,范围越小越安全)
|
||||||
|
*/
|
||||||
|
public static final String[] JSON_WHITELIST_STR = { "org.springframework", "doctor" };
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 定时任务白名单配置(仅允许访问的包名,如其他需要可以自行添加)
|
||||||
|
*/
|
||||||
|
public static final String[] JOB_WHITELIST_STR = { "doctor" };
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 定时任务违规的字符
|
||||||
|
*/
|
||||||
|
public static final String[] JOB_ERROR_STR = { "java.net.URL", "javax.naming.InitialContext", "org.yaml.snakeyaml",
|
||||||
|
"org.springframework", "org.apache", "doctor.common.core.utils.file" };
|
||||||
|
}
|
|
@ -0,0 +1,117 @@
|
||||||
|
package doctor.common.core.domain;
|
||||||
|
|
||||||
|
import doctor.common.core.constant.Constants;
|
||||||
|
import doctor.common.core.constant.HealthConstants;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 响应信息主体
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
*/
|
||||||
|
public class HealthR<T> implements Serializable
|
||||||
|
{
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/** 成功 */
|
||||||
|
public static final String SUCCESS = HealthConstants.SUCCESS;
|
||||||
|
|
||||||
|
/** 失败 */
|
||||||
|
public static final String FAIL = HealthConstants.FAIL;
|
||||||
|
|
||||||
|
private String message;
|
||||||
|
|
||||||
|
private String status;
|
||||||
|
|
||||||
|
private T result;
|
||||||
|
|
||||||
|
public static <T> HealthR<T> ok()
|
||||||
|
{
|
||||||
|
return restResult(null,SUCCESS, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> HealthR<T> ok(T result)
|
||||||
|
{
|
||||||
|
return restResult(result,SUCCESS, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> HealthR<T> ok(T result, String message)
|
||||||
|
{
|
||||||
|
return restResult(result, SUCCESS, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> HealthR<T> fail()
|
||||||
|
{
|
||||||
|
return restResult(null,FAIL, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> HealthR<T> fail(String message)
|
||||||
|
{
|
||||||
|
return restResult(null, FAIL, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> HealthR<T> fail(T result)
|
||||||
|
{
|
||||||
|
return restResult(result,FAIL, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> HealthR<T> fail(T result, String message)
|
||||||
|
{
|
||||||
|
return restResult(result,FAIL, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> HealthR<T> fail(String status, String message)
|
||||||
|
{
|
||||||
|
return restResult(null, status, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static <T> HealthR<T> restResult(T result, String status, String message)
|
||||||
|
{
|
||||||
|
HealthR<T> apiResult = new HealthR<>();
|
||||||
|
apiResult.setStatus(status);
|
||||||
|
apiResult.setResult(result);
|
||||||
|
apiResult.setMessage(message);
|
||||||
|
return apiResult;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMessage()
|
||||||
|
{
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMessage(String message)
|
||||||
|
{
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getStatus()
|
||||||
|
{
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStatus(String status)
|
||||||
|
{
|
||||||
|
this.status = status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public T getResult()
|
||||||
|
{
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setResult(T result)
|
||||||
|
{
|
||||||
|
this.result = result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> Boolean isError(HealthR<T> ret)
|
||||||
|
{
|
||||||
|
return !isSuccess(ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> Boolean isSuccess(HealthR<T> ret)
|
||||||
|
{
|
||||||
|
return HealthR.SUCCESS .equals(ret.getStatus()) ;
|
||||||
|
}
|
||||||
|
}
|
|
@ -13,7 +13,7 @@ import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/doctor")
|
@RequestMapping("/doctor")
|
||||||
@DS("slave")
|
@DS("master")
|
||||||
public class SysDoctorController {
|
public class SysDoctorController {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
|
|
Loading…
Reference in New Issue