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

View File

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