Commit f603c787 authored by liwenhong's avatar liwenhong

add:login

parent 2edd304f
...@@ -22,5 +22,6 @@ module.exports = { ...@@ -22,5 +22,6 @@ module.exports = {
PANDORA_URI: PANDORA_URI[env], PANDORA_URI: PANDORA_URI[env],
GOODS_URI: API_INTERNAL_URI[env], GOODS_URI: API_INTERNAL_URI[env],
GROUPMEAL_URI: API_INTERNAL_URI[env], GROUPMEAL_URI: API_INTERNAL_URI[env],
WITHDRAWAL_URI: API_INTERNAL_URI[env],
API_YD_LOGIN API_YD_LOGIN
}; };
...@@ -5,11 +5,12 @@ const { API_INTERNAL_URI, API_YD_LOGIN } = require("../config.js"); ...@@ -5,11 +5,12 @@ const { API_INTERNAL_URI, API_YD_LOGIN } = require("../config.js");
exports.fetch_user = async (ctx, next) => { exports.fetch_user = async (ctx, next) => {
const url = `${PANDORA_URI}/api/user/getuser`; const url = `${PANDORA_URI}/api/user/getuser`;
const cookie = ctx.request.header.cookie;
console.log('cookie============', cookie)
const opts = { const opts = {
url: url, url: url,
method: "GET", method: "GET",
headers: {
Cookie: ctx.request.header.cookie
}
}; };
ctx.body = await req(ctx, opts); ctx.body = await req(ctx, opts);
}; };
......
...@@ -11,13 +11,10 @@ ...@@ -11,13 +11,10 @@
<el-dropdown-menu> <el-dropdown-menu>
<el-dropdown-item> <el-dropdown-item>
<i class="el-icon-message"></i> <i class="el-icon-message"></i>
{{userInfo.email}} {{ userEmail }}
</el-dropdown-item> </el-dropdown-item>
<el-dropdown-item> <el-dropdown-item @click="$emit('logout')">
<span><a 退出登录
class="link"
href="//pandora.yidian-inc.com/"
>返回pandora工具平台</a></span>
</el-dropdown-item> </el-dropdown-item>
</el-dropdown-menu> </el-dropdown-menu>
</template> </template>
...@@ -27,7 +24,7 @@ ...@@ -27,7 +24,7 @@
<script> <script>
import { mapState } from 'vuex' import { mapState } from 'vuex'
import { HEADER_CONFIG } from '@/config/pageconfig'; import { HEADER_CONFIG } from '@/config/pageconfig';
import { getCookie } from "@/utils/util";
export default { export default {
computed: mapState({ computed: mapState({
userInfo: state => (state.userInfo || {}), userInfo: state => (state.userInfo || {}),
...@@ -36,8 +33,12 @@ export default { ...@@ -36,8 +33,12 @@ export default {
data () { data () {
return { return {
DEFAULT_AVATAR: HEADER_CONFIG.miscellaneous.defaultAvatar, DEFAULT_AVATAR: HEADER_CONFIG.miscellaneous.defaultAvatar,
userEmail: ''
}; };
}, },
mounted() {
this.userEmail = getCookie('username') || ''
}
}; };
</script> </script>
......
...@@ -53,8 +53,11 @@ export default { ...@@ -53,8 +53,11 @@ export default {
...mapActions(['userLogin']), ...mapActions(['userLogin']),
async login () { async login () {
const { email } = this.userInfo; const { email } = this.userInfo;
let validEmail = email.match(/@yidian-inc.com|@linkingcities/);
if (!email) { if (!email) {
return this.$message.warn("请输入用户邮箱"); return this.$message("请输入用户邮箱");
} else if(!validEmail) {
return this.$message("请输入合法邮箱");
} }
this.userInfo.email = email.indexOf("@") === -1 ? email + "@yidian-inc.com" : email; this.userInfo.email = email.indexOf("@") === -1 ? email + "@yidian-inc.com" : email;
const res = await this.userLogin({ payload: this.userInfo }); const res = await this.userLogin({ payload: this.userInfo });
......
...@@ -289,7 +289,7 @@ import { ...@@ -289,7 +289,7 @@ import {
} from "@/service/Withdrawal/withdrawal"; } from "@/service/Withdrawal/withdrawal";
import { ElMessage } from "element-plus"; import { ElMessage } from "element-plus";
import { fetchCurrentUser } from "../../../service/user"; import { fetchCurrentUser } from "../../../service/user";
import { getCookie } from "@/utils/util"; import { getCookie, redirectToLogin } from "@/utils/util";
const TABS = { const TABS = {
pending: "0", pending: "0",
...@@ -355,7 +355,7 @@ export default { ...@@ -355,7 +355,7 @@ export default {
const res = await this.getPermissionsAll(); const res = await this.getPermissionsAll();
if (!res) { if (!res) {
this.$router.push('/op/login'); redirectToLogin();
return this.$message("您没有权限"); return this.$message("您没有权限");
} }
...@@ -365,7 +365,7 @@ export default { ...@@ -365,7 +365,7 @@ export default {
if (withdrawlPermission.length === 0) { if (withdrawlPermission.length === 0) {
// push to forbidden // push to forbidden
this.$router.push('/op/login'); redirectToLogin();
return this.$message("您没有权限"); return this.$message("您没有权限");
} }
console.log("withdrawlPermission", withdrawlPermission); console.log("withdrawlPermission", withdrawlPermission);
...@@ -375,7 +375,7 @@ export default { ...@@ -375,7 +375,7 @@ export default {
({ name }) => name === "show" ({ name }) => name === "show"
); );
if (subpermissions.length === 0) { if (subpermissions.length === 0) {
this.$router.push('/op/login'); redirectToLogin();
return this.$message("您没有权限"); return this.$message("您没有权限");
} }
}, },
......
/* eslint-disable */ /* eslint-disable */
import { yd_login, j_login } from "@/service/user"; import { yd_login, j_login } from "@/service/user";
import { isYdUser, setCookie } from "@/utils/util"; import { isYdUser, setCookie, delCookie,redirectToLogin, getCookie } from "@/utils/util";
import { redirectToLogin, delCookie } from "@/utils/util";
import { ElMessage } from "element-plus"; import { ElMessage } from "element-plus";
// import Cookies from 'js-cookie'
export default { export default {
state: {}, state: {},
...@@ -18,7 +18,8 @@ export default { ...@@ -18,7 +18,8 @@ export default {
} }
let res = flag ? await yd_login(payload) : await j_login(params) let res = flag ? await yd_login(payload) : await j_login(params)
let storage = window.localStorage; let storage = window.localStorage;
if (res.userInfo && !storage['uid']) { if(!getCookie('username')) {
if (res.userInfo && flag) {
storage['YD_PANDORA_auth'] = JSON.stringify(res.auth || {}) storage['YD_PANDORA_auth'] = JSON.stringify(res.auth || {})
storage['YD_PANDORA_JWT_TOKEN'] = (res.type + ' ' + res.token )|| '' storage['YD_PANDORA_JWT_TOKEN'] = (res.type + ' ' + res.token )|| ''
storage['YD_PANDORA_user'] = JSON.stringify(res.userInfo || {}) storage['YD_PANDORA_user'] = JSON.stringify(res.userInfo || {})
...@@ -37,11 +38,18 @@ export default { ...@@ -37,11 +38,18 @@ export default {
} else { } else {
ElMessage.error(res); ElMessage.error(res);
} }
}
}, },
logout() { logout() {
return new Promise((resolve) => { return new Promise((resolve) => {
window.localStorage.clear(); window.localStorage.clear();
delCookie('username'); delCookie('username')
delCookie('uid')
delCookie('YD_PANDORA_JWT_TOKEN')
delCookie('nickname')
delCookie('userid')
delCookie('YD_PANDORA_UID')
// Cookies.remove('username','', { path: 'http://dev.yidian-inc.com' }) // removed!
redirectToLogin() redirectToLogin()
resolve() resolve()
}); });
......
...@@ -33,12 +33,12 @@ export const defaultConfig = { ...@@ -33,12 +33,12 @@ export const defaultConfig = {
*/ */
const getDefaultParams = () => { const getDefaultParams = () => {
return { return {
'op_cur_user': store.state.userInfo && store.state.userInfo.email || getCookie('username'), 'op_cur_user': (store.state.userInfo && store.state.userInfo.email) || getCookie('username'),
'reqid': uuidv1().replace(/-/g, '') 'reqid': uuidv1().replace(/-/g, '')
} }
}; };
const getDefaultHeaders = config => { const getDefaultHeaders = (config) => {
const { method } = config; const { method } = config;
if (method.toLowerCase() === "post") { if (method.toLowerCase() === "post") {
return { return {
......
/* eslint-disable */
import router from "@/router"; import router from "@/router";
// export async function handleUserLogin() { // export async function handleUserLogin() {
// const { status, user } = await fetchCurrentUser(); // const { status, user } = await fetchCurrentUser();
...@@ -22,20 +23,15 @@ import router from "@/router"; ...@@ -22,20 +23,15 @@ import router from "@/router";
export function redirectToLogin() { export function redirectToLogin() {
let hasCallback = window.location.href.match(/\?callback/); let hasCallback = window.location.href.match(/\?callback/);
if(hasCallback) return;
let isLogin = window.location.pathname.match(/op\/login/); let isLogin = window.location.pathname.match(/op\/login/);
const cbUrl = hasCallback && !isLogin ? window.location.search.split('?callback=')[1] : window.location.pathname; router.push(`/op/login${!isLogin ? '?callback=' + window.encodeURIComponent(window.location.pathname) : ''}`)
console.log('cbUrl',cbUrl)
router.push(`/op/login?callback=${window.encodeURI(cbUrl)}`)
} }
export function redirectPage() { export function redirectPage() {
let url = window.location.search.split('?callback=')[1] || window.location.pathname; let url = window.location.search.split('?callback=')[1] || window.location.pathname;
// if(!url) { router.push(window.decodeURIComponent(url))
// router.push('/op/platform')
// } else {
router.push(url)
console.log('redirectUrl', url) console.log('redirectUrl', url)
// }
} }
export function isYdUser(email) { export function isYdUser(email) {
...@@ -66,8 +62,7 @@ export function getCookie(NameOfCookie) { ...@@ -66,8 +62,7 @@ export function getCookie(NameOfCookie) {
export function delCookie(name) { export function delCookie(name) {
var exp = new Date(); var exp = new Date();
exp.setTime(exp.getTime() - 1); exp.setTime(exp.getTime() - 1);
var cval = getCookie(name); var cval=getCookie(name);
if(cval!=null) if(cval!=null)
document.cookie= name + "="+cval+";expires="+exp.toGMTString(); document.cookie= name + "="+cval+";expires="+exp.toGMTString();
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment