| | |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang3.ObjectUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.security.authentication.AuthenticationManager; |
| | | import org.springframework.security.authentication.BadCredentialsException; |
| | |
| | | * |
| | | * @author ruoyi |
| | | */ |
| | | @Slf4j |
| | | @Component |
| | | public class SysLoginService { |
| | | @Autowired |
| | |
| | | * @param uuid 唯一标识 |
| | | * @return 结果 |
| | | */ |
| | | public String login(String username, String password, String code, String uuid, String orgid) { |
| | | public String login(String username, String password, String code, String uuid, String orgid, String campusid) { |
| | | boolean captchaEnabled = configService.selectCaptchaEnabled(); |
| | | // 验证码开关 |
| | | if (captchaEnabled) { |
| | |
| | | // 用户验证 |
| | | Authentication authentication = null; |
| | | try { |
| | | UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(username + "&" + orgid, password); |
| | | UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(username + "&" + orgid + "&" + campusid, password); |
| | | AuthenticationContextHolder.setContext(authenticationToken); |
| | | // 该方法会去调用UserDetailsServiceImpl.loadUserByUsername |
| | | authentication = authenticationManager.authenticate(authenticationToken); |
| | |
| | | return tokenService.createToken(loginUser); |
| | | } |
| | | |
| | | |
| | | public String loginByUserName(String userName) { |
| | | SysUser sysUser = userService.selectUserByUserNameAndDeptId(userName); |
| | | log.info("---------sysUser的值为:{}", sysUser); |
| | | if (ObjectUtils.isNotEmpty(sysUser)) { |
| | | // 构建登录用户对象 |
| | | LoginUser loginUser = new LoginUser(); |
| | | loginUser.setUser(sysUser); |
| | | loginUser.setUserId(sysUser.getUserId()); |
| | | // 创建 token |
| | | String token = tokenService.createToken(loginUser); |
| | | // 生成token |
| | | return token; |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * 校验验证码 |
| | | * |