前台用户账号密码登录
This commit is contained in:
parent
608ff95255
commit
a44c907099
|
@ -177,6 +177,11 @@ public class Constants
|
||||||
*/
|
*/
|
||||||
public static final String USER_TYPE_WX = "USER_TYPE_WX";
|
public static final String USER_TYPE_WX = "USER_TYPE_WX";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 登录用户为APP账密登录
|
||||||
|
*/
|
||||||
|
public static final String USER_TYPE_APP = "USER_TYPE_APP";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 登录用户为PC
|
* 登录用户为PC
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -220,30 +220,24 @@ public class SysLoginService
|
||||||
* @param password
|
* @param password
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
|
||||||
public String appLogin(String username, String password) {
|
public String appLogin(String username, String password) {
|
||||||
// 登录前置校验
|
// 登录前置校验
|
||||||
loginPreCheck(username, password);
|
loginPreCheck(username, password);
|
||||||
// 用户验证
|
// 用户验证
|
||||||
Authentication authentication = null;
|
Authentication authentication = null;
|
||||||
try
|
try {
|
||||||
{
|
|
||||||
UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(username, password);
|
UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(username, password);
|
||||||
AuthenticationContextHolder.setContext(authenticationToken);
|
AuthenticationContextHolder.setContext(authenticationToken);
|
||||||
// 把用户登录类型放在上下文中的details属性中,在UserDetailsServiceImpl.loadUserByUsername中获取
|
// 把用户登录类型放在上下文中的details属性中,在UserDetailsServiceImpl.loadUserByUsername中获取
|
||||||
authenticationToken.setDetails(Constants.USER_TYPE_WX);
|
authenticationToken.setDetails(Constants.USER_TYPE_APP);
|
||||||
// 该方法会去调用UserDetailsServiceImpl.loadUserByUsername
|
// 该方法会去调用UserDetailsServiceImpl.loadUserByUsername
|
||||||
authentication = authenticationManager.authenticate(authenticationToken);
|
authentication = authenticationManager.authenticate(authenticationToken);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e) {
|
||||||
{
|
if (e instanceof BadCredentialsException) {
|
||||||
if (e instanceof BadCredentialsException)
|
|
||||||
{
|
|
||||||
AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.password.not.match")));
|
AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.password.not.match")));
|
||||||
throw new UserPasswordNotMatchException();
|
throw new UserPasswordNotMatchException();
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, e.getMessage()));
|
AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, e.getMessage()));
|
||||||
throw new ServiceException(e.getMessage());
|
throw new ServiceException(e.getMessage());
|
||||||
}
|
}
|
||||||
|
@ -285,7 +279,7 @@ public class SysLoginService
|
||||||
|
|
||||||
Authentication authentication = null;
|
Authentication authentication = null;
|
||||||
try {
|
try {
|
||||||
UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(user.getUserName(), Constants.CUSTOM_LOGIN_WX);
|
UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(user.getPhonenumber(), Constants.CUSTOM_LOGIN_WX);
|
||||||
// 用户名和密码等信息保存在一个上下文中,只要是同一线程等会就能拿到用户名和密码,也就是能在loadUserByUsername(String username)方法中进行密码验证等
|
// 用户名和密码等信息保存在一个上下文中,只要是同一线程等会就能拿到用户名和密码,也就是能在loadUserByUsername(String username)方法中进行密码验证等
|
||||||
AuthenticationContextHolder.setContext(authenticationToken);
|
AuthenticationContextHolder.setContext(authenticationToken);
|
||||||
// 把用户登录类型放在上下文中的details属性中,在UserDetailsServiceImpl.loadUserByUsername中获取
|
// 把用户登录类型放在上下文中的details属性中,在UserDetailsServiceImpl.loadUserByUsername中获取
|
||||||
|
|
|
@ -2,6 +2,7 @@ package com.ruoyi.framework.web.service;
|
||||||
|
|
||||||
import com.ruoyi.common.constant.Constants;
|
import com.ruoyi.common.constant.Constants;
|
||||||
import com.ruoyi.common.core.domain.entity.SmUser;
|
import com.ruoyi.common.core.domain.entity.SmUser;
|
||||||
|
import com.ruoyi.common.enums.LoginType;
|
||||||
import com.ruoyi.framework.security.context.AuthenticationContextHolder;
|
import com.ruoyi.framework.security.context.AuthenticationContextHolder;
|
||||||
import com.ruoyi.ss.user.service.ISmUserService;
|
import com.ruoyi.ss.user.service.ISmUserService;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
|
@ -52,47 +53,24 @@ public class UserDetailsServiceImpl implements UserDetailsService
|
||||||
if (authentication != null && authentication.getDetails() != null) {
|
if (authentication != null && authentication.getDetails() != null) {
|
||||||
String userType = (String) authentication.getDetails();
|
String userType = (String) authentication.getDetails();
|
||||||
if(Constants.USER_TYPE_PC.equals(userType)){
|
if(Constants.USER_TYPE_PC.equals(userType)){
|
||||||
// PC用户登录
|
// PC 用户登录
|
||||||
SysUser user = userService.selectUserByUserName(username);
|
SysUser user = userService.selectUserByUserName(username);
|
||||||
if (StringUtils.isNull(user))
|
this.checkUser(user, username);
|
||||||
{
|
passwordService.validate(user);
|
||||||
log.info("登录用户:{} 不存在.", username);
|
return createLoginUser(user);
|
||||||
throw new ServiceException(MessageUtils.message("user.not.exists"));
|
} else if(Constants.USER_TYPE_WX.equals(userType)) {
|
||||||
}
|
// app 用户微信登录
|
||||||
else if (UserStatus.DELETED.getCode().equals(user.getDelFlag()))
|
SmUser user = smUserService.selectUserByPhone(username);
|
||||||
{
|
this.checkUser(user, username);
|
||||||
log.info("登录用户:{} 已被删除.", username);
|
return createLoginUser(user);
|
||||||
throw new ServiceException(MessageUtils.message("user.password.delete"));
|
} else if(Constants.USER_TYPE_APP.equals(userType)) {
|
||||||
}
|
// app 用户手机号密码登录
|
||||||
else if (UserStatus.DISABLE.getCode().equals(user.getStatus()))
|
SmUser user = smUserService.selectUserByPhone(username);
|
||||||
{
|
this.checkUser(user, username);
|
||||||
log.info("登录用户:{} 已被停用.", username);
|
|
||||||
throw new ServiceException(MessageUtils.message("user.blocked"));
|
|
||||||
}
|
|
||||||
|
|
||||||
passwordService.validate(user);
|
passwordService.validate(user);
|
||||||
|
|
||||||
return createLoginUser(user);
|
return createLoginUser(user);
|
||||||
} else {
|
} else {
|
||||||
// app用户登录
|
throw new ServiceException("不支持的登录方式");
|
||||||
SmUser user = smUserService.selectUserByUserName(username);
|
|
||||||
if (StringUtils.isNull(user))
|
|
||||||
{
|
|
||||||
log.info("登录用户:{} 不存在.", username);
|
|
||||||
throw new ServiceException(MessageUtils.message("user.not.exists"));
|
|
||||||
}
|
|
||||||
else if (UserStatus.DELETED.getCode().equals(user.getDelFlag()))
|
|
||||||
{
|
|
||||||
log.info("登录用户:{} 已被删除.", username);
|
|
||||||
throw new ServiceException(MessageUtils.message("user.password.delete"));
|
|
||||||
}
|
|
||||||
else if (UserStatus.DISABLE.getCode().equals(user.getStatus()))
|
|
||||||
{
|
|
||||||
log.info("登录用户:{} 已被停用.", username);
|
|
||||||
throw new ServiceException(MessageUtils.message("user.blocked"));
|
|
||||||
}
|
|
||||||
|
|
||||||
return createLoginUser(user);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
@ -101,6 +79,48 @@ public class UserDetailsServiceImpl implements UserDetailsService
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 校验用户账号是否正常
|
||||||
|
*/
|
||||||
|
private void checkUser(SysUser user, String username) {
|
||||||
|
if (StringUtils.isNull(user))
|
||||||
|
{
|
||||||
|
log.info("登录用户:{} 不存在.", username);
|
||||||
|
throw new ServiceException(MessageUtils.message("user.not.exists"));
|
||||||
|
}
|
||||||
|
else if (UserStatus.DELETED.getCode().equals(user.getDelFlag()))
|
||||||
|
{
|
||||||
|
log.info("登录用户:{} 已被删除.", username);
|
||||||
|
throw new ServiceException(MessageUtils.message("user.password.delete"));
|
||||||
|
}
|
||||||
|
else if (UserStatus.DISABLE.getCode().equals(user.getStatus()))
|
||||||
|
{
|
||||||
|
log.info("登录用户:{} 已被停用.", username);
|
||||||
|
throw new ServiceException(MessageUtils.message("user.blocked"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 校验用户账号是否正常
|
||||||
|
*/
|
||||||
|
private void checkUser(SmUser user, String username) {
|
||||||
|
if (StringUtils.isNull(user))
|
||||||
|
{
|
||||||
|
log.info("登录用户:{} 不存在.", username);
|
||||||
|
throw new ServiceException(MessageUtils.message("user.not.exists"));
|
||||||
|
}
|
||||||
|
else if (UserStatus.DELETED.getCode().equals(user.getDelFlag()))
|
||||||
|
{
|
||||||
|
log.info("登录用户:{} 已被删除.", username);
|
||||||
|
throw new ServiceException(MessageUtils.message("user.password.delete"));
|
||||||
|
}
|
||||||
|
else if (UserStatus.DISABLE.getCode().equals(user.getStatus()))
|
||||||
|
{
|
||||||
|
log.info("登录用户:{} 已被停用.", username);
|
||||||
|
throw new ServiceException(MessageUtils.message("user.blocked"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public UserDetails createLoginUser(SysUser user)
|
public UserDetails createLoginUser(SysUser user)
|
||||||
{
|
{
|
||||||
return new LoginUser(user.getUserId(), user.getDeptId(), user, permissionService.getMenuPermission(user));
|
return new LoginUser(user.getUserId(), user.getDeptId(), user, permissionService.getMenuPermission(user));
|
||||||
|
|
|
@ -310,13 +310,11 @@ public class SmUserServiceImpl implements ISmUserService
|
||||||
ServiceUtil.assertion(user == null, "用户不存在");
|
ServiceUtil.assertion(user == null, "用户不存在");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 判断是否重复注册
|
// 判断手机号是否重复
|
||||||
SmUserVo repeatPhone = selectUserByPhone(data.getPhonenumber());
|
SmUserVo repeatPhone = selectUserByPhone(data.getPhonenumber());
|
||||||
ServiceUtil.assertion(repeatPhone != null && !Objects.equals(repeatPhone.getUserId(), data.getUserId()), "用户手机号重复");
|
ServiceUtil.assertion(repeatPhone != null && !Objects.equals(repeatPhone.getUserId(), data.getUserId()), "用户手机号重复");
|
||||||
|
|
||||||
SmUserVo repeatIdCard = selectUserByIdCard(data.getIdentityCard());
|
// 判断微信openId是否重复
|
||||||
ServiceUtil.assertion(repeatIdCard != null && !Objects.equals(repeatIdCard.getUserId(), data.getUserId()), "用户身份证号重复");
|
|
||||||
|
|
||||||
SmUserVo repeatWxOpenId = selectUserByWxOpenId(data.getWxOpenId());
|
SmUserVo repeatWxOpenId = selectUserByWxOpenId(data.getWxOpenId());
|
||||||
ServiceUtil.assertion(repeatWxOpenId != null && repeatWxOpenId.getWxOpenId() != null &&
|
ServiceUtil.assertion(repeatWxOpenId != null && repeatWxOpenId.getWxOpenId() != null &&
|
||||||
!Objects.equals(repeatWxOpenId.getUserId(), data.getUserId()), "用户微信openId重复");
|
!Objects.equals(repeatWxOpenId.getUserId(), data.getUserId()), "用户微信openId重复");
|
||||||
|
|
|
@ -20,9 +20,9 @@ wx:
|
||||||
# apiV3密钥
|
# apiV3密钥
|
||||||
apiV3Key: 49819e0f0abdb2df3246f7b27f264d75
|
apiV3Key: 49819e0f0abdb2df3246f7b27f264d75
|
||||||
# 通知回调地址
|
# 通知回调地址
|
||||||
notifyUrl: https://kg.chuantewulian.cn/prod-api/app/pay/notify/wx # 正式环境
|
notifyUrl: https://kg.chuangtewl.com/prod-api/app/pay/notify/wx # 正式环境
|
||||||
# 退款通知回调地址
|
# 退款通知回调地址
|
||||||
refundNotifyUrl: https://kg.chuantewulian.cn/prod-api/app/pay/notify/wx/refund
|
refundNotifyUrl: https://kg.chuangtewl.com/prod-api/app/pay/notify/wx/refund
|
||||||
# 密钥所在位置
|
# 密钥所在位置
|
||||||
privateKeyPath: /www/wwwroot/smart-switch/wxpay/apiclient_key.pem
|
privateKeyPath: /www/wwwroot/smart-switch/wxpay/apiclient_key.pem
|
||||||
# 证书序列号
|
# 证书序列号
|
||||||
|
|
Loading…
Reference in New Issue
Block a user