mirror of
https://github.com/continew-org/continew-admin.git
synced 2025-10-27 06:57:12 +08:00
新增:新增上传头像 API,采用本地存储方式存储头像
This commit is contained in:
@@ -26,9 +26,9 @@ import cn.hutool.core.bean.BeanUtil;
|
||||
import top.charles7c.cnadmin.auth.service.LoginService;
|
||||
import top.charles7c.cnadmin.common.enums.DisEnableStatusEnum;
|
||||
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.common.util.validate.ValidationUtils;
|
||||
import top.charles7c.cnadmin.system.model.entity.SysUser;
|
||||
import top.charles7c.cnadmin.system.service.UserService;
|
||||
|
||||
@@ -50,10 +50,11 @@ public class LoginServiceImpl implements LoginService {
|
||||
SysUser sysUser = userService.getByUsername(username);
|
||||
|
||||
// 校验
|
||||
CheckUtils.exIfNull(sysUser, "用户名或密码错误");
|
||||
ValidationUtils.exIfNull(sysUser, "用户名或密码错误");
|
||||
Long userId = sysUser.getUserId();
|
||||
CheckUtils.exIfNotEqual(sysUser.getPassword(), SecureUtils.md5Salt(password, userId.toString()), "用户名或密码错误");
|
||||
CheckUtils.exIfEqual(DisEnableStatusEnum.DISABLE, sysUser.getStatus(), "此账号已被禁用,如有疑问,请联系管理员");
|
||||
ValidationUtils.exIfNotEqual(sysUser.getPassword(), SecureUtils.md5Salt(password, userId.toString()),
|
||||
"用户名或密码错误");
|
||||
ValidationUtils.exIfEqual(DisEnableStatusEnum.DISABLE, sysUser.getStatus(), "此账号已被禁用,如有疑问,请联系管理员");
|
||||
|
||||
// 登录
|
||||
LoginUser loginUser = BeanUtil.copyProperties(sysUser, LoginUser.class);
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* 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.model.vo;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
|
||||
/**
|
||||
* 头像信息
|
||||
*
|
||||
* @author Charles7c
|
||||
* @since 2023/1/2 16:29
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
@Schema(description = "头像信息")
|
||||
public class AvatarVO implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 头像地址
|
||||
*/
|
||||
@Schema(description = "头像地址")
|
||||
private String avatar;
|
||||
}
|
||||
@@ -34,4 +34,14 @@ public interface UserService {
|
||||
* @return 用户信息
|
||||
*/
|
||||
SysUser getByUsername(String username);
|
||||
|
||||
/**
|
||||
* 修改头像
|
||||
*
|
||||
* @param avatar
|
||||
* 头像路径
|
||||
* @param userId
|
||||
* 用户ID
|
||||
*/
|
||||
void updateAvatar(String avatar, Long userId);
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ import lombok.RequiredArgsConstructor;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
|
||||
import top.charles7c.cnadmin.system.mapper.UserMapper;
|
||||
@@ -42,4 +43,10 @@ public class UserServiceImpl implements UserService {
|
||||
public SysUser getByUsername(String username) {
|
||||
return userMapper.selectOne(Wrappers.<SysUser>lambdaQuery().eq(SysUser::getUsername, username));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateAvatar(String avatar, Long userId) {
|
||||
userMapper.update(null,
|
||||
new LambdaUpdateWrapper<SysUser>().set(SysUser::getAvatar, avatar).eq(SysUser::getUserId, userId));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user