mirror of
https://github.com/continew-org/continew-admin.git
synced 2025-09-11 16:57:12 +08:00
完善:完善用户登录 API,优化部分包结构(引入 MyBatis Plus、多数据源、P6Spy、Liquibase 等依赖,详情可见 README 介绍)
This commit is contained in:
@@ -21,13 +21,16 @@ import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
|
||||
import top.charles7c.cnadmin.auth.model.entity.SysUser;
|
||||
import top.charles7c.cnadmin.auth.service.LoginService;
|
||||
import top.charles7c.cnadmin.auth.service.UserService;
|
||||
import top.charles7c.cnadmin.common.consts.CommonConstants;
|
||||
import top.charles7c.cnadmin.common.model.dto.LoginUser;
|
||||
import top.charles7c.cnadmin.common.util.CheckUtils;
|
||||
import top.charles7c.cnadmin.common.util.SecureUtils;
|
||||
import top.charles7c.cnadmin.common.util.helper.LoginHelper;
|
||||
import top.charles7c.cnadmin.system.model.entity.SysUser;
|
||||
import top.charles7c.cnadmin.system.service.UserService;
|
||||
|
||||
/**
|
||||
* 登录业务实现类
|
||||
@@ -53,7 +56,8 @@ public class LoginServiceImpl implements LoginService {
|
||||
CheckUtils.exIfEqual(CommonConstants.STATUS_DISABLE, sysUser.getStatus(), "此账号已被禁用,如有疑问,请联系管理员");
|
||||
|
||||
// 登录
|
||||
StpUtil.login(userId);
|
||||
LoginUser loginUser = BeanUtil.copyProperties(sysUser, LoginUser.class);
|
||||
LoginHelper.login(loginUser);
|
||||
|
||||
// 返回令牌
|
||||
return StpUtil.getTokenValue();
|
||||
|
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package top.charles7c.cnadmin.system.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
import top.charles7c.cnadmin.system.model.entity.SysUser;
|
||||
|
||||
/**
|
||||
* 用户 Mapper
|
||||
*
|
||||
* @author Charles7c
|
||||
* @since 2022/12/22 21:47
|
||||
*/
|
||||
public interface UserMapper extends BaseMapper<SysUser> {}
|
@@ -14,10 +14,15 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package top.charles7c.cnadmin.auth.model.entity;
|
||||
package top.charles7c.cnadmin.system.model.entity;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
|
||||
import top.charles7c.cnadmin.common.model.entity.BaseEntity;
|
||||
|
||||
/**
|
||||
@@ -27,6 +32,7 @@ import top.charles7c.cnadmin.common.model.entity.BaseEntity;
|
||||
* @since 2022/12/21 20:42
|
||||
*/
|
||||
@Data
|
||||
@TableName("sys_user")
|
||||
public class SysUser extends BaseEntity {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
@@ -34,6 +40,7 @@ public class SysUser extends BaseEntity {
|
||||
/**
|
||||
* 用户 ID
|
||||
*/
|
||||
@TableId
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
@@ -41,28 +48,48 @@ public class SysUser extends BaseEntity {
|
||||
*/
|
||||
private String username;
|
||||
|
||||
/**
|
||||
* 密码
|
||||
*/
|
||||
private String password;
|
||||
|
||||
/**
|
||||
* 昵称
|
||||
*/
|
||||
private String nickname;
|
||||
|
||||
/**
|
||||
* 密码
|
||||
*/
|
||||
private String password;
|
||||
|
||||
/**
|
||||
* 性别(0未知 1男 2女)
|
||||
*/
|
||||
private Integer gender;
|
||||
|
||||
/**
|
||||
* 头像
|
||||
* 手机号码
|
||||
*/
|
||||
private String phone;
|
||||
|
||||
/**
|
||||
* 邮箱
|
||||
*/
|
||||
private String email;
|
||||
|
||||
/**
|
||||
* 头像地址
|
||||
*/
|
||||
private String avatar;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
private String notes;
|
||||
|
||||
/**
|
||||
* 状态(1启用 2禁用)
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 最后一次修改密码的时间
|
||||
*/
|
||||
private Date pwdResetTime;
|
||||
}
|
@@ -14,9 +14,9 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package top.charles7c.cnadmin.auth.service;
|
||||
package top.charles7c.cnadmin.system.service;
|
||||
|
||||
import top.charles7c.cnadmin.auth.model.entity.SysUser;
|
||||
import top.charles7c.cnadmin.system.model.entity.SysUser;
|
||||
|
||||
/**
|
||||
* 用户业务接口
|
@@ -14,15 +14,17 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package top.charles7c.cnadmin.auth.service.impl;
|
||||
package top.charles7c.cnadmin.system.service.impl;
|
||||
|
||||
import java.util.Date;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import top.charles7c.cnadmin.auth.model.entity.SysUser;
|
||||
import top.charles7c.cnadmin.auth.service.UserService;
|
||||
import top.charles7c.cnadmin.common.util.SecureUtils;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
|
||||
import top.charles7c.cnadmin.system.mapper.UserMapper;
|
||||
import top.charles7c.cnadmin.system.model.entity.SysUser;
|
||||
import top.charles7c.cnadmin.system.service.UserService;
|
||||
|
||||
/**
|
||||
* 用户业务实现类
|
||||
@@ -31,24 +33,13 @@ import top.charles7c.cnadmin.common.util.SecureUtils;
|
||||
* @since 2022/12/21 21:49
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class UserServiceImpl implements UserService {
|
||||
|
||||
private final UserMapper userMapper;
|
||||
|
||||
@Override
|
||||
public SysUser getByUsername(String username) {
|
||||
if (!"admin".equals(username)) {
|
||||
return null;
|
||||
}
|
||||
SysUser sysUser = new SysUser();
|
||||
sysUser.setUserId(1L);
|
||||
sysUser.setUsername("admin");
|
||||
sysUser.setPassword(SecureUtils.md5Salt("123456", sysUser.getUserId().toString()));
|
||||
sysUser.setNickname("超级管理员");
|
||||
sysUser.setGender(1);
|
||||
sysUser.setStatus(1);
|
||||
sysUser.setCreateUser(1L);
|
||||
sysUser.setCreateTime(new Date());
|
||||
sysUser.setUpdateUser(1L);
|
||||
sysUser.setUpdateTime(new Date());
|
||||
return sysUser;
|
||||
return userMapper.selectOne(Wrappers.<SysUser>lambdaQuery().eq(SysUser::getUsername, username));
|
||||
}
|
||||
}
|
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace="top.charles7c.cnadmin.system.mapper.UserMapper">
|
||||
</mapper>
|
Reference in New Issue
Block a user