Skip to content

Commit

Permalink
Added login, miss error display #5
Browse files Browse the repository at this point in the history
  • Loading branch information
rudmanmrrod committed Jul 7, 2019
1 parent b40f882 commit c84e5c3
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 15 deletions.
12 changes: 2 additions & 10 deletions frontend/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,8 @@
<v-toolbar app>
<v-toolbar-title class="headline text-uppercase">
<span>Vuetify</span>
<span class="font-weight-light">MATERIAL DESIGN</span>
<span class="font-weight-light">Watchin SGE</span>
</v-toolbar-title>
<v-spacer></v-spacer>
<v-btn
flat
href="https://github.com/vuetifyjs/vuetify/releases/latest"
target="_blank"
>
<span class="mr-2">Latest Release</span>
</v-btn>
</v-toolbar>

<v-content>
Expand All @@ -26,7 +18,7 @@ export default {
name: 'App',
mounted(){
if(this.$store.state.users.user){
console.log("user here")
this.$router.push('/')
}
else{
this.$router.push('/login')
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/components/Dashboard/Dashboard.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<template>
<h1>Dashboard</h1>
</template>
11 changes: 9 additions & 2 deletions frontend/src/components/UserManagement/Login.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export default{
data(){
return {
user:{
email:'',
username:'',
password:''
}
}
Expand All @@ -12,7 +12,14 @@ export default{
if(this.$validator.validateAll()){
this.$validator.validate().then( result => {
if (result){
console.log("valid!")
this.$axios.post(this.$store.getters.getLogin, this.user)
.then( response => {
this.$store.dispatch('login',response.data)
this.$router.push('/')
})
.catch(error => {
console.log(error)
})
}
})
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/UserManagement/Login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<h1>Login</h1><hr>
<v-flex xs12>
<v-text-field
v-model="user.email"
v-model="user.username"
name="username"
v-validate="'required'"
:error-messages="errors.collect('username')"
Expand Down
6 changes: 6 additions & 0 deletions frontend/src/router.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
import Vue from 'vue'
import Router from 'vue-router'
import Login from './components/UserManagement/Login.vue'
import Dashboard from './components/Dashboard/Dashboard.vue'

Vue.use(Router)

export default new Router({
mode: 'history',
base: process.env.BASE_URL,
routes: [
{
path:'/',
name:'dashboard',
component: Dashboard
},
{
path:'/login',
name:'login',
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/store.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import Vue from 'vue'
import Vuex from 'vuex'
import users from './store/users.js'
import routes from './store/backroutes.js'

Vue.use(Vuex)

export default new Vuex.Store({
modules: {
route: routes,
users: users
},
state: {
Expand Down
10 changes: 10 additions & 0 deletions frontend/src/store/backroutes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export default{
state:{
baseUrl: 'http:https://localhost:8000/'
},
getters:{
getLogin(state){
return state.baseUrl + 'api/auth/jwt/create/'
}
}
}
8 changes: 6 additions & 2 deletions frontend/src/store/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@ export default{
user: localStorage.getItem('user')
},
mutations: {

['LOGIN'] (state,payload){
state.user = payload
}
},
actions: {

login({commit},token){
commit('LOGIN',token)
}
}
}

0 comments on commit c84e5c3

Please sign in to comment.