修改邮箱bug
This commit is contained in:
parent
a96f0b2165
commit
9a58ac439e
|
@ -1,5 +1,6 @@
|
||||||
package com.example.catchTheLetters.controller;
|
package com.example.catchTheLetters.controller;
|
||||||
|
|
||||||
|
import com.example.catchTheLetters.entity.Forget;
|
||||||
import com.example.catchTheLetters.model.dto.LoginDto;
|
import com.example.catchTheLetters.model.dto.LoginDto;
|
||||||
import com.example.catchTheLetters.model.dto.RegisterDto;
|
import com.example.catchTheLetters.model.dto.RegisterDto;
|
||||||
import com.example.catchTheLetters.entity.User;
|
import com.example.catchTheLetters.entity.User;
|
||||||
|
@ -92,4 +93,10 @@ public class AuthController {
|
||||||
public R<String> uploadAvatar(@RequestHeader("token") String token, @RequestParam("file") MultipartFile file) {
|
public R<String> uploadAvatar(@RequestHeader("token") String token, @RequestParam("file") MultipartFile file) {
|
||||||
return authService.uploadAvatar(token, file);
|
return authService.uploadAvatar(token, file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ApiOperation(value = "忘记密码")
|
||||||
|
@PostMapping("/forget-password")
|
||||||
|
public R<String> forgetPassword(@RequestBody Forget forget){
|
||||||
|
return authService.forgetPassword(forget.getEmail(),forget.getPassword());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
package com.example.catchTheLetters.entity;
|
||||||
|
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class Forget {
|
||||||
|
String email;
|
||||||
|
String password;
|
||||||
|
}
|
|
@ -78,4 +78,6 @@ public interface AuthService {
|
||||||
* @return 头像地址
|
* @return 头像地址
|
||||||
*/
|
*/
|
||||||
R<String> uploadAvatar(String token, MultipartFile file);
|
R<String> uploadAvatar(String token, MultipartFile file);
|
||||||
|
|
||||||
|
R<String> forgetPassword(String email,String newPassword);
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,10 +12,12 @@ import com.example.catchTheLetters.utils.DESUtil;
|
||||||
import com.example.catchTheLetters.utils.JwtUtil;
|
import com.example.catchTheLetters.utils.JwtUtil;
|
||||||
import com.example.catchTheLetters.utils.MinioUtil;
|
import com.example.catchTheLetters.utils.MinioUtil;
|
||||||
import com.example.catchTheLetters.utils.R;
|
import com.example.catchTheLetters.utils.R;
|
||||||
|
import com.mongodb.client.result.UpdateResult;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
import org.springframework.data.mongodb.core.MongoTemplate;
|
import org.springframework.data.mongodb.core.MongoTemplate;
|
||||||
import org.springframework.data.mongodb.core.query.Criteria;
|
import org.springframework.data.mongodb.core.query.Criteria;
|
||||||
import org.springframework.data.mongodb.core.query.Query;
|
import org.springframework.data.mongodb.core.query.Query;
|
||||||
|
import org.springframework.data.mongodb.core.query.Update;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
@ -230,4 +232,16 @@ public class AuthServiceImpl implements AuthService {
|
||||||
|
|
||||||
return success ? R.ok("http://1.14.105.160:9001/catchtheletters/avatar/" + fileName) : R.fail("上传失败");
|
return success ? R.ok("http://1.14.105.160:9001/catchtheletters/avatar/" + fileName) : R.fail("上传失败");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public R<String> forgetPassword(String email, String newPassword) {
|
||||||
|
String password = desUtil.SHA512(newPassword);
|
||||||
|
Query query = new Query(Criteria.where("email").is(email));
|
||||||
|
Update update = new Update().set("password", password);
|
||||||
|
UpdateResult updateResult = mongoTemplate.updateFirst(query, update, User.class);
|
||||||
|
if (updateResult.getMatchedCount() == 0) {
|
||||||
|
return R.fail("no user found");
|
||||||
|
}
|
||||||
|
return R.ok("修改成功");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue