From 7135ebeca4a0efb9b6e20b575d1ce2d4b6777d01 Mon Sep 17 00:00:00 2001 From: pikaqiudeshujia Date: Wed, 29 May 2024 09:33:36 +0800 Subject: [PATCH] =?UTF-8?q?release-=20=E7=94=A8=E6=88=B7=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E5=AF=86=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../luoo/user/controller/LoginController.java | 62 ++++++++++--------- .../com/luoo/user/dto/UserNameLoginDto.java | 26 ++++++++ .../luoo/user/service/UserInfoService.java | 12 ++++ 3 files changed, 70 insertions(+), 30 deletions(-) create mode 100644 luoo_user/src/main/java/com/luoo/user/dto/UserNameLoginDto.java diff --git a/luoo_user/src/main/java/com/luoo/user/controller/LoginController.java b/luoo_user/src/main/java/com/luoo/user/controller/LoginController.java index bbf2a1b..5de8c16 100644 --- a/luoo_user/src/main/java/com/luoo/user/controller/LoginController.java +++ b/luoo_user/src/main/java/com/luoo/user/controller/LoginController.java @@ -1,45 +1,40 @@ package com.luoo.user.controller; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.util.*; -import java.util.concurrent.TimeUnit; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - +import annotation.GlobalInterceptor; +import annotation.VerifyParam; +import api.Result; +import api.StatusCode; import com.alibaba.fastjson.JSONObject; +import com.luoo.user.dto.UserNameLoginDto; import com.luoo.user.dto.request.*; -import com.luoo.user.service.WeChatAouth2Service; -import com.luoo.user.util.IOSTokenUtils; -import org.apache.commons.lang.StringUtils; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.web.bind.annotation.*; - -import constants.Constants; -import controller.BaseController; - import com.luoo.user.dto.response.CountryCodeDTO; import com.luoo.user.dto.response.CreateImageCode; import com.luoo.user.pojo.UserInfo; import com.luoo.user.service.UserInfoService; -import com.luoo.user.util.NickNameUtil; - -import annotation.GlobalInterceptor; -import annotation.VerifyParam; -import api.Result; -import api.StatusCode; +import com.luoo.user.service.WeChatAouth2Service; +import com.luoo.user.util.IOSTokenUtils; +import constants.Constants; +import controller.BaseController; import enums.RequestFrequencyTypeEnum; -import enums.VerifyRegexEnum; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; -import util.IdWorker; +import org.apache.commons.lang.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; import util.JwtUtil; import util.StringTools; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.util.*; +import java.util.concurrent.TimeUnit; + /** * 控制器层 * @@ -364,13 +359,13 @@ public class LoginController extends BaseController { /** * 通过用户名/密码登录 * - * @param userName 用户名 - * @param password 密码 * @return 登录结果 */ @ApiOperation(value = "通过用户名/密码登录") - @PostMapping("/login/{userName}/{password}") - public Result loginByUserName(@PathVariable String userName, @PathVariable String password) { + @PostMapping("/login/username") + public Result loginByUserName(@Validated @RequestBody UserNameLoginDto userNameLoginDto) { + String userName = userNameLoginDto.getUserName(); + String password = userNameLoginDto.getPassword(); UserInfo userInfo = userInfoService.findByUserNameAndPassword(userName, password); if (userInfo !=null) { //生成token @@ -385,4 +380,11 @@ public class LoginController extends BaseController { } } + @ApiOperation(value = "修改密码") + @PostMapping("/changePassword") + public Result changePassword(@Validated @RequestBody UserNameLoginDto changePasswordDto) { + userInfoService.changePassword(changePasswordDto.getUserName(), changePasswordDto.getPassword()); + return Result.success(); + } + } diff --git a/luoo_user/src/main/java/com/luoo/user/dto/UserNameLoginDto.java b/luoo_user/src/main/java/com/luoo/user/dto/UserNameLoginDto.java new file mode 100644 index 0000000..ff957b7 --- /dev/null +++ b/luoo_user/src/main/java/com/luoo/user/dto/UserNameLoginDto.java @@ -0,0 +1,26 @@ +package com.luoo.user.dto; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import javax.validation.constraints.NotBlank; +import java.io.Serializable; + +/** + * @Author: yawei.huang + * @Package: com.luoo.user.dto + * @Project: luoo_parent + * @Date: 2024/5/29 8:55 + * @Filename: UserNameLoginDto + * @Describe: + */ +@Data +public class UserNameLoginDto implements Serializable { + @ApiModelProperty("用户名") + @NotBlank(message = "用户名不能为空") + private String userName; + + @ApiModelProperty("密码") + @NotBlank(message = "密码不能为空") + private String password; +} diff --git a/luoo_user/src/main/java/com/luoo/user/service/UserInfoService.java b/luoo_user/src/main/java/com/luoo/user/service/UserInfoService.java index 9b33001..7b0f6eb 100644 --- a/luoo_user/src/main/java/com/luoo/user/service/UserInfoService.java +++ b/luoo_user/src/main/java/com/luoo/user/service/UserInfoService.java @@ -697,4 +697,16 @@ public class UserInfoService { return new PageResult<>(totalElements, content); } + /** + * 修改密码 + * + * @param userName 用户名 + * @param password 新密码 + */ + @Transactional(rollbackFor = Exception.class) + public void changePassword(String userName, String password) { + UserInfo userInfoByUserName = userInfoDao.findUserInfoByUserName(userName); + userInfoByUserName.setPassword(encoder.encode(password)); + userInfoDao.save(userInfoByUserName); + } }