完善:完善用户登录 API,优化部分包结构(引入 MyBatis Plus、多数据源、P6Spy、Liquibase 等依赖,详情可见 README 介绍)

This commit is contained in:
2022-12-25 12:35:35 +08:00
parent 00e2b44d0e
commit 78e84e8941
28 changed files with 954 additions and 106 deletions

View File

@@ -1,68 +0,0 @@
/*
* 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.auth.model.entity;
import lombok.Data;
import top.charles7c.cnadmin.common.model.entity.BaseEntity;
/**
* 用户实体
*
* @author Charles7c
* @since 2022/12/21 20:42
*/
@Data
public class SysUser extends BaseEntity {
private static final long serialVersionUID = 1L;
/**
* 用户 ID
*/
private Long userId;
/**
* 用户名
*/
private String username;
/**
* 密码
*/
private String password;
/**
* 昵称
*/
private String nickname;
/**
* 性别0未知 1男 2女
*/
private Integer gender;
/**
* 头像
*/
private String avatar;
/**
* 状态1启用 2禁用
*/
private Integer status;
}

View File

@@ -1,37 +0,0 @@
/*
* 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.auth.service;
import top.charles7c.cnadmin.auth.model.entity.SysUser;
/**
* 用户业务接口
*
* @author Charles7c
* @since 2022/12/21 21:48
*/
public interface UserService {
/**
* 根据用户名查询
*
* @param username
* 用户名
* @return 用户信息
*/
SysUser getByUsername(String username);
}

View File

@@ -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();

View File

@@ -1,54 +0,0 @@
/*
* 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.auth.service.impl;
import java.util.Date;
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;
/**
* 用户业务实现类
*
* @author Charles7c
* @since 2022/12/21 21:49
*/
@Service
public class UserServiceImpl implements UserService {
@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;
}
}