cas 单点登录完成

This commit is contained in:
clay
2022-09-05 22:53:45 +08:00
parent 812a7b4595
commit a186667478
10 changed files with 85 additions and 12 deletions

View File

@@ -3,7 +3,7 @@ ENV = 'development'
# EBTS/开发环境
#VUE_APP_BASE_API = '/dev-api'
VUE_APP_BASE_API = 'http://192.168.190.67'
VUE_APP_BASE_API = 'http://192.168.190.67/dev-api'
#VUE_APP_BASE_API = 'http://sistapi.hchyun.cn/dev-api'
# 路由懒加载

View File

@@ -5,4 +5,5 @@ ENV = 'staging'
# EBTS/测试环境
#VUE_APP_BASE_API = '/dev-api'
VUE_APP_BASE_API = 'http://sistapi.hchyun.cn/dev-api'
#VUE_APP_BASE_API = 'http://sistapi.hchyun.cn/dev-api'
VUE_APP_BASE_API = 'http://192.168.190.67/dev-api'

View File

@@ -37,4 +37,19 @@ export function getCodeImg() {
url: '/captchaImage',
method: 'get'
})
}
}
// 获取验证码
export function casLogin() {
return request({
url: '/cas-login',
method: 'get'
})
}
// 获取验证码
export function casLogout() {
return request({
url: '/logout',
method: 'get'
})
}

View File

@@ -4,11 +4,12 @@ import { Message } from 'element-ui'
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'
import { getToken } from '@/utils/auth'
import axios from "axios";
NProgress.configure({ showSpinner: false })
const whiteList = ['/login', '/auth-redirect', '/bind', '/register']
const whiteList = ['/login', '/auth-redirect', '/bind', '/register','/cas-login','logout']
const defaultSettings = require('@/settings.js')
router.beforeEach((to, from, next) => {
@@ -50,17 +51,20 @@ router.beforeEach((to, from, next) => {
}
}
} else {
debugger
// debugger
// 没有token
if (whiteList.indexOf(to.path) !== -1) {
// 在免登录白名单,直接进入
next()
} else {
// next(`/login?redirect=${to.fullPath}`) // 否则全部重定向到登录页
// axios.get("http://192.168.190.67/dev-api/cas-login").then(res=>{
//
// })
// NProgress.done()
if (!defaultSettings.casEnable) {
next(`/login?redirect=${to.fullPath}`) // 否则全部重定向到登录页
}
// if (!defaultSettings.casEnable) {
// next(`/login?redirect=${to.fullPath}`) // 否则全部重定向到登录页
// }
//开启cas
if (defaultSettings.casEnable) {
window.location.href = defaultSettings.casloginUrl // 否则全部重定向到登录页

View File

@@ -42,6 +42,16 @@ export const constantRoutes = [
component: (resolve) => require(['@/views/login'], resolve),
hidden: true
},
{
path: '/cas-login',
component: (resolve) => require(['@/views/cas-login.vue'], resolve),
hidden: true
},
{
path: '/logout',
component: (resolve) => require(['@/views/cas-logout.vue'], resolve),
hidden: true
},
{
path: '/404',
component: (resolve) => require(['@/views/error/404'], resolve),

View File

@@ -8,13 +8,13 @@ module.exports = {
/**
* 单点登录url
*/
casloginUrl: 'https://cas.swjtu.edu.cn/authserver/login?service=http://192.168.190.67/dev-api/dev',
casloginUrl: 'https://cas.swjtu.edu.cn/authserver/login?service=http://192.168.190.67/dev-api/cas-login',
/**
* 单点登出url
*/
// caslogoutUrl: 'http://localhost:8888/cas/logout?service=http://localhost:8080',
caslogoutUrl: 'https://cas.swjtu.edu.cn/authserver/logout?service=http://192.168.190.67',
caslogoutUrl: 'https://cas.swjtu.edu.cn/authserver/logout?service=http://192.168.190.67/admin/logout',
/**

View File

@@ -4,6 +4,7 @@ import store from '@/store'
import { getToken } from '@/utils/auth'
import errorCode from '@/utils/errorCode'
axios.defaults.withCredentials = true;//这行代码是必须的
axios.defaults.headers['Content-Type'] = 'application/json;charset=utf-8'
const defaultSettings = require('@/settings')
// 创建axios实例

View File

@@ -0,0 +1,21 @@
<template>
</template>
<script>
import {setToken} from "@/utils/auth";
export default {
name: "cas-login",
mounted() {
// debugger
let search = window.location.search;
let token = search.slice(search.indexOf("=") + 1)
setToken(token)
this.$router.push('/')
},
methods: {}
}
</script>
<style scoped>
</style>

View File

@@ -0,0 +1,21 @@
<template>
</template>
<script>
import {casLogout} from "@/api/login";
export default {
name: "logout",
mounted() {
casLogout().then(res=>{
console.log(res)
})
}
}
</script>
<style scoped>
</style>

View File

@@ -17,8 +17,8 @@ module.exports = {
// 部署生产环境和开发环境下的URL。
// 默认情况下Vue CLI 会假设你的应用是被部署在一个域名的根路径上
// 例如 https://www.hchyun.com/。如果应用被部署在一个子路径上,你就需要用这个选项指定这个子路径。例如,如果你的应用被部署在 https://www.hchyun.com/admin/,则设置 baseUrl 为 /admin/。
// publicPath: "/admin/",
publicPath: "/",
publicPath: "/admin/",
// publicPath: "/",
// 在npm run build 或 yarn build 时 生成文件的目录名称要和baseUrl的生产环境路径一致默认dist
outputDir: 'dist',
// 用于放置生成的静态资源 (js、css、img、fonts) 的;(项目打包之后,静态资源会放在这个文件夹下)