修改登录API逻辑
This commit is contained in:
@@ -1,9 +1,6 @@
|
||||
package com.guo.learningprogresstracker.service.impl;
|
||||
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.guo.learningprogresstracker.domain.entity.CommonResult;
|
||||
import com.guo.learningprogresstracker.domain.entity.UserEntity;
|
||||
import com.guo.learningprogresstracker.exception.AppException;
|
||||
import com.guo.learningprogresstracker.service.LoginService;
|
||||
import com.guo.learningprogresstracker.service.UserService;
|
||||
@@ -14,12 +11,10 @@ import org.springframework.stereotype.Service;
|
||||
public class LoginServiceImpl implements LoginService {
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
@Override
|
||||
public String login(String username, String password) throws AppException {
|
||||
UserEntity userEntity = userService.getOneOpt(Wrappers.<UserEntity>lambdaQuery()
|
||||
.eq(UserEntity::getUserName, username)
|
||||
.eq(UserEntity::getUserPassword, password)).orElseThrow(() -> new AppException("账号或密码错误!"));
|
||||
StpUtil.login(userEntity.getId());
|
||||
public String login(String userId) throws AppException {
|
||||
StpUtil.login(userId);
|
||||
//todo Token只在此处使用了,属于后续优化点
|
||||
return StpUtil.getTokenInfo().getTokenValue();
|
||||
}
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
package com.guo.learningprogresstracker.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.guo.learningprogresstracker.domain.entity.UserEntity;
|
||||
import com.guo.learningprogresstracker.exception.AppException;
|
||||
import com.guo.learningprogresstracker.service.UserService;
|
||||
import com.guo.learningprogresstracker.mapper.UserMapper;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
@@ -12,9 +15,18 @@ import org.springframework.stereotype.Service;
|
||||
* @createDate 2024-06-09 15:28:48
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class UserServiceImpl extends ServiceImpl<UserMapper, UserEntity>
|
||||
implements UserService{
|
||||
|
||||
@Override
|
||||
public String authenticate(String username, String password) throws AppException {
|
||||
|
||||
UserEntity userEntity = this.getOneOpt(Wrappers.<UserEntity>lambdaQuery()
|
||||
.eq(UserEntity::getUserName, username)
|
||||
.eq(UserEntity::getUserPassword, password)).orElseThrow(() -> new AppException("账号或密码错误!"));
|
||||
return userEntity.getId();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user