增加快速登录接口

This commit is contained in:
wanggeng 2024-12-04 09:58:26 +08:00
parent aab774220b
commit 9395e58307
5 changed files with 129 additions and 3 deletions

View File

@ -0,0 +1,41 @@
package cn.com.tenlion.operator.controller.app.api.systemuser;
import cn.com.tenlion.operator.service.quick.login.QuickLoginService;
import ink.wgink.annotation.CheckRequestBodyAnnotation;
import ink.wgink.interfaces.consts.ISystemConstant;
import ink.wgink.module.sms.service.sms.ISmsService;
import ink.wgink.pojo.result.SuccessResultData;
import ink.wgink.register.base.pojo.vos.RegisterPhoneVO;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* ClassName: QuickLoginAppController
* Description:
* Author: wanggeng
* Date: 2024/12/2 16:24
* Version: 1.0
*/
@Api(tags = ISystemConstant.API_TAGS_APP_PREFIX + "快速登录接口")
@RestController
@RequestMapping(ISystemConstant.APP_PREFIX + "/quick/login")
public class QuickLoginAppController {
@Autowired
private ISmsService smsService;
@Autowired
private QuickLoginService quickLoginService;
@PostMapping("phone")
@CheckRequestBodyAnnotation
public SuccessResultData<String> phone(@RequestBody RegisterPhoneVO registerPhoneVO) {
smsService.checkVerifyCode(registerPhoneVO.getPhone(), registerPhoneVO.getVerifyCode());
String token = quickLoginService.saveAndLogin(registerPhoneVO);
return new SuccessResultData<>(token);
}
}

View File

@ -8,7 +8,7 @@ import java.util.Collection;
public class LoginPhoneAuthToken extends AbstractAuthenticationToken {
private final Object principal;
private Object credentials;
private final Object credentials;
public LoginPhoneAuthToken(Object principal, Object credentials) {
super(null);

View File

@ -16,7 +16,7 @@ import java.util.Map;
/**
* 用户注册时候的监听
* */
*/
@Component
public class UserRegisterService implements IRegisterHandlerService, IRegisterWithExpandInfoHandlerService {
@ -40,7 +40,7 @@ public class UserRegisterService implements IRegisterHandlerService, IRegisterWi
throw new SaveException("角色不存在");
}
String roleName = "普通用户";
if(roleDTO.getRoleName().contains("代理商")) {
if (roleDTO.getRoleName().contains("代理商")) {
roleName = "代理商";
}
// 1.修改用户的角色

View File

@ -0,0 +1,26 @@
package cn.com.tenlion.operator.service.login.handler;
import cn.com.tenlion.operator.service.user.expand.UserExpandServiceImpl;
import ink.wgink.interfaces.expand.login.ILoginAppHandlerService;
import ink.wgink.pojo.bos.LoginAppUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* ClassName: LoginAppHandlerServiceImpl
* Description:
* Author: wanggeng
* Date: 2024/12/2 17:53
* Version: 1.0
*/
@Service
public class LoginAppHandlerServiceImpl implements ILoginAppHandlerService {
@Autowired
private UserExpandServiceImpl userExpandService;
@Override
public void handle(LoginAppUser loginAppUser) throws Exception {
userExpandService.updateRedis(loginAppUser.getUserId());
}
}

View File

@ -0,0 +1,59 @@
package cn.com.tenlion.operator.service.quick.login;
import ink.wgink.common.base.DefaultBaseService;
import ink.wgink.common.manager.env.EnvManager;
import ink.wgink.exceptions.base.SystemException;
import ink.wgink.login.app.pojo.vos.appsign.AppLoginPhoneVO;
import ink.wgink.login.app.service.appsign.IAppSignService;
import ink.wgink.register.base.pojo.vos.RegisterPhoneVO;
import ink.wgink.register.base.service.IRegisterService;
import ink.wgink.service.user.pojo.pos.UserPO;
import ink.wgink.service.user.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.HashMap;
/**
* ClassName: QuickLoginService
* Description:
* Author: wanggeng
* Date: 2024/12/2 16:25
* Version: 1.0
*/
@Service
public class QuickLoginService extends DefaultBaseService {
@Autowired
private IUserService userService;
@Autowired
private IRegisterService registerService;
@Autowired
private IAppSignService appSignService;
/**
* 新增和登录
*
* @param username
* @return
*/
public String saveAndLogin(RegisterPhoneVO registerPhoneVO) {
UserPO userPO = userService.getPOByUsername(registerPhoneVO.getPhone());
if (userPO == null) {
LOG.debug("用户不存在,注册用户");
}
try {
registerService.registerPhone(registerPhoneVO, new HashMap<String, Object>() {{
put("userRole", EnvManager.value("NORMAL_USER_ROLE_ID"));
}});
AppLoginPhoneVO appLoginPhoneVO = new AppLoginPhoneVO();
appLoginPhoneVO.setUsername(registerPhoneVO.getPhone());
return appSignService.phoneSign(appLoginPhoneVO);
} catch (Exception e) {
LOG.error(e.getMessage(), e);
throw new SystemException("登录失败");
}
}
}