|
@@ -7,10 +7,12 @@ import cn.iselab.mooctest.user.model.User;
|
|
|
import cn.iselab.mooctest.user.model.UserIntegral;
|
|
|
import cn.iselab.mooctest.user.service.IntegralService;
|
|
|
import cn.iselab.mooctest.user.service.UserService;
|
|
|
+import cn.iselab.mooctest.user.util.EncryptionUtil;
|
|
|
import cn.iselab.mooctest.user.web.exception.HttpBadRequestException;
|
|
|
import cn.iselab.mooctest.user.web.logic.BaseLogic;
|
|
|
import cn.iselab.mooctest.user.web.logic.UserLogic;
|
|
|
import cn.iselab.mooctest.user.web.wrapper.UserWrapper;
|
|
|
+import org.apache.commons.validator.routines.EmailValidator;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
@@ -100,31 +102,52 @@ public class UserLogicImpl extends BaseLogic implements UserLogic {
|
|
|
}
|
|
|
User user;
|
|
|
try {
|
|
|
- if (!userDTO.getEmail().isEmpty()) {
|
|
|
- user = userService.findByEmail(userDTO.getEmail());
|
|
|
- if (user.getPassword().equals(userDTO.getPassword())) {
|
|
|
- msg = "邮箱登录成功--用户名--" + user.getEmail();
|
|
|
- result.init(ResponseStatus.SUCCESS, msg, userWrapper.wrap(user));
|
|
|
- LOG.info(msg);
|
|
|
- } else {
|
|
|
- msg = "邮箱登录失败--密码错误";
|
|
|
- result.init(ResponseStatus.FAILED, msg, userDTO);
|
|
|
- LOG.error(msg);
|
|
|
- }
|
|
|
+ user = (!userDTO.getEmail().isEmpty())?
|
|
|
+ userService.findByEmail(userDTO.getEmail())
|
|
|
+ :userService.findByMobile(userDTO.getMobile());
|
|
|
+
|
|
|
+ if(user.getAvailability()!=1){
|
|
|
+ msg = user.getAvailability()==0?"该帐号未激活":"该帐号被删除";
|
|
|
+ result.init(ResponseStatus.FAILED, msg, userDTO);
|
|
|
+ LOG.error(msg+"-email:"+user.getEmail());
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ if (user.getPassword().equals(userDTO.getPassword())) {
|
|
|
+ msg = "登录成功--登录帐号--" + user.getEmail();
|
|
|
+ result.init(ResponseStatus.SUCCESS, msg, userWrapper.wrap(user));
|
|
|
+ LOG.info(msg+"-email:"+user.getEmail());
|
|
|
} else {
|
|
|
- user = userService.findByMobile(userDTO.getMobile());
|
|
|
- if (user.getPassword().equals(userDTO.getPassword())) {
|
|
|
- msg = "手机登录成功--用户名";
|
|
|
- result.init(ResponseStatus.SUCCESS, msg, userWrapper.wrap(user));
|
|
|
- LOG.info(msg);
|
|
|
- } else {
|
|
|
- msg = "手机登录失败--密码错误";
|
|
|
- result.init(ResponseStatus.FAILED, msg, userDTO);
|
|
|
- LOG.error(msg);
|
|
|
- }
|
|
|
+ msg = "登录失败--密码错误";
|
|
|
+ result.init(ResponseStatus.FAILED, msg, userDTO);
|
|
|
+ LOG.error(msg+"-email:"+user.getEmail());
|
|
|
}
|
|
|
+//
|
|
|
+// if (!userDTO.getEmail().isEmpty()) {
|
|
|
+// user = userService.findByEmail(userDTO.getEmail());
|
|
|
+// if (user.getPassword().equals(userDTO.getPassword())) {
|
|
|
+// msg = "邮箱登录成功--邮箱--" + user.getEmail();
|
|
|
+// result.init(ResponseStatus.SUCCESS, msg, userWrapper.wrap(user));
|
|
|
+// LOG.info(msg);
|
|
|
+// } else {
|
|
|
+// msg = "邮箱登录失败--密码错误";
|
|
|
+// result.init(ResponseStatus.FAILED, msg, userDTO);
|
|
|
+// LOG.error(msg);
|
|
|
+// }
|
|
|
+// } else {
|
|
|
+// user = userService.findByMobile(userDTO.getMobile());
|
|
|
+// if (user.getPassword().equals(userDTO.getPassword())) {
|
|
|
+// msg = "手机登录成功--手机号";
|
|
|
+// result.init(ResponseStatus.SUCCESS, msg, userWrapper.wrap(user));
|
|
|
+// LOG.info(msg);
|
|
|
+// } else {
|
|
|
+// msg = "手机登录失败--密码错误";
|
|
|
+// result.init(ResponseStatus.FAILED, msg, userDTO);
|
|
|
+// LOG.error(msg);
|
|
|
+// }
|
|
|
+// }
|
|
|
}catch (NullPointerException e){
|
|
|
result.init(ResponseStatus.FAILED, "用户不存在", userDTO);
|
|
|
+ LOG.error(result.getMsg(),e);
|
|
|
}finally {
|
|
|
return result;
|
|
|
}
|
|
@@ -197,4 +220,55 @@ public class UserLogicImpl extends BaseLogic implements UserLogic {
|
|
|
}
|
|
|
return userWrapper.wrap(userService.findAllByEmails(emails));
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ResponseResult<UserDTO> registerAccount(UserDTO userDTO) {
|
|
|
+ ResponseResult<UserDTO> result = new ResponseResult<>();
|
|
|
+ if(!userDTO.getEmail().trim().isEmpty() && !userDTO.getPassword().trim().isEmpty()) {
|
|
|
+ if(userService.findByEmail(userDTO.getEmail()) != null){
|
|
|
+ result.init(ResponseStatus.FAILED, "该邮箱已被注册", userDTO);
|
|
|
+ LOG.error(result.getMsg());
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ if (!EmailValidator.getInstance().isValid(userDTO.getEmail())){
|
|
|
+ result.init(ResponseStatus.FAILED, "注册邮箱非法", userDTO);
|
|
|
+ LOG.error(result.getMsg());
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ if (userDTO.getName().length()>50 || userDTO.getName().length()<2){
|
|
|
+ result.init(ResponseStatus.FAILED, "姓名长度非法,应在2~50位", userDTO);
|
|
|
+ LOG.error(result.getMsg());
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ if (userDTO.getPassword().length() > 16 || userDTO.getPassword().length() < 6){
|
|
|
+ result.init(ResponseStatus.FAILED, "密码长度非法,应在6~16位", userDTO);
|
|
|
+ LOG.error(result.getMsg());
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ try{
|
|
|
+ User user = userWrapper.unwrap(userDTO);
|
|
|
+ user.setAvailability(0);
|
|
|
+ user.setPassword(EncryptionUtil.encryptMD5(user.getPassword()));
|
|
|
+ userService.register(user);
|
|
|
+ result.init(ResponseStatus.SUCCESS, "注册成功!请前往登录!", userWrapper.wrap(user));
|
|
|
+ }catch (Exception e){
|
|
|
+ result.init(ResponseStatus.FAILED, "系统错误:注册失败", null);
|
|
|
+ LOG.error(result.getMsg(),e);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ }else{
|
|
|
+ result.init(ResponseStatus.FAILED, "帐号和密码不可为空", userDTO);
|
|
|
+ LOG.error(result.getMsg());
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ResponseResult<UserDTO> activeAccount(String email) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|