session check

This commit is contained in:
HelloWorld 2020-03-17 08:21:31 +08:00
parent 7e78ded5b4
commit f7d99047d4
2 changed files with 13 additions and 5 deletions

View File

@ -7,19 +7,25 @@ function md5(str) {
module.exports = class extends Base {
async __before() {
const user = await this.session('user');
let user = await this.session('user');
user = {}
console.log("session user", user);
//获取用户的 session 信息,如果为空,返回 false 阻止后续的行为继续执行
// if (think.isEmpty(user)) {
// return false;
// }
if (['register', 'login'].indexOf(this.ctx.action) >= 0) {
return;
}
// 获取用户的 session 信息,如果为空,返回 false 阻止后续的行为继续执行
if (think.isEmpty(user)) {
return this.fail('NOT_LOGIN');
}
}
indexAction() {
return this.display();
}
// 注册
async registerAction() {
try {
let post = this.post();
@ -32,6 +38,7 @@ module.exports = class extends Base {
}
}
// 登陆
async loginAction() {
try {
let post = this.post();

View File

@ -39,6 +39,7 @@ app.controller('loginCtr', ['$scope', '$filter', '$state', '$http', '$cookieStor
$cookieStore.put("username", $scope.username);
await axios.post('login', params);
return;
pubSubService.publish('loginCtr.login', { login: true });
$state.go('bookmarks', {})
}