|
@@ -118,6 +118,43 @@ public class SysLoginService
|
|
|
*/
|
|
|
public String weChatLogin(AppletLoginForm form)
|
|
|
{
|
|
|
+ if(StringUtils.isNotEmpty(form.getUsername()) && StringUtils.isNotEmpty(form.getPassword())){
|
|
|
+ // 登录前置校验
|
|
|
+ loginPreCheck(form.getUsername(), form.getPassword());
|
|
|
+ // 用户验证
|
|
|
+ Authentication authentication = null;
|
|
|
+ String username = form.getUsername();
|
|
|
+ String password = form.getPassword();
|
|
|
+ try
|
|
|
+ {
|
|
|
+ UsernamePasswordAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(username, password);
|
|
|
+ AuthenticationContextHolder.setContext(authenticationToken);
|
|
|
+ // 该方法会去调用UserDetailsServiceImpl.loadUserByUsername
|
|
|
+ authentication = authenticationManager.authenticate(authenticationToken);
|
|
|
+ }
|
|
|
+ catch (Exception e)
|
|
|
+ {
|
|
|
+ if (e instanceof BadCredentialsException)
|
|
|
+ {
|
|
|
+ AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, MessageUtils.message("user.password.not.match")));
|
|
|
+ throw new UserPasswordNotMatchException();
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ AsyncManager.me().execute(AsyncFactory.recordLogininfor(username, Constants.LOGIN_FAIL, e.getMessage()));
|
|
|
+ throw new ServiceException(e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ finally
|
|
|
+ {
|
|
|
+ AuthenticationContextHolder.clearContext();
|
|
|
+ }
|
|
|
+ AsyncManager.me().execute(AsyncFactory.recordLogininfor(form.getUsername(), Constants.LOGIN_SUCCESS, MessageUtils.message("user.login.success")));
|
|
|
+ LoginUser loginUser = (LoginUser) authentication.getPrincipal();
|
|
|
+ recordLoginInfo(loginUser.getUserId());
|
|
|
+ // 生成token
|
|
|
+ return tokenService.createToken(loginUser);
|
|
|
+ }
|
|
|
//用户唯一标识 OpenID 、 用户在微信开放平台帐号下的唯一标识UnionID
|
|
|
// (若当前小程序已绑定到微信开放平台帐号) 和 会话密钥 session_key
|
|
|
AppletSessionDTO dto = WxCodeSessionUtil.jscode2Session(form);
|
|
@@ -144,7 +181,7 @@ public class SysLoginService
|
|
|
|
|
|
throw new ServiceException("对不起,您的账号:" + phonenumber + " 已停用");
|
|
|
}
|
|
|
- passwordService.validate(user);
|
|
|
+ //passwordService.validate(user);
|
|
|
LoginUser loginUser = createLoginUser(user);
|
|
|
recordLoginInfo(loginUser.getUserId());
|
|
|
return tokenService.createToken(loginUser);
|