feat(系统管理): 扫码登录登录页面调整

This commit is contained in:
guoyuqi 2024-09-04 20:07:35 +08:00 committed by 刘瑞斌
parent 6c6e0c56e9
commit e0b0cf67aa
13 changed files with 275 additions and 155 deletions

View File

@ -166,7 +166,7 @@ public class LoginController {
}
@GetMapping(value = "/callback/we_com")
@GetMapping(value = "/sso/callback/we_com")
@Operation(summary = "获取企业微信登陆验证")
@MsAuditLog(module = OperLogModule.AUTH_TITLE, type = OperLogConstants.LOGIN, title = "WE_COM")
public Mono<ResultHolder> callbackWeCom(@RequestParam("code") String code, WebSession session, Locale locale) {

View File

@ -38,6 +38,8 @@ public class LoginFilter implements WebFilter, Ordered {
excludePatterns.add(new PathPatternParser().parse("/"));
// 认证源查询
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())));

View File

@ -18,7 +18,7 @@ import java.util.Optional;
public class SessionFilter implements WebFilter {
// 所有模块的前缀
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 API_DOWNLOAD_PREFIX = "/api/jmeter/";
private static final String TRACK_IMAGE_PREFIX = "/resource/md/get/path";

View File

@ -143,9 +143,9 @@ public class UserLoginService {
}
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) {
user = getUserDTOByEmail(userId, UserSource.LOCAL.name());
user = getUserDTOByEmail(userId, UserSource.LOCAL.name(), UserSource.QR_CODE.name());
if (user == null) {
throw new RuntimeException(Translator.get("password_is_incorrect"));
}
@ -422,7 +422,7 @@ public class UserLoginService {
if (userId.length() > 64) {
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"));
}
UserExample example = new UserExample();
@ -595,7 +595,7 @@ public class UserLoginService {
userDTOByEmail = getUserDTOByEmail(email);
if (userDTO != null && userDTOByEmail == null) {
userDTOByEmail = new UserDTO();
io.metersphere.commons.utils.BeanUtils.copyBean(userDTOByEmail, userDTO);
BeanUtils.copyProperties(userDTO, userDTOByEmail);
userDTOByEmail.setEmail(email);
changeMail = true;
}
@ -624,6 +624,7 @@ public class UserLoginService {
LogUtil.info(email);
LogUtil.info(name);
LogUtil.info(userId);
userCreateInfo.setEmail(email);
creatUser(userCreateInfo, source);
} else {
userId = userDTOByEmail.getId();
@ -642,18 +643,15 @@ public class UserLoginService {
LogUtil.info(userId);
LoginRequest request = new LoginRequest();
try {
RsaKey rsaKey = RsaUtil.getRsaKey();
request.setAuthenticate(source);
request.setUsername(RsaUtil.publicEncrypt(userId, rsaKey.getPublicKey()));
request.setPassword(CodingUtil.md5(email));
request.setUsername(userId);
request.setPassword(email);
} catch (Exception e) {
LogUtil.error("login error: ", e);
MSException.throwException("login error: " + e.getMessage());
}
Optional<SessionUser> login = login(request, session, locale);
SecurityUtils.getSubject().getSession().setAttribute("authenticate", source);
return login;
return login(request, session, locale);
}
private void updateUser(String email, String userId) {
@ -672,7 +670,7 @@ public class UserLoginService {
PlatformSource platformSource = platformSourceMapper.selectByPrimaryKey(key);
WeComInfoDTO weComInfoDTO = new WeComInfoDTO();
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.setValid(platformSource.getValid());
return weComInfoDTO;
@ -683,7 +681,7 @@ public class UserLoginService {
PlatformSource platformSource = platformSourceMapper.selectByPrimaryKey(key);
DingTalkInfoDTO dingTalkInfoDTO = new DingTalkInfoDTO();
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.setValid(platformSource.getValid());
return dingTalkInfoDTO;
@ -706,16 +704,16 @@ public class UserLoginService {
private void creatUser(UserRequest userCreateInfo, String source) {
User user = new User();
io.metersphere.commons.utils.BeanUtils.copyBean(user, userCreateInfo);
BeanUtils.copyProperties(userCreateInfo, user);
user.setCreateTime(System.currentTimeMillis());
user.setCreateUser(SessionUtils.getUserId());
user.setCreateUser("admin");
user.setUpdateTime(System.currentTimeMillis());
// 默认1:启用状态
user.setStatus(UserStatus.NORMAL);
user.setSource(source);
// 密码使用 MD5
user.setPassword(CodingUtil.md5(user.getPassword()));
checkEmailIsExist(user.getEmail());
user.setEmail(user.getEmail());
user.setPassword(CodingUtil.md5(user.getEmail()));
userMapper.insertSelective(user);
//获取默认空间
Workspace workspace = getWorkspace();
@ -724,21 +722,26 @@ public class UserLoginService {
//添加用户组
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();
log.setOperTitle(user.getName());
log.setOperContent(user.getName());
log.setProjectId(project.getId());
log.setOperPath("/sso/callback/we_com");
log.setId(UUID.randomUUID().toString());
log.setOperType(OperLogConstants.CREATE.name());
log.setOperModule(OperLogModule.SYSTEM_PARAMETER_SETTING);
log.setProjectId(null);
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);
log.setOperContent(JSON.toJSONString(details));
log.setOperTime(System.currentTimeMillis());
@ -824,7 +827,7 @@ public class UserLoginService {
}
LarkInfoDTO LarkInfoDTO = new LarkInfoDTO();
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.setValid(platformSource.getValid());
return LarkInfoDTO;

View File

@ -6,3 +6,115 @@
<div id="micro-app"></div>
</div>
</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>

View File

@ -29,7 +29,7 @@ export function getDingInfo() {
}
export function getDingCallback(code) {
return get(GetDingCallbackUrl, code );
return get(GetDingCallbackUrl, code);
}
export function getLarkInfo() {

View File

@ -5,14 +5,12 @@
<script>
import {getDingCallback, getDingInfo} from "../../api/qrcode";
import {getDingInfo} from "../../api/qrcode";
import loadJs from "../../utils/remoteJs";
import {getCurrentUserId} from "../../utils/token";
import {hasPermissions} from "../../utils/permission";
import {useUserStore} from "@/store";
import {setLanguage} from "@/i18n";
import {getLanguage} from "../../api/user";
import {DEFAULT_LANGUAGE} from "../../utils/constants";
import axios from "axios";
export default {
name:'dingTalkQrCode',
@ -21,61 +19,10 @@ export default {
}
},
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(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=>{
initActive(){
getDingInfo().then(res=>{
const dingData =res.data;
const router = this.$router
const url = encodeURIComponent(window.location.origin);
window.DTFrameLogin(
{
@ -91,12 +38,45 @@ export default {
state: 'fit2cloud-ding-qr',
prompt: 'consent',
},
async (loginResult) => {
const { authCode } = loginResult;
const dingCallback = getDingCallback(authCode);
// 使code
this.doLogin(dingCallback);
localStorage.setItem('loginType', 'DING_TALK');
(loginResult) => {
const {redirectUrl, authCode, state} = loginResult;
axios.get("/sso/callback/ding_talk?code="+authCode).then((response) => {
if (response.data && response.data.data) {
// 使code
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');
}
}).catch((err)=>{
console.log("axios")
console.log(err)
});
},
(errorMsg) => {
// ,使toast

View File

@ -55,12 +55,15 @@
{{ $t('commons.login') }}
</el-button>
</div>
<el-divider v-if="orgOptions.length > 0" class="login-divider"
><span style="color: #959598; font-size: 12px">更多登录方式</span></el-divider
<el-divider v-xpack v-if="orgOptions.length > 0" class="login-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_people" 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"/>
</div>
<div class="msg">
{{ msg }}
@ -90,15 +93,17 @@ import {
getDisplayInfo,
getLanguage,
getSystemTheme,
saveBaseUrl,
} from '../../api/user';
import { useUserStore } from '@/store';
import { operationConfirm } from '../../utils';
import { getModuleList } from '../../api/module';
import { getLicense } from '../../api/license';
import { setLanguage } from '../../i18n';
import { getPlatformParamUrl } from '../../api/qrcode';
import tabQrCode from '../login/tabQrCode.vue';
saveBaseUrl
} from "../../api/user";
import {useUserStore} from "@/store"
import {getQueryVariable, getUrlParameterWidthRegExp, operationConfirm} from "../../utils";
import {getModuleList} from "../../api/module";
import {getLicense} from "../../api/license";
import {setLanguage} from "../../i18n";
import {getLarkCallback, getLarkSuiteCallback, getPlatformParamUrl} from "../../api/qrcode";
import tabQrCode from "../login/tabQrCode.vue";
import axios from "axios";
const checkLicense = () => {
return getLicense()
.then((response) => {

View File

@ -11,7 +11,6 @@
import {getWeComCallback, getWeComInfo} from "../../api/qrcode";
import {getCurrentUserId} from "../../utils/token";
import {getLanguage} from "../../api/user";
import {setLanguage} from "@/i18n";
import {hasPermissions} from "../../utils/permission";
export default {
@ -26,48 +25,6 @@
}
},
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) {
if (!language) {
getLanguage()
@ -77,10 +34,10 @@
});
}
},
async init () {
await getWeComInfo().then(res => {
init () {
getWeComInfo().then(res => {
const data = res.data;
const router = this.$router
this.wwLogin= ww.createWWLoginPanel({
el: '#wecom-qr',
params: {
@ -96,14 +53,37 @@
onLoginSuccess(code) {
getWeComCallback(code).then(res=>{
const weComCallback = res.data;
console.log("weComCallback")
console.log(weComCallback)
this.doLogin(weComCallback)
const userStore = useUserStore()
//
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');
});
},
onLoginFail(err) {
console.log(err.errMsg);
console.log("err");
console.log(err);
},
});
});

View File

@ -135,6 +135,13 @@ export default {
switchProject(response) {
this.$patch(response.data);
sessionStorage.setItem(PROJECT_ID, response.data.lastProjectId);
},
checkPermission(response){
return new Promise((resolve, reject) => {
this.$patch(response.data)
saveSessionStorage(response)
resolve(response)
});
}
}
}

View File

@ -487,3 +487,34 @@ export function gotoNext(_this, path, step) {
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, ' '));
}

View File

@ -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.
// The container's size and style must be set using CSS by the integrator.
const IDTLoginFrameParams = {
const frameParams = {
id: '', // Required, container element ID, without '#'
width: 300, // Optional, QR code iframe width, 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).
// Added the isPre parameter to set the running environment.
const IDTLoginLoginParams = {
const loginParams = {
redirect_uri: '', // Required, URL must be encoded
response_type: 'code', // Required, fixed value 'code'
client_id: '', // Required

View File

@ -11,7 +11,7 @@ module.exports = defineConfig({
publicPath: "/",
productionSourceMap: false,
devServer: {
port: 3000,
port: 5244,
client: {
webSocketTransport: "sockjs",
overlay: false,