feat(系统管理): 扫码登录登录页面调整
This commit is contained in:
parent
6c6e0c56e9
commit
e0b0cf67aa
|
@ -166,7 +166,7 @@ public class LoginController {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@GetMapping(value = "/callback/we_com")
|
@GetMapping(value = "/sso/callback/we_com")
|
||||||
@Operation(summary = "获取企业微信登陆验证")
|
@Operation(summary = "获取企业微信登陆验证")
|
||||||
@MsAuditLog(module = OperLogModule.AUTH_TITLE, type = OperLogConstants.LOGIN, title = "WE_COM")
|
@MsAuditLog(module = OperLogModule.AUTH_TITLE, type = OperLogConstants.LOGIN, title = "WE_COM")
|
||||||
public Mono<ResultHolder> callbackWeCom(@RequestParam("code") String code, WebSession session, Locale locale) {
|
public Mono<ResultHolder> callbackWeCom(@RequestParam("code") String code, WebSession session, Locale locale) {
|
||||||
|
|
|
@ -38,6 +38,8 @@ public class LoginFilter implements WebFilter, Ordered {
|
||||||
excludePatterns.add(new PathPatternParser().parse("/"));
|
excludePatterns.add(new PathPatternParser().parse("/"));
|
||||||
// 认证源查询
|
// 认证源查询
|
||||||
excludePatterns.add(new PathPatternParser().parse("/authsource/*"));
|
excludePatterns.add(new PathPatternParser().parse("/authsource/*"));
|
||||||
|
//扫码源
|
||||||
|
excludePatterns.add(new PathPatternParser().parse("/sso/callback/we_com"));
|
||||||
|
|
||||||
// 各模块首页
|
// 各模块首页
|
||||||
swaggerUiConfigProperties.getUrls().forEach(v -> excludePatterns.add(new PathPatternParser().parse("/" + v.getName())));
|
swaggerUiConfigProperties.getUrls().forEach(v -> excludePatterns.add(new PathPatternParser().parse("/" + v.getName())));
|
||||||
|
|
|
@ -18,7 +18,7 @@ import java.util.Optional;
|
||||||
public class SessionFilter implements WebFilter {
|
public class SessionFilter implements WebFilter {
|
||||||
// 所有模块的前缀
|
// 所有模块的前缀
|
||||||
private static final String[] PREFIX = new String[]{"/setting", "/project", "/api", "/performance", "/track", "/workstation", "/ui", "/report"};
|
private static final String[] PREFIX = new String[]{"/setting", "/project", "/api", "/performance", "/track", "/workstation", "/ui", "/report"};
|
||||||
private static final String[] TO_SUB_SERVICE = new String[]{"/license", "/system", "/resource", "/sso/callback/logout", "/sso/callback/cas/logout", "/platform/get/param", "/platform/get/info", "/ding_talk/info", "/we_com/info", "/lark/info", "/lark_suite/info", "/sso/callback/we_com", "/sso/callback/ding_talk", "/sso/callback/lark", "/sso/callback/lark_suite"};
|
private static final String[] TO_SUB_SERVICE = new String[]{"/license", "/system", "/resource", "/sso/callback/logout", "/sso/callback/cas/logout", "/platform/get/param", "/platform/get/info", "/ding_talk/info", "/we_com/info", "/lark/info", "/lark_suite/info"};
|
||||||
private static final String PERFORMANCE_DOWNLOAD_PREFIX = "/jmeter/";
|
private static final String PERFORMANCE_DOWNLOAD_PREFIX = "/jmeter/";
|
||||||
private static final String API_DOWNLOAD_PREFIX = "/api/jmeter/";
|
private static final String API_DOWNLOAD_PREFIX = "/api/jmeter/";
|
||||||
private static final String TRACK_IMAGE_PREFIX = "/resource/md/get/path";
|
private static final String TRACK_IMAGE_PREFIX = "/resource/md/get/path";
|
||||||
|
|
|
@ -143,9 +143,9 @@ public class UserLoginService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public UserDTO loginLocalMode(String userId, String password) {
|
public UserDTO loginLocalMode(String userId, String password) {
|
||||||
UserDTO user = getLoginUser(userId, Collections.singletonList(UserSource.LOCAL.name()));
|
UserDTO user = getLoginUser(userId, List.of(UserSource.LOCAL.name(), UserSource.QR_CODE.name()));
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
user = getUserDTOByEmail(userId, UserSource.LOCAL.name());
|
user = getUserDTOByEmail(userId, UserSource.LOCAL.name(), UserSource.QR_CODE.name());
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
throw new RuntimeException(Translator.get("password_is_incorrect"));
|
throw new RuntimeException(Translator.get("password_is_incorrect"));
|
||||||
}
|
}
|
||||||
|
@ -422,7 +422,7 @@ public class UserLoginService {
|
||||||
if (userId.length() > 64) {
|
if (userId.length() > 64) {
|
||||||
MSException.throwException(Translator.get("user_id_length_too_long"));
|
MSException.throwException(Translator.get("user_id_length_too_long"));
|
||||||
}
|
}
|
||||||
if (password.length() > 30) {
|
if (password.length() > 50) {
|
||||||
MSException.throwException(Translator.get("password_length_too_long"));
|
MSException.throwException(Translator.get("password_length_too_long"));
|
||||||
}
|
}
|
||||||
UserExample example = new UserExample();
|
UserExample example = new UserExample();
|
||||||
|
@ -595,7 +595,7 @@ public class UserLoginService {
|
||||||
userDTOByEmail = getUserDTOByEmail(email);
|
userDTOByEmail = getUserDTOByEmail(email);
|
||||||
if (userDTO != null && userDTOByEmail == null) {
|
if (userDTO != null && userDTOByEmail == null) {
|
||||||
userDTOByEmail = new UserDTO();
|
userDTOByEmail = new UserDTO();
|
||||||
io.metersphere.commons.utils.BeanUtils.copyBean(userDTOByEmail, userDTO);
|
BeanUtils.copyProperties(userDTO, userDTOByEmail);
|
||||||
userDTOByEmail.setEmail(email);
|
userDTOByEmail.setEmail(email);
|
||||||
changeMail = true;
|
changeMail = true;
|
||||||
}
|
}
|
||||||
|
@ -624,6 +624,7 @@ public class UserLoginService {
|
||||||
LogUtil.info(email);
|
LogUtil.info(email);
|
||||||
LogUtil.info(name);
|
LogUtil.info(name);
|
||||||
LogUtil.info(userId);
|
LogUtil.info(userId);
|
||||||
|
userCreateInfo.setEmail(email);
|
||||||
creatUser(userCreateInfo, source);
|
creatUser(userCreateInfo, source);
|
||||||
} else {
|
} else {
|
||||||
userId = userDTOByEmail.getId();
|
userId = userDTOByEmail.getId();
|
||||||
|
@ -642,18 +643,15 @@ public class UserLoginService {
|
||||||
LogUtil.info(userId);
|
LogUtil.info(userId);
|
||||||
LoginRequest request = new LoginRequest();
|
LoginRequest request = new LoginRequest();
|
||||||
try {
|
try {
|
||||||
RsaKey rsaKey = RsaUtil.getRsaKey();
|
|
||||||
request.setAuthenticate(source);
|
request.setAuthenticate(source);
|
||||||
request.setUsername(RsaUtil.publicEncrypt(userId, rsaKey.getPublicKey()));
|
request.setUsername(userId);
|
||||||
request.setPassword(CodingUtil.md5(email));
|
request.setPassword(email);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LogUtil.error("login error: ", e);
|
LogUtil.error("login error: ", e);
|
||||||
MSException.throwException("login error: " + e.getMessage());
|
MSException.throwException("login error: " + e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<SessionUser> login = login(request, session, locale);
|
return login(request, session, locale);
|
||||||
SecurityUtils.getSubject().getSession().setAttribute("authenticate", source);
|
|
||||||
return login;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateUser(String email, String userId) {
|
private void updateUser(String email, String userId) {
|
||||||
|
@ -672,7 +670,7 @@ public class UserLoginService {
|
||||||
PlatformSource platformSource = platformSourceMapper.selectByPrimaryKey(key);
|
PlatformSource platformSource = platformSourceMapper.selectByPrimaryKey(key);
|
||||||
WeComInfoDTO weComInfoDTO = new WeComInfoDTO();
|
WeComInfoDTO weComInfoDTO = new WeComInfoDTO();
|
||||||
WeComCreator weComCreator = JSON.parseObject(platformSource.getConfig(), WeComCreator.class);
|
WeComCreator weComCreator = JSON.parseObject(platformSource.getConfig(), WeComCreator.class);
|
||||||
io.metersphere.commons.utils.BeanUtils.copyBean(weComInfoDTO, weComCreator);
|
BeanUtils.copyProperties(weComCreator, weComInfoDTO);
|
||||||
weComInfoDTO.setEnable(platformSource.getEnable());
|
weComInfoDTO.setEnable(platformSource.getEnable());
|
||||||
weComInfoDTO.setValid(platformSource.getValid());
|
weComInfoDTO.setValid(platformSource.getValid());
|
||||||
return weComInfoDTO;
|
return weComInfoDTO;
|
||||||
|
@ -683,7 +681,7 @@ public class UserLoginService {
|
||||||
PlatformSource platformSource = platformSourceMapper.selectByPrimaryKey(key);
|
PlatformSource platformSource = platformSourceMapper.selectByPrimaryKey(key);
|
||||||
DingTalkInfoDTO dingTalkInfoDTO = new DingTalkInfoDTO();
|
DingTalkInfoDTO dingTalkInfoDTO = new DingTalkInfoDTO();
|
||||||
DingTalkCreator dingTalkCreator = JSON.parseObject(platformSource.getConfig(), DingTalkCreator.class);
|
DingTalkCreator dingTalkCreator = JSON.parseObject(platformSource.getConfig(), DingTalkCreator.class);
|
||||||
io.metersphere.commons.utils.BeanUtils.copyBean(dingTalkInfoDTO, dingTalkCreator);
|
BeanUtils.copyProperties(dingTalkCreator, dingTalkInfoDTO);
|
||||||
dingTalkInfoDTO.setEnable(platformSource.getEnable());
|
dingTalkInfoDTO.setEnable(platformSource.getEnable());
|
||||||
dingTalkInfoDTO.setValid(platformSource.getValid());
|
dingTalkInfoDTO.setValid(platformSource.getValid());
|
||||||
return dingTalkInfoDTO;
|
return dingTalkInfoDTO;
|
||||||
|
@ -706,16 +704,16 @@ public class UserLoginService {
|
||||||
|
|
||||||
private void creatUser(UserRequest userCreateInfo, String source) {
|
private void creatUser(UserRequest userCreateInfo, String source) {
|
||||||
User user = new User();
|
User user = new User();
|
||||||
io.metersphere.commons.utils.BeanUtils.copyBean(user, userCreateInfo);
|
BeanUtils.copyProperties(userCreateInfo, user);
|
||||||
user.setCreateTime(System.currentTimeMillis());
|
user.setCreateTime(System.currentTimeMillis());
|
||||||
user.setCreateUser(SessionUtils.getUserId());
|
user.setCreateUser("admin");
|
||||||
user.setUpdateTime(System.currentTimeMillis());
|
user.setUpdateTime(System.currentTimeMillis());
|
||||||
// 默认1:启用状态
|
// 默认1:启用状态
|
||||||
user.setStatus(UserStatus.NORMAL);
|
user.setStatus(UserStatus.NORMAL);
|
||||||
user.setSource(source);
|
user.setSource(source);
|
||||||
// 密码使用 MD5
|
// 密码使用 MD5
|
||||||
user.setPassword(CodingUtil.md5(user.getPassword()));
|
user.setEmail(user.getEmail());
|
||||||
checkEmailIsExist(user.getEmail());
|
user.setPassword(CodingUtil.md5(user.getEmail()));
|
||||||
userMapper.insertSelective(user);
|
userMapper.insertSelective(user);
|
||||||
//获取默认空间
|
//获取默认空间
|
||||||
Workspace workspace = getWorkspace();
|
Workspace workspace = getWorkspace();
|
||||||
|
@ -724,21 +722,26 @@ public class UserLoginService {
|
||||||
//添加用户组
|
//添加用户组
|
||||||
addRole(workspace, project, user);
|
addRole(workspace, project, user);
|
||||||
//添加日志
|
//添加日志
|
||||||
addLog(user);
|
addLog(user, project);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addLog(User user) {
|
public static void main(String[] args) {
|
||||||
|
String s = CodingUtil.md5("MiPiSU5wRvpn9JcmUsYJubXAiEiE@metersphere.io");
|
||||||
|
System.out.println(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addLog(User user, Project project) {
|
||||||
OperatingLogWithBLOBs log = new OperatingLogWithBLOBs();
|
OperatingLogWithBLOBs log = new OperatingLogWithBLOBs();
|
||||||
log.setOperTitle(user.getName());
|
log.setOperTitle(user.getName());
|
||||||
log.setOperContent(user.getName());
|
log.setOperContent(user.getName());
|
||||||
|
log.setProjectId(project.getId());
|
||||||
log.setOperPath("/sso/callback/we_com");
|
log.setOperPath("/sso/callback/we_com");
|
||||||
log.setId(UUID.randomUUID().toString());
|
log.setId(UUID.randomUUID().toString());
|
||||||
log.setOperType(OperLogConstants.CREATE.name());
|
log.setOperType(OperLogConstants.CREATE.name());
|
||||||
log.setOperModule(OperLogModule.SYSTEM_PARAMETER_SETTING);
|
log.setOperModule(OperLogModule.SYSTEM_PARAMETER_SETTING);
|
||||||
log.setProjectId(null);
|
|
||||||
List<DetailColumn> columns = new LinkedList<>();
|
List<DetailColumn> columns = new LinkedList<>();
|
||||||
OperatingLogDetails details = new OperatingLogDetails(user.getId(), null, user.getName(),
|
OperatingLogDetails details = new OperatingLogDetails(user.getId(), project.getId(), user.getName(),
|
||||||
user.getCreateUser(), columns);
|
user.getCreateUser(), columns);
|
||||||
log.setOperContent(JSON.toJSONString(details));
|
log.setOperContent(JSON.toJSONString(details));
|
||||||
log.setOperTime(System.currentTimeMillis());
|
log.setOperTime(System.currentTimeMillis());
|
||||||
|
@ -824,7 +827,7 @@ public class UserLoginService {
|
||||||
}
|
}
|
||||||
LarkInfoDTO LarkInfoDTO = new LarkInfoDTO();
|
LarkInfoDTO LarkInfoDTO = new LarkInfoDTO();
|
||||||
LarkCreator larkCreator = JSON.parseObject(platformSource.getConfig(), LarkCreator.class);
|
LarkCreator larkCreator = JSON.parseObject(platformSource.getConfig(), LarkCreator.class);
|
||||||
io.metersphere.commons.utils.BeanUtils.copyBean(LarkInfoDTO, larkCreator);
|
BeanUtils.copyProperties(larkCreator, LarkInfoDTO);
|
||||||
LarkInfoDTO.setEnable(platformSource.getEnable());
|
LarkInfoDTO.setEnable(platformSource.getEnable());
|
||||||
LarkInfoDTO.setValid(platformSource.getValid());
|
LarkInfoDTO.setValid(platformSource.getValid());
|
||||||
return LarkInfoDTO;
|
return LarkInfoDTO;
|
||||||
|
|
|
@ -6,3 +6,115 @@
|
||||||
<div id="micro-app"></div>
|
<div id="micro-app"></div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
<script>
|
||||||
|
|
||||||
|
|
||||||
|
import {getQueryVariable, getUrlParameterWidthRegExp} from "@/utils";
|
||||||
|
import axios from "axios";
|
||||||
|
import {useUserStore} from "@/store";
|
||||||
|
import {getCurrentUserId} from "@/utils/token";
|
||||||
|
import {hasPermissions} from "@/utils/permission";
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: "AppLayout",
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
};
|
||||||
|
},
|
||||||
|
beforeMount() {
|
||||||
|
const router = this.$router
|
||||||
|
const code = getQueryVariable('code');
|
||||||
|
const state = getQueryVariable('state') || '';
|
||||||
|
if (state.split('#')[0] === 'fit2cloud-lark-qr' && state.split('#')[1] === "/" ) {
|
||||||
|
this.loading = true;
|
||||||
|
try {
|
||||||
|
axios.get("/sso/callback/lark?code="+code).then((response) => {
|
||||||
|
console.log(response)
|
||||||
|
const weComCallback = response.data.data;
|
||||||
|
const userStore = useUserStore()
|
||||||
|
// 删除缓存
|
||||||
|
userStore.checkPermission(response.data);
|
||||||
|
sessionStorage.removeItem('changePassword');
|
||||||
|
localStorage.setItem('default_language', weComCallback.language);
|
||||||
|
sessionStorage.setItem('loginSuccess', 'true');
|
||||||
|
sessionStorage.setItem('changePassword', weComCallback.message);
|
||||||
|
localStorage.setItem('AuthenticateType', 'QRCODE');
|
||||||
|
if (sessionStorage.getItem('lastUser') === getCurrentUserId()) {
|
||||||
|
router.push({path: sessionStorage.getItem('redirectUrl') || '/'});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let redirectUrl = '/';
|
||||||
|
if (hasPermissions('PROJECT_USER:READ', 'PROJECT_ENVIRONMENT:READ', 'PROJECT_OPERATING_LOG:READ', 'PROJECT_FILE:READ+JAR', 'PROJECT_FILE:READ+FILE', 'PROJECT_CUSTOM_CODE:READ', 'PROJECT_MESSAGE:READ', 'PROJECT_TEMPLATE:READ')) {
|
||||||
|
redirectUrl = '/project/home';
|
||||||
|
} else if (hasPermissions('WORKSPACE_SERVICE:READ', 'WORKSPACE_USER:READ', 'WORKSPACE_PROJECT_MANAGER:READ', 'WORKSPACE_PROJECT_ENVIRONMENT:READ', 'WORKSPACE_OPERATING_LOG:READ')) {
|
||||||
|
redirectUrl = '/setting/project/:type';
|
||||||
|
} else if (hasPermissions('SYSTEM_USER:READ', 'SYSTEM_WORKSPACE:READ', 'SYSTEM_GROUP:READ', 'SYSTEM_TEST_POOL:READ', 'SYSTEM_SETTING:READ', 'SYSTEM_AUTH:READ', 'SYSTEM_QUOTA:READ', 'SYSTEM_OPERATING_LOG:READ')) {
|
||||||
|
redirectUrl = '/setting';
|
||||||
|
} else {
|
||||||
|
redirectUrl = '/';
|
||||||
|
}
|
||||||
|
sessionStorage.setItem('redirectUrl', redirectUrl);
|
||||||
|
sessionStorage.setItem('lastUser', getCurrentUserId());
|
||||||
|
this.loading = false;
|
||||||
|
router.push({name: "login_redirect", path: redirectUrl || '/', query: {}});
|
||||||
|
localStorage.setItem('loginType', 'LARK');
|
||||||
|
})
|
||||||
|
} catch (err) {
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.log(err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (state.split('#')[0] === 'fit2cloud-lark-suite-qr' && state.split('#')[1] === "/") {
|
||||||
|
this.loading = true;
|
||||||
|
try {
|
||||||
|
axios.get("/sso/callback/lark?lark_suite="+code).then((response) => {
|
||||||
|
const weComCallback = response.data.data;
|
||||||
|
const userStore = useUserStore()
|
||||||
|
// 删除缓存
|
||||||
|
userStore.checkPermission(response.data);
|
||||||
|
sessionStorage.removeItem('changePassword');
|
||||||
|
localStorage.setItem('default_language', weComCallback.language);
|
||||||
|
sessionStorage.setItem('loginSuccess', 'true');
|
||||||
|
sessionStorage.setItem('changePassword', weComCallback.message);
|
||||||
|
localStorage.setItem('AuthenticateType', 'QRCODE');
|
||||||
|
if (sessionStorage.getItem('lastUser') === getCurrentUserId()) {
|
||||||
|
router.push({path: sessionStorage.getItem('redirectUrl') || '/'});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let redirectUrl = '/';
|
||||||
|
if (hasPermissions('PROJECT_USER:READ', 'PROJECT_ENVIRONMENT:READ', 'PROJECT_OPERATING_LOG:READ', 'PROJECT_FILE:READ+JAR', 'PROJECT_FILE:READ+FILE', 'PROJECT_CUSTOM_CODE:READ', 'PROJECT_MESSAGE:READ', 'PROJECT_TEMPLATE:READ')) {
|
||||||
|
redirectUrl = '/project/home';
|
||||||
|
} else if (hasPermissions('WORKSPACE_SERVICE:READ', 'WORKSPACE_USER:READ', 'WORKSPACE_PROJECT_MANAGER:READ', 'WORKSPACE_PROJECT_ENVIRONMENT:READ', 'WORKSPACE_OPERATING_LOG:READ')) {
|
||||||
|
redirectUrl = '/setting/project/:type';
|
||||||
|
} else if (hasPermissions('SYSTEM_USER:READ', 'SYSTEM_WORKSPACE:READ', 'SYSTEM_GROUP:READ', 'SYSTEM_TEST_POOL:READ', 'SYSTEM_SETTING:READ', 'SYSTEM_AUTH:READ', 'SYSTEM_QUOTA:READ', 'SYSTEM_OPERATING_LOG:READ')) {
|
||||||
|
redirectUrl = '/setting';
|
||||||
|
} else {
|
||||||
|
redirectUrl = '/';
|
||||||
|
}
|
||||||
|
sessionStorage.setItem('redirectUrl', redirectUrl);
|
||||||
|
sessionStorage.setItem('lastUser', getCurrentUserId());
|
||||||
|
this.loading = false;
|
||||||
|
router.push({name: "login_redirect", path: redirectUrl || '/', query: {}});
|
||||||
|
localStorage.setItem('loginType', 'LARK_SUITE');
|
||||||
|
})
|
||||||
|
} catch (err) {
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.log(err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (getQueryVariable('code') && getQueryVariable('state')) {
|
||||||
|
const currentUrl = window.location.href;
|
||||||
|
const url = new URL(currentUrl);
|
||||||
|
getUrlParameterWidthRegExp('code');
|
||||||
|
getUrlParameterWidthRegExp('state');
|
||||||
|
url.searchParams.delete('code');
|
||||||
|
url.searchParams.delete('state');
|
||||||
|
const newUrl = url.toString();
|
||||||
|
// 或者在不刷新页面的情况下更新URL(比如使用 History API)
|
||||||
|
window.history.replaceState({}, document.title, newUrl);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
</script>
|
||||||
|
|
|
@ -29,7 +29,7 @@ export function getDingInfo() {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getDingCallback(code) {
|
export function getDingCallback(code) {
|
||||||
return get(GetDingCallbackUrl, code );
|
return get(GetDingCallbackUrl, code);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getLarkInfo() {
|
export function getLarkInfo() {
|
||||||
|
|
|
@ -5,14 +5,12 @@
|
||||||
<script>
|
<script>
|
||||||
|
|
||||||
|
|
||||||
import {getDingCallback, getDingInfo} from "../../api/qrcode";
|
import {getDingInfo} from "../../api/qrcode";
|
||||||
import loadJs from "../../utils/remoteJs";
|
import loadJs from "../../utils/remoteJs";
|
||||||
import {getCurrentUserId} from "../../utils/token";
|
import {getCurrentUserId} from "../../utils/token";
|
||||||
import {hasPermissions} from "../../utils/permission";
|
import {hasPermissions} from "../../utils/permission";
|
||||||
import {useUserStore} from "@/store";
|
import {useUserStore} from "@/store";
|
||||||
import {setLanguage} from "@/i18n";
|
import axios from "axios";
|
||||||
import {getLanguage} from "../../api/user";
|
|
||||||
import {DEFAULT_LANGUAGE} from "../../utils/constants";
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name:'dingTalkQrCode',
|
name:'dingTalkQrCode',
|
||||||
|
@ -21,61 +19,10 @@ export default {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods:{
|
methods:{
|
||||||
checkRedirectUrl() {
|
initActive(){
|
||||||
if (this.lastUser === getCurrentUserId()) {
|
getDingInfo().then(res=>{
|
||||||
this.$router.push({path: sessionStorage.getItem('redirectUrl') || '/'});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let redirectUrl = '/';
|
|
||||||
if (hasPermissions('PROJECT_USER:READ', 'PROJECT_ENVIRONMENT:READ', 'PROJECT_OPERATING_LOG:READ', 'PROJECT_FILE:READ+JAR', 'PROJECT_FILE:READ+FILE', 'PROJECT_CUSTOM_CODE:READ', 'PROJECT_MESSAGE:READ', 'PROJECT_TEMPLATE:READ')) {
|
|
||||||
redirectUrl = '/project/home';
|
|
||||||
} else if (hasPermissions('WORKSPACE_SERVICE:READ', 'WORKSPACE_USER:READ', 'WORKSPACE_PROJECT_MANAGER:READ', 'WORKSPACE_PROJECT_ENVIRONMENT:READ', 'WORKSPACE_OPERATING_LOG:READ')) {
|
|
||||||
redirectUrl = '/setting/project/:type';
|
|
||||||
} else if (hasPermissions('SYSTEM_USER:READ', 'SYSTEM_WORKSPACE:READ', 'SYSTEM_GROUP:READ', 'SYSTEM_TEST_POOL:READ', 'SYSTEM_SETTING:READ', 'SYSTEM_AUTH:READ', 'SYSTEM_QUOTA:READ', 'SYSTEM_OPERATING_LOG:READ')) {
|
|
||||||
redirectUrl = '/setting';
|
|
||||||
} else {
|
|
||||||
redirectUrl = '/';
|
|
||||||
}
|
|
||||||
|
|
||||||
sessionStorage.setItem('redirectUrl', redirectUrl);
|
|
||||||
sessionStorage.setItem('lastUser', getCurrentUserId());
|
|
||||||
this.$router.push({name: "login_redirect", path: redirectUrl || '/', query: this.otherQuery});
|
|
||||||
},
|
|
||||||
doLogin(callback) {
|
|
||||||
const userStore = useUserStore()
|
|
||||||
// 删除缓存
|
|
||||||
sessionStorage.removeItem('changePassword');
|
|
||||||
userStore.getIsLogin()
|
|
||||||
.then(res => {
|
|
||||||
this.getLanguage(res.data.language);
|
|
||||||
sessionStorage.setItem('loginSuccess', 'true');
|
|
||||||
sessionStorage.setItem('changePassword', callback.message);
|
|
||||||
localStorage.setItem('AuthenticateType', 'QRCODE');
|
|
||||||
this.checkRedirectUrl()
|
|
||||||
})
|
|
||||||
.catch(data => {
|
|
||||||
// 保存公钥
|
|
||||||
localStorage.setItem("publicKey", data.message);
|
|
||||||
let lang = localStorage.getItem("language");
|
|
||||||
if (lang) {
|
|
||||||
setLanguage(lang);
|
|
||||||
}
|
|
||||||
window.location.href = "/";
|
|
||||||
});
|
|
||||||
},
|
|
||||||
getLanguage(language) {
|
|
||||||
if (!language) {
|
|
||||||
getLanguage()
|
|
||||||
.then(response => {
|
|
||||||
language = response.data;
|
|
||||||
localStorage.setItem(DEFAULT_LANGUAGE, language);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
async initActive(){
|
|
||||||
await getDingInfo().then(res=>{
|
|
||||||
const dingData =res.data;
|
const dingData =res.data;
|
||||||
|
const router = this.$router
|
||||||
const url = encodeURIComponent(window.location.origin);
|
const url = encodeURIComponent(window.location.origin);
|
||||||
window.DTFrameLogin(
|
window.DTFrameLogin(
|
||||||
{
|
{
|
||||||
|
@ -91,12 +38,45 @@ export default {
|
||||||
state: 'fit2cloud-ding-qr',
|
state: 'fit2cloud-ding-qr',
|
||||||
prompt: 'consent',
|
prompt: 'consent',
|
||||||
},
|
},
|
||||||
async (loginResult) => {
|
(loginResult) => {
|
||||||
const { authCode } = loginResult;
|
const {redirectUrl, authCode, state} = loginResult;
|
||||||
const dingCallback = getDingCallback(authCode);
|
axios.get("/sso/callback/ding_talk?code="+authCode).then((response) => {
|
||||||
|
if (response.data && response.data.data) {
|
||||||
// 也可以在不跳转页面的情况下,使用code进行授权
|
// 也可以在不跳转页面的情况下,使用code进行授权
|
||||||
this.doLogin(dingCallback);
|
const weComCallback = response.data.data;
|
||||||
|
const userStore = useUserStore()
|
||||||
|
// 删除缓存
|
||||||
|
userStore.checkPermission(response.data);
|
||||||
|
sessionStorage.removeItem('changePassword');
|
||||||
|
localStorage.setItem('default_language', weComCallback.language);
|
||||||
|
sessionStorage.setItem('loginSuccess', 'true');
|
||||||
|
sessionStorage.setItem('changePassword', weComCallback.message);
|
||||||
|
localStorage.setItem('AuthenticateType', 'QRCODE');
|
||||||
|
if (sessionStorage.getItem('lastUser') === getCurrentUserId()) {
|
||||||
|
router.push({path: sessionStorage.getItem('redirectUrl') || '/'});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let routerUrl = '/';
|
||||||
|
if (hasPermissions('PROJECT_USER:READ', 'PROJECT_ENVIRONMENT:READ', 'PROJECT_OPERATING_LOG:READ', 'PROJECT_FILE:READ+JAR', 'PROJECT_FILE:READ+FILE', 'PROJECT_CUSTOM_CODE:READ', 'PROJECT_MESSAGE:READ', 'PROJECT_TEMPLATE:READ')) {
|
||||||
|
routerUrl = '/project/home';
|
||||||
|
} else if (hasPermissions('WORKSPACE_SERVICE:READ', 'WORKSPACE_USER:READ', 'WORKSPACE_PROJECT_MANAGER:READ', 'WORKSPACE_PROJECT_ENVIRONMENT:READ', 'WORKSPACE_OPERATING_LOG:READ')) {
|
||||||
|
routerUrl = '/setting/project/:type';
|
||||||
|
} else if (hasPermissions('SYSTEM_USER:READ', 'SYSTEM_WORKSPACE:READ', 'SYSTEM_GROUP:READ', 'SYSTEM_TEST_POOL:READ', 'SYSTEM_SETTING:READ', 'SYSTEM_AUTH:READ', 'SYSTEM_QUOTA:READ', 'SYSTEM_OPERATING_LOG:READ')) {
|
||||||
|
routerUrl = '/setting';
|
||||||
|
} else {
|
||||||
|
routerUrl = '/';
|
||||||
|
}
|
||||||
|
console.log("routerUrl")
|
||||||
|
console.log(routerUrl)
|
||||||
|
sessionStorage.setItem('redirectUrl', routerUrl);
|
||||||
|
sessionStorage.setItem('lastUser', getCurrentUserId());
|
||||||
|
router.push({name: "login_redirect", path: routerUrl || '/', query: {}});
|
||||||
localStorage.setItem('loginType', 'DING_TALK');
|
localStorage.setItem('loginType', 'DING_TALK');
|
||||||
|
}
|
||||||
|
}).catch((err)=>{
|
||||||
|
console.log("axios")
|
||||||
|
console.log(err)
|
||||||
|
});
|
||||||
},
|
},
|
||||||
(errorMsg) => {
|
(errorMsg) => {
|
||||||
// 这里一般需要展示登录失败的具体原因,可以使用toast等轻提示
|
// 这里一般需要展示登录失败的具体原因,可以使用toast等轻提示
|
||||||
|
|
|
@ -55,12 +55,15 @@
|
||||||
{{ $t('commons.login') }}
|
{{ $t('commons.login') }}
|
||||||
</el-button>
|
</el-button>
|
||||||
</div>
|
</div>
|
||||||
<el-divider v-if="orgOptions.length > 0" class="login-divider"
|
<el-divider v-xpack v-if="orgOptions.length > 0" class="login-divider"><span style="color: #959598; font-size: 12px">更多登录方式</span></el-divider>
|
||||||
><span style="color: #959598; font-size: 12px">更多登录方式</span></el-divider
|
<div
|
||||||
|
v-xpack
|
||||||
|
v-if="orgOptions.length > 0"
|
||||||
|
class="loginType"
|
||||||
|
@click="switchLoginType('QR_CODE')"
|
||||||
>
|
>
|
||||||
<div v-if="orgOptions.length > 0" class="loginType" @click="switchLoginType('QR_CODE')">
|
<svg-icon v-if="!showQrCodeTab" icon-class="icon_scan_code" class-name="ms-icon"/>
|
||||||
<svg-icon v-if="!showQrCodeTab" icon-class="icon_scan_code" class-name="ms-icon" />
|
<svg-icon v-if="showQrCodeTab" icon-class="icon_people" class-name="ms-icon"/>
|
||||||
<svg-icon v-if="showQrCodeTab" icon-class="icon_people" class-name="ms-icon" />
|
|
||||||
</div>
|
</div>
|
||||||
<div class="msg">
|
<div class="msg">
|
||||||
{{ msg }}
|
{{ msg }}
|
||||||
|
@ -90,15 +93,17 @@ import {
|
||||||
getDisplayInfo,
|
getDisplayInfo,
|
||||||
getLanguage,
|
getLanguage,
|
||||||
getSystemTheme,
|
getSystemTheme,
|
||||||
saveBaseUrl,
|
saveBaseUrl
|
||||||
} from '../../api/user';
|
} from "../../api/user";
|
||||||
import { useUserStore } from '@/store';
|
import {useUserStore} from "@/store"
|
||||||
import { operationConfirm } from '../../utils';
|
import {getQueryVariable, getUrlParameterWidthRegExp, operationConfirm} from "../../utils";
|
||||||
import { getModuleList } from '../../api/module';
|
import {getModuleList} from "../../api/module";
|
||||||
import { getLicense } from '../../api/license';
|
import {getLicense} from "../../api/license";
|
||||||
import { setLanguage } from '../../i18n';
|
import {setLanguage} from "../../i18n";
|
||||||
import { getPlatformParamUrl } from '../../api/qrcode';
|
import {getLarkCallback, getLarkSuiteCallback, getPlatformParamUrl} from "../../api/qrcode";
|
||||||
import tabQrCode from '../login/tabQrCode.vue';
|
import tabQrCode from "../login/tabQrCode.vue";
|
||||||
|
import axios from "axios";
|
||||||
|
|
||||||
const checkLicense = () => {
|
const checkLicense = () => {
|
||||||
return getLicense()
|
return getLicense()
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
|
|
|
@ -11,7 +11,6 @@
|
||||||
import {getWeComCallback, getWeComInfo} from "../../api/qrcode";
|
import {getWeComCallback, getWeComInfo} from "../../api/qrcode";
|
||||||
import {getCurrentUserId} from "../../utils/token";
|
import {getCurrentUserId} from "../../utils/token";
|
||||||
import {getLanguage} from "../../api/user";
|
import {getLanguage} from "../../api/user";
|
||||||
import {setLanguage} from "@/i18n";
|
|
||||||
import {hasPermissions} from "../../utils/permission";
|
import {hasPermissions} from "../../utils/permission";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
@ -26,48 +25,6 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods:{
|
methods:{
|
||||||
checkRedirectUrl() {
|
|
||||||
if (this.lastUser === getCurrentUserId()) {
|
|
||||||
this.$router.push({path: sessionStorage.getItem('redirectUrl') || '/'});
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let redirectUrl = '/';
|
|
||||||
if (hasPermissions('PROJECT_USER:READ', 'PROJECT_ENVIRONMENT:READ', 'PROJECT_OPERATING_LOG:READ', 'PROJECT_FILE:READ+JAR', 'PROJECT_FILE:READ+FILE', 'PROJECT_CUSTOM_CODE:READ', 'PROJECT_MESSAGE:READ', 'PROJECT_TEMPLATE:READ')) {
|
|
||||||
redirectUrl = '/project/home';
|
|
||||||
} else if (hasPermissions('WORKSPACE_SERVICE:READ', 'WORKSPACE_USER:READ', 'WORKSPACE_PROJECT_MANAGER:READ', 'WORKSPACE_PROJECT_ENVIRONMENT:READ', 'WORKSPACE_OPERATING_LOG:READ')) {
|
|
||||||
redirectUrl = '/setting/project/:type';
|
|
||||||
} else if (hasPermissions('SYSTEM_USER:READ', 'SYSTEM_WORKSPACE:READ', 'SYSTEM_GROUP:READ', 'SYSTEM_TEST_POOL:READ', 'SYSTEM_SETTING:READ', 'SYSTEM_AUTH:READ', 'SYSTEM_QUOTA:READ', 'SYSTEM_OPERATING_LOG:READ')) {
|
|
||||||
redirectUrl = '/setting';
|
|
||||||
} else {
|
|
||||||
redirectUrl = '/';
|
|
||||||
}
|
|
||||||
|
|
||||||
sessionStorage.setItem('redirectUrl', redirectUrl);
|
|
||||||
sessionStorage.setItem('lastUser', getCurrentUserId());
|
|
||||||
this.$router.push({name: "login_redirect", path: redirectUrl || '/', query: this.otherQuery});
|
|
||||||
},
|
|
||||||
|
|
||||||
doLogin(weComCallback) {
|
|
||||||
const userStore = useUserStore()
|
|
||||||
// 删除缓存
|
|
||||||
sessionStorage.removeItem('changePassword');
|
|
||||||
userStore.getIsLogin()
|
|
||||||
.then(res => {
|
|
||||||
this.getLanguage(res.data.language);
|
|
||||||
sessionStorage.setItem('loginSuccess', 'true');
|
|
||||||
sessionStorage.setItem('changePassword', weComCallback.message);
|
|
||||||
localStorage.setItem('AuthenticateType', 'QRCODE');
|
|
||||||
})
|
|
||||||
.catch(data => {
|
|
||||||
// 保存公钥
|
|
||||||
localStorage.setItem("publicKey", data.message);
|
|
||||||
let lang = localStorage.getItem("language");
|
|
||||||
if (lang) {
|
|
||||||
setLanguage(lang);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
this.checkRedirectUrl()
|
|
||||||
},
|
|
||||||
getLanguage(language) {
|
getLanguage(language) {
|
||||||
if (!language) {
|
if (!language) {
|
||||||
getLanguage()
|
getLanguage()
|
||||||
|
@ -77,10 +34,10 @@
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
init () {
|
||||||
async init () {
|
getWeComInfo().then(res => {
|
||||||
await getWeComInfo().then(res => {
|
|
||||||
const data = res.data;
|
const data = res.data;
|
||||||
|
const router = this.$router
|
||||||
this.wwLogin= ww.createWWLoginPanel({
|
this.wwLogin= ww.createWWLoginPanel({
|
||||||
el: '#wecom-qr',
|
el: '#wecom-qr',
|
||||||
params: {
|
params: {
|
||||||
|
@ -96,14 +53,37 @@
|
||||||
onLoginSuccess(code) {
|
onLoginSuccess(code) {
|
||||||
getWeComCallback(code).then(res=>{
|
getWeComCallback(code).then(res=>{
|
||||||
const weComCallback = res.data;
|
const weComCallback = res.data;
|
||||||
console.log("weComCallback")
|
const userStore = useUserStore()
|
||||||
console.log(weComCallback)
|
// 删除缓存
|
||||||
this.doLogin(weComCallback)
|
userStore.checkPermission(res);
|
||||||
|
sessionStorage.removeItem('changePassword');
|
||||||
|
localStorage.setItem('default_language', weComCallback.language);
|
||||||
|
sessionStorage.setItem('loginSuccess', 'true');
|
||||||
|
sessionStorage.setItem('changePassword', weComCallback.message);
|
||||||
|
localStorage.setItem('AuthenticateType', 'QRCODE');
|
||||||
|
if (sessionStorage.getItem('lastUser') === getCurrentUserId()) {
|
||||||
|
router.push({path: sessionStorage.getItem('redirectUrl') || '/'});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
let redirectUrl = '/';
|
||||||
|
if (hasPermissions('PROJECT_USER:READ', 'PROJECT_ENVIRONMENT:READ', 'PROJECT_OPERATING_LOG:READ', 'PROJECT_FILE:READ+JAR', 'PROJECT_FILE:READ+FILE', 'PROJECT_CUSTOM_CODE:READ', 'PROJECT_MESSAGE:READ', 'PROJECT_TEMPLATE:READ')) {
|
||||||
|
redirectUrl = '/project/home';
|
||||||
|
} else if (hasPermissions('WORKSPACE_SERVICE:READ', 'WORKSPACE_USER:READ', 'WORKSPACE_PROJECT_MANAGER:READ', 'WORKSPACE_PROJECT_ENVIRONMENT:READ', 'WORKSPACE_OPERATING_LOG:READ')) {
|
||||||
|
redirectUrl = '/setting/project/:type';
|
||||||
|
} else if (hasPermissions('SYSTEM_USER:READ', 'SYSTEM_WORKSPACE:READ', 'SYSTEM_GROUP:READ', 'SYSTEM_TEST_POOL:READ', 'SYSTEM_SETTING:READ', 'SYSTEM_AUTH:READ', 'SYSTEM_QUOTA:READ', 'SYSTEM_OPERATING_LOG:READ')) {
|
||||||
|
redirectUrl = '/setting';
|
||||||
|
} else {
|
||||||
|
redirectUrl = '/';
|
||||||
|
}
|
||||||
|
sessionStorage.setItem('redirectUrl', redirectUrl);
|
||||||
|
sessionStorage.setItem('lastUser', getCurrentUserId());
|
||||||
|
router.push({name: "login_redirect", path: redirectUrl || '/', query: {}});
|
||||||
localStorage.setItem('loginType', 'WE_COM');
|
localStorage.setItem('loginType', 'WE_COM');
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
onLoginFail(err) {
|
onLoginFail(err) {
|
||||||
console.log(err.errMsg);
|
console.log("err");
|
||||||
|
console.log(err);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -135,6 +135,13 @@ export default {
|
||||||
switchProject(response) {
|
switchProject(response) {
|
||||||
this.$patch(response.data);
|
this.$patch(response.data);
|
||||||
sessionStorage.setItem(PROJECT_ID, response.data.lastProjectId);
|
sessionStorage.setItem(PROJECT_ID, response.data.lastProjectId);
|
||||||
|
},
|
||||||
|
checkPermission(response){
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
this.$patch(response.data)
|
||||||
|
saveSessionStorage(response)
|
||||||
|
resolve(response)
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -487,3 +487,34 @@ export function gotoNext(_this, path, step) {
|
||||||
this.$router.push(path)
|
this.$router.push(path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getQueryVariable(variable) {
|
||||||
|
const urlString = window.location.href;
|
||||||
|
const queryIndex = urlString.indexOf('?');
|
||||||
|
if (queryIndex !== -1) {
|
||||||
|
const query = urlString.substring(queryIndex + 1);
|
||||||
|
|
||||||
|
// 分割查询参数
|
||||||
|
const params = query.split('&');
|
||||||
|
// 遍历参数,找到 _token 参数的值
|
||||||
|
let variableValue;
|
||||||
|
params.forEach((param) => {
|
||||||
|
const equalIndex = param.indexOf('=');
|
||||||
|
const variableName = param.substring(0, equalIndex);
|
||||||
|
if (variableName === variable) {
|
||||||
|
variableValue = param.substring(equalIndex + 1);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return variableValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getUrlParameterWidthRegExp(name) {
|
||||||
|
const url = window.location.href;
|
||||||
|
name = name.replace(/[[\]]/g, '\\$&');
|
||||||
|
const regex = new RegExp(`[?&]${name}(=([^&#]*)|&|#|$)`);
|
||||||
|
const results = regex.exec(url);
|
||||||
|
if (!results) return null;
|
||||||
|
if (!results[2]) return '';
|
||||||
|
return decodeURIComponent(results[2].replace(/\+/g, ' '));
|
||||||
|
}
|
||||||
|
|
|
@ -16,7 +16,7 @@ window.QRLogin= function(qrLogin) {
|
||||||
// ********************************************************************************
|
// ********************************************************************************
|
||||||
// Note: The width and height parameters only set the QR code iframe element's size and do not affect the container size.
|
// Note: The width and height parameters only set the QR code iframe element's size and do not affect the container size.
|
||||||
// The container's size and style must be set using CSS by the integrator.
|
// The container's size and style must be set using CSS by the integrator.
|
||||||
const IDTLoginFrameParams = {
|
const frameParams = {
|
||||||
id: '', // Required, container element ID, without '#'
|
id: '', // Required, container element ID, without '#'
|
||||||
width: 300, // Optional, QR code iframe width, minimum 280, default 300
|
width: 300, // Optional, QR code iframe width, minimum 280, default 300
|
||||||
height: 300 // Optional, QR code iframe height, minimum 280, default 300
|
height: 300 // Optional, QR code iframe height, minimum 280, default 300
|
||||||
|
@ -27,7 +27,7 @@ const IDTLoginFrameParams = {
|
||||||
// ********************************************************************************
|
// ********************************************************************************
|
||||||
// The parameters are the same as those used for "splicing link to initiate login authorization" (some parameters are missing).
|
// The parameters are the same as those used for "splicing link to initiate login authorization" (some parameters are missing).
|
||||||
// Added the isPre parameter to set the running environment.
|
// Added the isPre parameter to set the running environment.
|
||||||
const IDTLoginLoginParams = {
|
const loginParams = {
|
||||||
redirect_uri: '', // Required, URL must be encoded
|
redirect_uri: '', // Required, URL must be encoded
|
||||||
response_type: 'code', // Required, fixed value 'code'
|
response_type: 'code', // Required, fixed value 'code'
|
||||||
client_id: '', // Required
|
client_id: '', // Required
|
||||||
|
|
|
@ -11,7 +11,7 @@ module.exports = defineConfig({
|
||||||
publicPath: "/",
|
publicPath: "/",
|
||||||
productionSourceMap: false,
|
productionSourceMap: false,
|
||||||
devServer: {
|
devServer: {
|
||||||
port: 3000,
|
port: 5244,
|
||||||
client: {
|
client: {
|
||||||
webSocketTransport: "sockjs",
|
webSocketTransport: "sockjs",
|
||||||
overlay: false,
|
overlay: false,
|
||||||
|
|
Loading…
Reference in New Issue