cas 单点登录完成
This commit is contained in:
@@ -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'
|
||||
|
||||
# 路由懒加载
|
||||
|
||||
@@ -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'
|
||||
|
||||
@@ -38,3 +38,18 @@ export function getCodeImg() {
|
||||
method: 'get'
|
||||
})
|
||||
}
|
||||
|
||||
// 获取验证码
|
||||
export function casLogin() {
|
||||
return request({
|
||||
url: '/cas-login',
|
||||
method: 'get'
|
||||
})
|
||||
}
|
||||
// 获取验证码
|
||||
export function casLogout() {
|
||||
return request({
|
||||
url: '/logout',
|
||||
method: 'get'
|
||||
})
|
||||
}
|
||||
|
||||
@@ -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 // 否则全部重定向到登录页
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -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',
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -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实例
|
||||
|
||||
21
ebts-ui/src/views/cas-login.vue
Normal file
21
ebts-ui/src/views/cas-login.vue
Normal 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>
|
||||
21
ebts-ui/src/views/cas-logout.vue
Normal file
21
ebts-ui/src/views/cas-logout.vue
Normal 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>
|
||||
@@ -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) 的;(项目打包之后,静态资源会放在这个文件夹下)
|
||||
|
||||
Reference in New Issue
Block a user