소스 검색

update login workflow

pull/342/head
Guillaume Vincent 8 년 전
부모
커밋
1feeb3a584
4개의 변경된 파일26개의 추가작업 그리고 51개의 파일을 삭제
  1. +5
    -5
      src/app/Login.vue
  2. +1
    -1
      src/landing-page/LoginBar/LoginBar.vue
  3. +11
    -11
      src/router.js
  4. +9
    -34
      src/services/auth.js

+ 5
- 5
src/app/Login.vue 파일 보기

@@ -52,12 +52,12 @@
password: this.credentials.password,
};
auth.login(credentials)
.then(() => {
.then((data) => {
console.log('Request succeeded with JSON response', data);
router.go('/app/');
})
.catch(() => {
logging.error(this.$t('login.credentials_invalids'));
});
}).catch((error) => {
console.log('Request failed', error);
});
},
},
};


+ 1
- 1
src/landing-page/LoginBar/LoginBar.vue 파일 보기

@@ -20,7 +20,7 @@
<div class="container">
<nav class="nav nav-inline pull-right">
<a class="nav-link" v-bind:class="{ 'bg-primary': $route.path=='/login/'}"
v-link="{ path: '/login/' }">
v-link="{ path: '/app/' }">
<i class="fa fa-lock"></i> {{ $t('login.login') }}
</a>
<a class="nav-link" v-bind:class="{ 'bg-primary': $route.path=='/register/' || $route.path=='/'}"


+ 11
- 11
src/router.js 파일 보기

@@ -4,8 +4,10 @@ import App from './App';

Vue.use(Router);

const router = new Router();

const router = new Router({
history: true,
hashbang: false,
});

import LandingPage from './landing-page/LandingPage';
import LoginPage from './app/Login';
@@ -14,8 +16,7 @@ import LessPassConnected from './app/Index';

router.map({
'/': {
auth: true,
component: LessPassConnected,
component: LandingPage,
},
'/login/': {
component: LoginPage,
@@ -23,8 +24,9 @@ router.map({
'/register/': {
component: RegisterPage,
},
'/welcome/': {
component: LandingPage,
'/app/': {
auth_required: true,
component: LessPassConnected,
},
});

@@ -39,13 +41,11 @@ import Auth from './services/auth';
Auth.checkAuth();

router.beforeEach(transition => {
alert(transition.to.auth);
if (transition.to.auth && !Auth.user.authenticated) {
alert(Auth.user.authenticated);
transition.redirect('/welcome/');
if (transition.to.auth_required && !Auth.user.authenticated) {
transition.redirect('/login/');
} else {
transition.next();
}
});

module.exports = router;
export default router;

+ 9
- 34
src/services/auth.js 파일 보기

@@ -1,5 +1,3 @@
import logging from './logging';

function checkStatus(response) {
if (response.status >= 200 && response.status < 300) {
return response;
@@ -17,6 +15,7 @@ module.exports = {
user: {
authenticated: false,
},

login(credential) {
return fetch('/api/sessions/', {
method: 'post',
@@ -26,38 +25,12 @@ module.exports = {
},
body: JSON.stringify(credential),
}).then(checkStatus)
.then(parseJSON);
},
login2(context, credentials, callback) {
const self = this;

fetch('/users.html');
context.$http.post('/api/sessions/', credentials).then(
response => {
localStorage.setItem('token', response.data.token);
self.user.authenticated = true;
logging.success(this.$t('login.welcome'));
if (callback) {
callback();
}
},
() => {
logging.error(this.$t('login.credentials_invalids'));
}
);
},

register(context, user, callback) {
context.$http.post('/api/users/', user).then(
() => {
if (callback) {
callback();
}
},
() => {
logging.warning(this.$t('register.beta'));
}
);
.then(parseJSON)
.then((data) => {
localStorage.setItem('token', data.token);
this.user.authenticated = true;
return data;
});
},

logout(callback) {
@@ -69,7 +42,9 @@ module.exports = {
},

checkAuth() {
console.log('check auth');
const jwt = localStorage.getItem('token');
console.log(jwt);
this.user.authenticated = !!jwt;
},



불러오는 중...
취소
저장