Commit f603c787 authored by liwenhong's avatar liwenhong

add:login

parent 2edd304f
......@@ -22,5 +22,6 @@ module.exports = {
PANDORA_URI: PANDORA_URI[env],
GOODS_URI: API_INTERNAL_URI[env],
GROUPMEAL_URI: API_INTERNAL_URI[env],
WITHDRAWAL_URI: API_INTERNAL_URI[env],
API_YD_LOGIN
};
......@@ -5,11 +5,12 @@ const { API_INTERNAL_URI, API_YD_LOGIN } = require("../config.js");
exports.fetch_user = async (ctx, next) => {
const url = `${PANDORA_URI}/api/user/getuser`;
const cookie = ctx.request.header.cookie;
console.log('cookie============', cookie)
const opts = {
url: url,
method: "GET",
headers: {
Cookie: ctx.request.header.cookie
}
};
ctx.body = await req(ctx, opts);
};
......
......@@ -8,16 +8,13 @@
<span class="user-name">{{userInfo.name}}</span>
</div>
<template #dropdown>
<el-dropdown-menu>
<el-dropdown-menu>
<el-dropdown-item>
<i class="el-icon-message"></i>
{{userInfo.email}}
{{ userEmail }}
</el-dropdown-item>
<el-dropdown-item>
<span><a
class="link"
href="//pandora.yidian-inc.com/"
>返回pandora工具平台</a></span>
<el-dropdown-item @click="$emit('logout')">
退出登录
</el-dropdown-item>
</el-dropdown-menu>
</template>
......@@ -27,7 +24,7 @@
<script>
import { mapState } from 'vuex'
import { HEADER_CONFIG } from '@/config/pageconfig';
import { getCookie } from "@/utils/util";
export default {
computed: mapState({
userInfo: state => (state.userInfo || {}),
......@@ -36,8 +33,12 @@ export default {
data () {
return {
DEFAULT_AVATAR: HEADER_CONFIG.miscellaneous.defaultAvatar,
userEmail: ''
};
},
mounted() {
this.userEmail = getCookie('username') || ''
}
};
</script>
......
......@@ -53,8 +53,11 @@ export default {
...mapActions(['userLogin']),
async login () {
const { email } = this.userInfo;
let validEmail = email.match(/@yidian-inc.com|@linkingcities/);
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;
const res = await this.userLogin({ payload: this.userInfo });
......
......@@ -289,7 +289,7 @@ import {
} from "@/service/Withdrawal/withdrawal";
import { ElMessage } from "element-plus";
import { fetchCurrentUser } from "../../../service/user";
import { getCookie } from "@/utils/util";
import { getCookie, redirectToLogin } from "@/utils/util";
const TABS = {
pending: "0",
......@@ -355,7 +355,7 @@ export default {
const res = await this.getPermissionsAll();
if (!res) {
this.$router.push('/op/login');
redirectToLogin();
return this.$message("您没有权限");
}
......@@ -365,7 +365,7 @@ export default {
if (withdrawlPermission.length === 0) {
// push to forbidden
this.$router.push('/op/login');
redirectToLogin();
return this.$message("您没有权限");
}
console.log("withdrawlPermission", withdrawlPermission);
......@@ -375,7 +375,7 @@ export default {
({ name }) => name === "show"
);
if (subpermissions.length === 0) {
this.$router.push('/op/login');
redirectToLogin();
return this.$message("您没有权限");
}
},
......
/* eslint-disable */
import { yd_login, j_login } from "@/service/user";
import { isYdUser, setCookie } from "@/utils/util";
import { redirectToLogin, delCookie } from "@/utils/util";
import { isYdUser, setCookie, delCookie,redirectToLogin, getCookie } from "@/utils/util";
import { ElMessage } from "element-plus";
// import Cookies from 'js-cookie'
export default {
state: {},
......@@ -18,30 +18,38 @@ export default {
}
let res = flag ? await yd_login(payload) : await j_login(params)
let storage = window.localStorage;
if (res.userInfo && !storage['uid']) {
storage['YD_PANDORA_auth'] = JSON.stringify(res.auth || {})
storage['YD_PANDORA_JWT_TOKEN'] = (res.type + ' ' + res.token )|| ''
storage['YD_PANDORA_user'] = JSON.stringify(res.userInfo || {})
setCookie('uid', res.userInfo && res.userInfo.id, 16)
setCookie('YD_PANDORA_UID', res.userInfo && res.userInfo.id, 16)
setCookie('userid', res.userInfo && res.userInfo.id, 16)
setCookie('username', res.userInfo && res.userInfo.email, 16)
setCookie('nickname', res.userInfo && res.userInfo.displayName, 16)
setCookie('YD_PANDORA_JWT_TOKEN', (res.type + ' ' + res.token )|| '', 16)
storage['isDefault'] = 1;
return true
} else if(+res.code === 0){
storage['isDefault'] = 2;
setCookie('username', payload.email, 16);
return true
} else {
ElMessage.error(res);
if(!getCookie('username')) {
if (res.userInfo && flag) {
storage['YD_PANDORA_auth'] = JSON.stringify(res.auth || {})
storage['YD_PANDORA_JWT_TOKEN'] = (res.type + ' ' + res.token )|| ''
storage['YD_PANDORA_user'] = JSON.stringify(res.userInfo || {})
setCookie('uid', res.userInfo && res.userInfo.id, 16)
setCookie('YD_PANDORA_UID', res.userInfo && res.userInfo.id, 16)
setCookie('userid', res.userInfo && res.userInfo.id, 16)
setCookie('username', res.userInfo && res.userInfo.email, 16)
setCookie('nickname', res.userInfo && res.userInfo.displayName, 16)
setCookie('YD_PANDORA_JWT_TOKEN', (res.type + ' ' + res.token )|| '', 16)
storage['isDefault'] = 1;
return true
} else if(+res.code === 0){
storage['isDefault'] = 2;
setCookie('username', payload.email, 16);
return true
} else {
ElMessage.error(res);
}
}
},
logout() {
return new Promise((resolve) => {
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()
resolve()
});
......
......@@ -33,12 +33,12 @@ export const defaultConfig = {
*/
const getDefaultParams = () => {
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, '')
}
};
const getDefaultHeaders = config => {
const getDefaultHeaders = (config) => {
const { method } = config;
if (method.toLowerCase() === "post") {
return {
......
/* eslint-disable */
import router from "@/router";
// export async function handleUserLogin() {
// const { status, user } = await fetchCurrentUser();
......@@ -22,23 +23,18 @@ import router from "@/router";
export function redirectToLogin() {
let hasCallback = window.location.href.match(/\?callback/);
if(hasCallback) return;
let isLogin = window.location.pathname.match(/op\/login/);
const cbUrl = hasCallback && !isLogin ? window.location.search.split('?callback=')[1] : window.location.pathname;
console.log('cbUrl',cbUrl)
router.push(`/op/login?callback=${window.encodeURI(cbUrl)}`)
router.push(`/op/login${!isLogin ? '?callback=' + window.encodeURIComponent(window.location.pathname) : ''}`)
}
export function redirectPage() {
let url = window.location.search.split('?callback=')[1] || window.location.pathname;
// if(!url) {
// router.push('/op/platform')
// } else {
router.push(url)
router.push(window.decodeURIComponent(url))
console.log('redirectUrl', url)
// }
}
export function isYdUser(email) {
export function isYdUser(email) {
return email.match(/yidian-inc/) || false
}
......@@ -63,11 +59,10 @@ export function getCookie(NameOfCookie) {
return null;
}
export function delCookie(name) {
var exp = new Date();
exp.setTime(exp.getTime() - 1);
var cval = getCookie(name);
if(cval!=null)
document.cookie= name + "="+cval+";expires="+exp.toGMTString();
}
export function delCookie(name) {
var exp = new Date();
exp.setTime(exp.getTime() - 1);
var cval=getCookie(name);
if(cval!=null)
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