|
@@ -2,17 +2,26 @@ package com.example.service.impl;
|
|
|
|
|
|
import com.example.constant.MessageConstant;
|
|
import com.example.constant.MessageConstant;
|
|
import com.example.constant.StatusConstant;
|
|
import com.example.constant.StatusConstant;
|
|
|
|
+import com.example.dto.PasswordDTO;
|
|
|
|
+import com.example.dto.UserDTO;
|
|
import com.example.dto.UserLoginDTO;
|
|
import com.example.dto.UserLoginDTO;
|
|
import com.example.entity.User;
|
|
import com.example.entity.User;
|
|
import com.example.exception.AccountNotFoundException;
|
|
import com.example.exception.AccountNotFoundException;
|
|
|
|
+import com.example.exception.PasswordEditFailedException;
|
|
import com.example.exception.PasswordErrorException;
|
|
import com.example.exception.PasswordErrorException;
|
|
import com.example.mapper.UserMapper;
|
|
import com.example.mapper.UserMapper;
|
|
|
|
+import com.example.result.Result;
|
|
import com.example.service.UserService;
|
|
import com.example.service.UserService;
|
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
|
+import org.apache.commons.logging.Log;
|
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.util.DigestUtils;
|
|
import org.springframework.util.DigestUtils;
|
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
|
|
import javax.security.auth.login.AccountLockedException;
|
|
import javax.security.auth.login.AccountLockedException;
|
|
|
|
+import java.time.LocalDateTime;
|
|
|
|
|
|
@Service
|
|
@Service
|
|
public class UserServiceImpl implements UserService {
|
|
public class UserServiceImpl implements UserService {
|
|
@@ -50,8 +59,66 @@ public class UserServiceImpl implements UserService {
|
|
//账号被锁定
|
|
//账号被锁定
|
|
throw new AccountNotFoundException(MessageConstant.ACCOUNT_LOCKED);
|
|
throw new AccountNotFoundException(MessageConstant.ACCOUNT_LOCKED);
|
|
}
|
|
}
|
|
-//3、返回实体对象
|
|
|
|
|
|
+ //3、返回实体对象
|
|
return user;
|
|
return user;
|
|
|
|
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 老师注册
|
|
|
|
+ *
|
|
|
|
+ * @param userDTO
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public void register(UserDTO userDTO) {
|
|
|
|
+ User user = new User();
|
|
|
|
+ //对象属性拷贝
|
|
|
|
+ BeanUtils.copyProperties(userDTO, user);
|
|
|
|
+ //设置账号状态
|
|
|
|
+ user.setStatus(StatusConstant.DISABLE);
|
|
|
|
+ user.setCreateTime(LocalDateTime.now());
|
|
|
|
+ userMapper.register(user);
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 修改密码
|
|
|
|
+ *
|
|
|
|
+ * @param passwordDTO
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public void update(PasswordDTO passwordDTO) {
|
|
|
|
+ Long id = passwordDTO.getId();
|
|
|
|
+ String newPassword = passwordDTO.getNewPassword();
|
|
|
|
+ String oldPassword = passwordDTO.getOldPassword();
|
|
|
|
+ System.out.println(newPassword);
|
|
|
|
+ String password = userMapper.getPassword(id);
|
|
|
|
+ //如果旧密码输入不一致则修改失败
|
|
|
|
+ if (!oldPassword.equals(password)) {
|
|
|
|
+ throw new PasswordEditFailedException(MessageConstant.PASSWORD_EDIT_FAILED);
|
|
|
|
+ }
|
|
|
|
+ //修改账号信息
|
|
|
|
+ userMapper.update(id, newPassword);
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 忘记密码
|
|
|
|
+ * @param userDTO
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public void forget(UserDTO userDTO) {
|
|
|
|
+ //首先调取姓名和手机号对比一致不一致
|
|
|
|
+ String username = userDTO.getUserName();
|
|
|
|
+ String phoneNumber = userDTO.getPhoneNumber();
|
|
|
|
+ String name = userDTO.getName();
|
|
|
|
+ String password = userDTO.getPassword();
|
|
|
|
+ User user = userMapper.getByUsername(username);
|
|
|
|
+ //不一致则报错
|
|
|
|
+ if (!(user.getName().equals(name) && user.getPhoneNumber().equals(phoneNumber))) {
|
|
|
|
+ throw new PasswordEditFailedException(MessageConstant.PASSWORD_EDIT_FAILED);
|
|
|
|
+ }
|
|
|
|
+ //一致则修改
|
|
|
|
+ userMapper.update(user.getId(),password);
|
|
}
|
|
}
|
|
|
|
+}
|