This commit is contained in:
xiaoqiantx223 2024-07-18 14:01:43 +08:00
parent 1289e2a378
commit 28bc67b88a
3 changed files with 24 additions and 10 deletions

View File

@ -12,4 +12,5 @@ auth:
- /maku/t_user/login
- /maku/t_user/updateUser
- /maku/t_user/register
- /maku/t_user/logout
- /maku/t_user/logout
- /maku/t_user/info/{username}

View File

@ -1,5 +1,7 @@
package net.maku.maku.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
@ -13,14 +15,16 @@ import net.maku.maku.entity.TUserEntity;
import net.maku.maku.service.TUserService;
import net.maku.maku.query.TUserQuery;
import net.maku.maku.vo.TUserVO;
import oracle.jdbc.proxy.annotation.Post;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import jakarta.validation.Valid;
import java.time.Duration;
import java.util.List;
import java.util.UUID;
/**
*
@ -36,6 +40,7 @@ public class TUserController {
private final TUserService tUserService;
private final RedisCache redisCache;
@PostMapping("/register")
@Operation(summary = "注册")
public ResponseEntity<Result<String>> register(@RequestBody TUserEntity entity) {
@ -54,28 +59,38 @@ public class TUserController {
public Result login(@RequestBody TUserEntity entity){
TUserEntity entity1 = tUserService.login(entity);
if(ObjectUtils.isNotNull(entity1)){
return Result.ok(entity1);
String token = UUID.randomUUID()+"";
redisCache.set(token, entity1);
return Result.ok(token);
}else {
return Result.error("登录失败");
}
}
@GetMapping("/updateUser")
@PutMapping("/updateUser")
@Operation(summary = "修改")
public Result<TUserVO> updateUser(@RequestBody TUserVO vo){
TUserVO tUserVO = tUserService.updateUser(vo);
return Result.ok(tUserVO);
}
//根据用户的用户名获取属性
// @PostMapping("/info/{username}")
// @Operation(summary = "用户中心")
// public Result findByUsername(@PathVariable String username){
// QueryWrapper<TUserEntity> wrapper = new QueryWrapper<>();
// wrapper.eq(,username);
// return Result.ok();
// }
@PostMapping("/logout")
@Operation(summary = "退出登录")
public Result<String> logout(HttpServletRequest request) {
String token = request.getHeader("token");
if (token == null) {
return Result.error("token为空");
}
Object o = redisCache.get(token);
if (o != null) {
redisCache.delete(token);

View File

@ -69,9 +69,6 @@ public class TUserServiceImpl extends BaseServiceImpl<TUserDao, TUserEntity> imp
wrapper.eq(TUserEntity::getPassword, entity.getPassword());
TUserEntity one = getOne(wrapper);
if(ObjectUtils.isNotNull(one)) {
UUID uuid = UUID.randomUUID();
one.setAvatar(uuid.toString());
updateById(one);
return one;
}
return null;
@ -80,6 +77,7 @@ public class TUserServiceImpl extends BaseServiceImpl<TUserDao, TUserEntity> imp
@Override
public TUserVO updateUser(TUserVO vo) {
TUserEntity entity = new TUserEntity();
entity.setId(vo.getId());
entity.setUsername(vo.getUsername());
entity.setPassword(vo.getPassword());
updateById(entity);