|
|
|
@ -4,6 +4,7 @@ import cn.binarywang.wx.miniapp.api.WxMaService;
|
|
|
|
import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo;
|
|
|
|
import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo;
|
|
|
|
import cn.binarywang.wx.miniapp.util.WxMaConfigHolder;
|
|
|
|
import cn.binarywang.wx.miniapp.util.WxMaConfigHolder;
|
|
|
|
import cn.dev33.satoken.annotation.SaIgnore;
|
|
|
|
import cn.dev33.satoken.annotation.SaIgnore;
|
|
|
|
|
|
|
|
import cn.dev33.satoken.context.SaHolder;
|
|
|
|
import cn.dev33.satoken.stp.StpUtil;
|
|
|
|
import cn.dev33.satoken.stp.StpUtil;
|
|
|
|
import cn.hutool.core.map.MapUtil;
|
|
|
|
import cn.hutool.core.map.MapUtil;
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
@ -30,6 +31,7 @@ import com.ruoyi.system.service.ISysUserService;
|
|
|
|
import com.ruoyi.system.service.SysLoginService;
|
|
|
|
import com.ruoyi.system.service.SysLoginService;
|
|
|
|
import lombok.Data;
|
|
|
|
import lombok.Data;
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
import me.chanjar.weixin.common.error.WxErrorException;
|
|
|
|
import me.chanjar.weixin.common.error.WxErrorException;
|
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
@ -48,6 +50,7 @@ import java.util.Map;
|
|
|
|
@Validated
|
|
|
|
@Validated
|
|
|
|
@RequiredArgsConstructor
|
|
|
|
@RequiredArgsConstructor
|
|
|
|
@RestController
|
|
|
|
@RestController
|
|
|
|
|
|
|
|
@Slf4j
|
|
|
|
public class SysLoginController {
|
|
|
|
public class SysLoginController {
|
|
|
|
|
|
|
|
|
|
|
|
private final SysLoginService loginService;
|
|
|
|
private final SysLoginService loginService;
|
|
|
|
@ -59,6 +62,7 @@ public class SysLoginController {
|
|
|
|
private final RuoYiConfig config;
|
|
|
|
private final RuoYiConfig config;
|
|
|
|
|
|
|
|
|
|
|
|
private final ISysConfigService configService;
|
|
|
|
private final ISysConfigService configService;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 登录方法
|
|
|
|
* 登录方法
|
|
|
|
*
|
|
|
|
*
|
|
|
|
@ -101,25 +105,27 @@ public class SysLoginController {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 登录
|
|
|
|
* 登录
|
|
|
|
|
|
|
|
*
|
|
|
|
* @param username 用户名
|
|
|
|
* @param username 用户名
|
|
|
|
* @param password 密码 使用RSA算法公钥加密后的字符串
|
|
|
|
* @param password 密码 使用RSA算法公钥加密后的字符串
|
|
|
|
* @return
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@PostMapping("/login-pwd")
|
|
|
|
@PostMapping("/login-pwd")
|
|
|
|
@SaIgnore
|
|
|
|
@SaIgnore
|
|
|
|
public R login(String username,String password) {
|
|
|
|
public R login(String username, String password) {
|
|
|
|
if(StrUtil.hasBlank(username,password)) {
|
|
|
|
if (StrUtil.hasBlank(username, password)) {
|
|
|
|
throw new ServiceException("用户名或密码不能为空",1);
|
|
|
|
throw new ServiceException("用户名或密码不能为空", 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
password = properties.getRsa().decryptStr(password, KeyType.PrivateKey);
|
|
|
|
password = properties.getRsa().decryptStr(password, KeyType.PrivateKey);
|
|
|
|
}catch (Exception ex){
|
|
|
|
} catch (Exception ex) {
|
|
|
|
throw new ServiceException("密码必须为RSA加密后",2);
|
|
|
|
throw new ServiceException("密码必须为RSA加密后", 2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return R.ok().setMsg("登录成功").setData(loginService.login(username,password));
|
|
|
|
return R.ok().setMsg("登录成功").setData(loginService.login(username, password));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
@ -132,7 +138,7 @@ public class SysLoginController {
|
|
|
|
@PostMapping("/smsLogin")
|
|
|
|
@PostMapping("/smsLogin")
|
|
|
|
public R<?> smsLogin(@Validated @RequestBody SmsLoginBody smsLoginBody) {
|
|
|
|
public R<?> smsLogin(@Validated @RequestBody SmsLoginBody smsLoginBody) {
|
|
|
|
String token = loginService.smsLogin(smsLoginBody.getPhonenumber(), smsLoginBody.getSmsCode());
|
|
|
|
String token = loginService.smsLogin(smsLoginBody.getPhonenumber(), smsLoginBody.getSmsCode());
|
|
|
|
return R.map().put(Constants.TOKEN,token);
|
|
|
|
return R.map().put(Constants.TOKEN, token);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
@ -145,7 +151,7 @@ public class SysLoginController {
|
|
|
|
@PostMapping("/xcxLogin")
|
|
|
|
@PostMapping("/xcxLogin")
|
|
|
|
public R<?> xcxLogin(@NotBlank(message = "{xcx.code.not.blank}") String xcxCode) {
|
|
|
|
public R<?> xcxLogin(@NotBlank(message = "{xcx.code.not.blank}") String xcxCode) {
|
|
|
|
String token = loginService.xcxLoginByOpenId(xcxCode);
|
|
|
|
String token = loginService.xcxLoginByOpenId(xcxCode);
|
|
|
|
return R.map().put(Constants.TOKEN,token);
|
|
|
|
return R.map().put(Constants.TOKEN, token);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -154,7 +160,7 @@ public class SysLoginController {
|
|
|
|
@Dev
|
|
|
|
@Dev
|
|
|
|
public R<?> xcxOpenid(@NotBlank(message = "{xcx.code.not.blank}") String openid) {
|
|
|
|
public R<?> xcxOpenid(@NotBlank(message = "{xcx.code.not.blank}") String openid) {
|
|
|
|
String token = loginService.xcxLoginByOpenId(openid);
|
|
|
|
String token = loginService.xcxLoginByOpenId(openid);
|
|
|
|
return R.map().put(Constants.TOKEN,token);
|
|
|
|
return R.map().put(Constants.TOKEN, token);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -165,11 +171,11 @@ public class SysLoginController {
|
|
|
|
@NotBlank(message = "{not.null}") String nickname,
|
|
|
|
@NotBlank(message = "{not.null}") String nickname,
|
|
|
|
@NotBlank(message = "邀请码不能为空") String regCode
|
|
|
|
@NotBlank(message = "邀请码不能为空") String regCode
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
if(!regCode.equals(configService.selectConfigByKey("reg.code"))){
|
|
|
|
if (!regCode.equals(configService.selectConfigByKey("reg.code"))) {
|
|
|
|
throw new RuntimeException("邀请码不正确");
|
|
|
|
throw new RuntimeException("邀请码不正确");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
String token = loginService.xcxRegLoginByOpenid(code,avatar,nickname);
|
|
|
|
String token = loginService.xcxRegLoginByOpenid(code, avatar, nickname);
|
|
|
|
return R.map().put(Constants.TOKEN,token);
|
|
|
|
return R.map().put(Constants.TOKEN, token);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -177,14 +183,14 @@ public class SysLoginController {
|
|
|
|
@PostMapping("/xcxRegLoginByOpenid")
|
|
|
|
@PostMapping("/xcxRegLoginByOpenid")
|
|
|
|
@Dev
|
|
|
|
@Dev
|
|
|
|
public R<?> xcxRegLoginByOpenid(String openid, MultipartFile avatar, String nickname) {
|
|
|
|
public R<?> xcxRegLoginByOpenid(String openid, MultipartFile avatar, String nickname) {
|
|
|
|
String token = loginService.xcxRegLoginByOpenid(openid,avatar,nickname);
|
|
|
|
String token = loginService.xcxRegLoginByOpenid(openid, avatar, nickname);
|
|
|
|
return R.map().put(Constants.TOKEN,token);
|
|
|
|
return R.map().put(Constants.TOKEN, token);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 退出登录
|
|
|
|
* 退出登录
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@RequestMapping(value = "/logout",method = {RequestMethod.POST,RequestMethod.GET})
|
|
|
|
@RequestMapping(value = "/logout", method = {RequestMethod.POST, RequestMethod.GET})
|
|
|
|
public R<Void> logout() {
|
|
|
|
public R<Void> logout() {
|
|
|
|
loginService.logout();
|
|
|
|
loginService.logout();
|
|
|
|
return R.ok("退出成功");
|
|
|
|
return R.ok("退出成功");
|
|
|
|
|