|
@@ -16,6 +16,7 @@ import com.huaxu.security.smsCode.SmsCodeException;
|
|
|
import com.huaxu.service.UserService;
|
|
|
import com.huaxu.util.ByteArrayUtils;
|
|
|
import com.huaxu.util.RedisUtil;
|
|
|
+import com.huaxu.util.UserUtil;
|
|
|
import com.huaxu.util.Util;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -177,7 +178,7 @@ public class UserServiceImpl implements UserService {
|
|
|
Set<GrantedAuthority> grantedAuthorities = new HashSet<>();
|
|
|
OAuth2Authentication oAuth2Authentication = (OAuth2Authentication) SecurityContextHolder.getContext().getAuthentication();
|
|
|
LoginUser loginUser = (LoginUser) oAuth2Authentication.getPrincipal();
|
|
|
-
|
|
|
+ Permission permission=new Permission();
|
|
|
//角色必须是ROLE_开头,其余的是用户功能权限
|
|
|
/* List<Permission> permissionList =findPermission(user);
|
|
|
Integer permissionType = permissionList.get(0).getPermissionType();
|
|
@@ -192,11 +193,13 @@ public class UserServiceImpl implements UserService {
|
|
|
grantedAuthorities.add(authority1);
|
|
|
}
|
|
|
}
|
|
|
- }*/
|
|
|
+ }
|
|
|
+ loginUser.setProgramItemList(programItemList);
|
|
|
+ */
|
|
|
GrantedAuthority authority1 = new SimpleGrantedAuthority("sys:menu:edit");
|
|
|
grantedAuthorities.add(authority1);
|
|
|
- loginUser.setLoginToken(UUID.randomUUID().toString());
|
|
|
- // loginUser.setProgramItemList(programItemList);
|
|
|
+
|
|
|
+
|
|
|
loginUser.setName(user.getUsername());
|
|
|
loginUser.setId(user.getId());
|
|
|
loginUser.setUsername(user.getUsername());
|
|
@@ -204,22 +207,17 @@ public class UserServiceImpl implements UserService {
|
|
|
loginUser.setDepartmentId(user.getDeptOrgId());
|
|
|
loginUser.setTenantId(user.getTenantId());
|
|
|
loginUser.setType(user.getUserType());
|
|
|
+ loginUser.setPhoneNumber(user.getPhone());
|
|
|
loginUser.setAuthorities(grantedAuthorities);
|
|
|
+ loginUser.setPermissonType(permission.getPermissionType());
|
|
|
+ loginUser.setRoleId(permission.getRoleId());
|
|
|
MobileLoginAuthenticationToken authenticationTokenReslut = new MobileLoginAuthenticationToken(loginUser,oAuth2Authentication.getCredentials(),loginUser.getAuthorities());
|
|
|
authenticationTokenReslut.setDetails(oAuth2Authentication.getDetails());
|
|
|
OAuth2Authentication oAuth2AuthenticationNew = new OAuth2Authentication(oAuth2Authentication.getOAuth2Request(), authenticationTokenReslut);
|
|
|
|
|
|
OAuth2AccessToken accessToken = authorizationServerTokenServices.createAccessToken(oAuth2AuthenticationNew);
|
|
|
- LoginLog loginLog=new LoginLog();
|
|
|
- loginLog.setName(loginUser.getName());
|
|
|
- loginLog.setCreateTime(new Date());
|
|
|
- loginLog.setPhone(loginUser.getPhoneNumber());
|
|
|
- loginLog.setCompanyId(loginUser.getCompanyId());
|
|
|
- loginLog.setDepartmentId(loginUser.getDepartmentId());
|
|
|
- loginLog.setType("登录");
|
|
|
- loginLog.setLoginIp(Util.getIpAddr(request));
|
|
|
- loginLogMapper.insert(loginLog);
|
|
|
|
|
|
+ insertLoginLog(loginUser,"登录");
|
|
|
return accessToken;
|
|
|
}
|
|
|
|
|
@@ -276,6 +274,18 @@ public class UserServiceImpl implements UserService {
|
|
|
public boolean logOut(String token) {
|
|
|
|
|
|
boolean flag=consumerTokenServices.revokeToken(token);
|
|
|
+ insertLoginLog(UserUtil.getCurrentUser(),"登出");
|
|
|
return flag;
|
|
|
}
|
|
|
+ private void insertLoginLog(LoginUser loginUser,String type){
|
|
|
+ LoginLog loginLog=new LoginLog();
|
|
|
+ loginLog.setName(loginUser.getName());
|
|
|
+ loginLog.setPhone(loginUser.getPhoneNumber());
|
|
|
+ loginLog.setCompanyId(loginUser.getCompanyId());
|
|
|
+ loginLog.setDepartmentId(loginUser.getDepartmentId());
|
|
|
+ loginLog.setType(type);
|
|
|
+ loginLog.setCreateTime(new Date());
|
|
|
+ loginLog.setLoginIp(Util.getIpAddr(request));
|
|
|
+ loginLogMapper.insert(loginLog);
|
|
|
+ }
|
|
|
}
|