|
|
@@ -31,8 +31,6 @@ import org.springframework.ui.ModelMap;
|
|
|
import org.springframework.util.Assert;
|
|
|
import org.springframework.web.servlet.ModelAndView;
|
|
|
|
|
|
-import java.time.LocalDateTime;
|
|
|
-
|
|
|
@Service
|
|
|
public class UserServiceImpl implements UserService {
|
|
|
private static final Sort PAGE_SORT = Sort.by(Sort.Direction.ASC, "id");
|
|
|
@@ -53,7 +51,7 @@ public class UserServiceImpl implements UserService {
|
|
|
@Override
|
|
|
@Transactional
|
|
|
public UserVO create(UserDTO userDTO) throws ServiceException {
|
|
|
- return register(userDTO.getUsername(), userDTO.getEmail(), null,userDTO.getPhone(), userDTO.getRole());
|
|
|
+ return register(userDTO.getUsername(), userDTO.getEmail(), null, userDTO.getRole());
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -100,11 +98,11 @@ public class UserServiceImpl implements UserService {
|
|
|
|
|
|
@Override
|
|
|
@Transactional
|
|
|
- public UserVO register(RegisterForm form) throws ServiceException {
|
|
|
- return register(form.getUsername(), form.getEmail(), form.getPassword(),form.getPhone(), UserRole.STUDENT);
|
|
|
+ public void register(RegisterForm form) throws ServiceException {
|
|
|
+ register(form.getUsername(), form.getEmail(), form.getPassword(), UserRole.STUDENT);
|
|
|
}
|
|
|
|
|
|
- private UserVO register(String username, String email, String password, String phone,UserRole role) throws ServiceException {
|
|
|
+ private UserVO register(String username, String email, String password, UserRole role) throws ServiceException {
|
|
|
User user = userDAO.findByUsername(username);
|
|
|
Asserts.isNull(user, "用户名已被使用!");
|
|
|
user = userDAO.findByEmail(email);
|
|
|
@@ -121,16 +119,14 @@ public class UserServiceImpl implements UserService {
|
|
|
user.setUsername(username);
|
|
|
user.setEmail(email);
|
|
|
user.setPassword(DigestUtils.sha256Hex(realPassword));
|
|
|
- user.setPhone(phone);
|
|
|
user.setRole(role);
|
|
|
- user.setCreatedAt(LocalDateTime.now());
|
|
|
ModelMap model = new ModelMap();
|
|
|
model.addAttribute("username", username);
|
|
|
if (password == null) {
|
|
|
model.addAttribute("password", realPassword);
|
|
|
}
|
|
|
model.addAttribute("role", role);
|
|
|
-// mailService.send(email, username, "注册成功 | MOOCODER", new ModelAndView("mail/register", model));
|
|
|
+ mailService.send(email, username, "注册成功 | MOOCODER", new ModelAndView("mail/register", model));
|
|
|
return new UserVO(userDAO.save(user));
|
|
|
}
|
|
|
|
|
|
@@ -151,17 +147,6 @@ public class UserServiceImpl implements UserService {
|
|
|
changePassword(user, password, true);
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- public UserVO login(String username, String password) throws ServiceException{
|
|
|
- User user=userDAO.findByUsername(username);
|
|
|
- if (user.getPassword().equals(DigestUtils.sha256Hex(password))){
|
|
|
- return new UserVO(user);
|
|
|
- }
|
|
|
- else {
|
|
|
- throw new ServiceException();
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
private void changePassword(User user, String password, boolean reset) throws ServiceException {
|
|
|
try {
|
|
|
gitlabApi.changePassword(user.getId(), password);
|