|  |  | 
 |  |  | import com.doumee.core.utils.Utils; | 
 |  |  | import com.doumee.dao.system.dto.LoginDTO; | 
 |  |  | import com.doumee.dao.system.model.SystemLoginLog; | 
 |  |  | import com.doumee.dao.system.model.SystemPermission; | 
 |  |  | import com.doumee.dao.system.model.SystemRole; | 
 |  |  | import com.doumee.dao.system.model.SystemUser; | 
 |  |  | import com.doumee.service.common.CaptchaService; | 
 |  |  | import com.doumee.service.system.SystemLoginLogService; | 
 |  |  | import com.doumee.service.system.SystemLoginService; | 
 |  |  | import com.doumee.service.system.*; | 
 |  |  | import lombok.extern.slf4j.Slf4j; | 
 |  |  | import org.apache.commons.lang3.StringUtils; | 
 |  |  | import org.apache.shiro.SecurityUtils; | 
 |  |  | import org.apache.shiro.authc.AuthenticationException; | 
 |  |  | import org.apache.shiro.authc.UsernamePasswordToken; | 
 |  |  | import org.apache.shiro.subject.Subject; | 
 |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
 |  |  | import org.springframework.beans.factory.annotation.Value; | 
 |  |  | import org.springframework.context.annotation.Lazy; | 
 |  |  | import org.springframework.http.server.reactive.ServerHttpRequest; | 
 |  |  | import org.springframework.stereotype.Service; | 
 |  |  |  | 
 |  |  | import javax.servlet.http.HttpServletRequest; | 
 |  |  | import java.util.Date; | 
 |  |  | import java.util.List; | 
 |  |  |  | 
 |  |  | @Slf4j | 
 |  |  | @Service | 
 |  |  | 
 |  |  |     private String systemVersion; | 
 |  |  |     @Value("${debug_model}") | 
 |  |  |     private Boolean isDebug; | 
 |  |  |     @Lazy | 
 |  |  |     @Autowired | 
 |  |  |     private SystemUserService systemUserService; | 
 |  |  |  | 
 |  |  |     @Lazy | 
 |  |  |     @Autowired | 
 |  |  |     private SystemRoleService systemRoleService; | 
 |  |  |  | 
 |  |  |     @Lazy | 
 |  |  |     @Autowired | 
 |  |  |     private SystemPermissionService systemPermissionService; | 
 |  |  |  | 
 |  |  |     @Autowired | 
 |  |  |     private CaptchaService captchaService; | 
 |  |  | 
 |  |  |             throw new BusinessException(ResponseStatus.ACCOUNT_INCORRECT); | 
 |  |  |         } | 
 |  |  |     } | 
 |  |  |  | 
 |  |  |     @Override | 
 |  |  |     public LoginUserInfo loginByPasswordNew(LoginDTO dto, ServerHttpRequest request) { | 
 |  |  |         SystemLoginLog loginLog = new SystemLoginLog(); | 
 |  |  |         loginLog.setLoginUsername(dto.getUsername()); | 
 |  |  |         loginLog.setLoginTime(new Date()); | 
 |  |  |         loginLog.setSystemVersion(systemVersion); | 
 |  |  |         loginLog.setLocation(Utils.Location.getLocationString(loginLog.getIp())); | 
 |  |  |         if(request!=null&&request.getHeaders()!=null && request.getHeaders().size()>0){ | 
 |  |  |             loginLog.setIp(Utils.User_Client.getIP(request)); | 
 |  |  |             loginLog.setPlatform(Utils.User_Client.getPlatform(request)); | 
 |  |  |             loginLog.setClientInfo(Utils.User_Client.getBrowser(request)); | 
 |  |  |             loginLog.setOsInfo(Utils.User_Client.getOS(request)); | 
 |  |  |         } | 
 |  |  |         loginLog.setServerIp(Utils.Server.getIP()); | 
 |  |  |         if(isDebug == null  || !isDebug){ | 
 |  |  |             // 校验验证码 | 
 |  |  |             try { | 
 |  |  |                 captchaService.check(dto.getUuid(), dto.getCode()); | 
 |  |  |             } catch (Exception e) { | 
 |  |  |                 log.error(e.getMessage(), e); | 
 |  |  |                 loginLog.setReason(e.getMessage().length() > 200 ? (e.getMessage().substring(0, 190) + "...") : e.getMessage()); | 
 |  |  |                 loginLog.setSuccess(Boolean.FALSE); | 
 |  |  |                 systemLoginLogService.create(loginLog); | 
 |  |  |                 throw new BusinessException(ResponseStatus.ACCOUNT_INCORRECT.getCode(),"对不起,验证码不正确!"); | 
 |  |  |             } | 
 |  |  |         } | 
 |  |  |  | 
 |  |  |         // 根据用户名查询用户对象 | 
 |  |  |         SystemUser queryDto = new SystemUser(); | 
 |  |  |         queryDto.setUsername(dto.getUsername()); | 
 |  |  |         queryDto.setDeleted(Boolean.FALSE); | 
 |  |  |         SystemUser user = systemUserService.findOne(queryDto); | 
 |  |  |         if (user == null) { | 
 |  |  |             throw new BusinessException(ResponseStatus.ACCOUNT_INCORRECT); | 
 |  |  |         } | 
 |  |  |         String pwd = Utils.Secure.encryptPassword(new String(dto.getPassword()), user.getSalt()); | 
 |  |  |         // 比较密码 | 
 |  |  |         if( !StringUtils.equals(pwd, user.getPassword())){ | 
 |  |  |             throw new BusinessException(ResponseStatus.ACCOUNT_INCORRECT); | 
 |  |  |         } | 
 |  |  |         // 获取登录用户信息 | 
 |  |  |         List<SystemRole> roles = systemRoleService.findByUserId(user.getId()); | 
 |  |  |         List<SystemPermission> permissions = systemPermissionService.findByUserId(user.getId()); | 
 |  |  |         LoginUserInfo userInfo = LoginUserInfo.from(user, roles, permissions,null); | 
 |  |  |         return  userInfo; | 
 |  |  |     } | 
 |  |  | } |