文件名修正
This commit is contained in:
@ -8,7 +8,7 @@ import co.jp.app.repository.erraRepository;
|
||||
|
||||
|
||||
@Service
|
||||
public class erraService {
|
||||
public class ErraService {
|
||||
|
||||
@Autowired
|
||||
erraRepository erraDao;
|
@ -6,13 +6,13 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import co.jp.app.entity.PetEntity;
|
||||
import co.jp.app.repository.uploadRepository;
|
||||
import co.jp.app.repository.UploadRepository;
|
||||
|
||||
@Service
|
||||
public class uploadService {
|
||||
public class UploadService {
|
||||
|
||||
@Autowired
|
||||
private uploadRepository uploadDao;
|
||||
private UploadRepository uploadDao;
|
||||
|
||||
public List<PetEntity> saveAll(Iterable<PetEntity> entities) {
|
||||
|
51
src/main/java/co/jp/app/service/UserService.java
Normal file
51
src/main/java/co/jp/app/service/UserService.java
Normal file
@ -0,0 +1,51 @@
|
||||
package co.jp.app.service;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import co.jp.app.entity.UserEntity;
|
||||
import co.jp.app.repository.UserRepository;
|
||||
|
||||
|
||||
@Service
|
||||
public class UserService {
|
||||
|
||||
private final UserRepository userEntityRepository;
|
||||
// private final PasswordEncoder passwordEncoder; // 注入密码编码器
|
||||
|
||||
@Autowired
|
||||
public UserService(UserRepository userEntityRepository /*, PasswordEncoder passwordEncoder */) {
|
||||
this.userEntityRepository = userEntityRepository;
|
||||
// this.passwordEncoder = passwordEncoder;
|
||||
}
|
||||
|
||||
@Transactional // 整个注册过程应该是一个事务
|
||||
public UserEntity registerNewUser(String name, String email, String rawPassword) throws Exception {
|
||||
// 1. 检查邮箱是否已被注册
|
||||
if (userEntityRepository.existsByEmail(email)) {
|
||||
throw new Exception("错误:该邮箱地址已被注册!"); // 或者自定义异常
|
||||
}
|
||||
|
||||
// (可选) 检查用户名是否已被注册 (如果您有用户名字段)
|
||||
// if (userEntityRepository.existsByUsername(username)) {
|
||||
// throw new Exception("错误:该用户名已被注册!");
|
||||
// }
|
||||
|
||||
// 2. 创建新的 UserEntity 对象
|
||||
UserEntity newUser = new UserEntity();
|
||||
newUser.setName(name);
|
||||
newUser.setEmail(email);
|
||||
|
||||
// 3. 对密码进行哈希加密 (非常重要!)
|
||||
// String hashedPassword = passwordEncoder.encode(rawPassword);
|
||||
// newUser.setPassword(hashedPassword);
|
||||
newUser.setPassword(rawPassword); // 实际项目中必须加密!这里为了简化先直接赋值
|
||||
|
||||
// 4. 设置其他默认属性,例如账户状态、角色等 (如果需要)
|
||||
// newUser.setActive(true);
|
||||
// newUser.setRoles(...);
|
||||
|
||||
// 5. 保存新用户到数据库
|
||||
return userEntityRepository.save(newUser);
|
||||
}
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
package co.jp.app.service;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import co.jp.app.entity.UserEntity;
|
||||
import co.jp.app.repository.userRepository;
|
||||
|
||||
|
||||
@Service
|
||||
public class userService {
|
||||
|
||||
@Autowired
|
||||
userRepository userdao;
|
||||
|
||||
public UserEntity getNameByEntity(String name) {
|
||||
return userdao.getByName(name);
|
||||
|
||||
}
|
||||
|
||||
public UserEntity getEmailByEntity(String email) {
|
||||
return userdao.getByEmail(email);
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user