Fixed gravatar

+ Login improvements
This commit is contained in:
konrad 2017-11-20 16:14:44 +01:00 committed by kolaente
parent 02e443b769
commit d577f0e425
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
4 changed files with 27 additions and 14 deletions

View File

@ -8,8 +8,9 @@
<router-link to="/publishers" class="item">Publishers</router-link> <router-link to="/publishers" class="item">Publishers</router-link>
<div class="right menu"> <div class="right menu">
<img v-bind:src="gravatar" class="menu-avatar"/> <img v-bind:src="gravatar" class="menu-avatar"/>
<div class="ui item"> {{ user.infos.username }}</div>
<a class="ui item" @click="logout()"> <a class="ui item" @click="logout()">
Logout <icon name="sign-out"></icon>
</a> </a>
</div> </div>
</div> </div>
@ -38,12 +39,20 @@ export default {
router.push({ name: 'login' }) router.push({ name: 'login' })
} }
let user = auth.getUserInfos() // Set the users avatar
this.gravatar = 'https://www.gravatar.com/avatar/' + user.avatar + '?s=40' this.setAvatar()
},
watch: {
// call again the method if the route changes
'$route': 'setAvatar'
}, },
methods: { methods: {
logout () { logout () {
auth.logout() auth.logout()
},
setAvatar () {
auth.getUserInfos()
this.gravatar = 'https://www.gravatar.com/avatar/' + this.user.infos.avatar + '?s=40&d=mm'
} }
} }
} }

View File

@ -21,6 +21,7 @@ export default {
// Tell others the user is autheticated // Tell others the user is autheticated
this.user.authenticated = true this.user.authenticated = true
this.getUserInfos()
// Hide the loader // Hide the loader
context.loading = false context.loading = false
@ -47,9 +48,10 @@ export default {
checkAuth () { checkAuth () {
let jwt = localStorage.getItem('token') let jwt = localStorage.getItem('token')
this.getUserInfos()
this.user.authenticated = false this.user.authenticated = false
if (jwt) { if (jwt) {
let infos = this.getUserInfos() let infos = this.user.infos
let ts = Math.round((new Date()).getTime() / 1000) let ts = Math.round((new Date()).getTime() / 1000)
if (infos.exp >= ts) { if (infos.exp >= ts) {
this.user.authenticated = true this.user.authenticated = true
@ -60,6 +62,7 @@ export default {
getUserInfos () { getUserInfos () {
let jwt = localStorage.getItem('token') let jwt = localStorage.getItem('token')
if (jwt) { if (jwt) {
this.user.infos = this.parseJwt(localStorage.getItem('token'))
return this.parseJwt(localStorage.getItem('token')) return this.parseJwt(localStorage.getItem('token'))
} else { } else {
return {} return {}

View File

@ -11,13 +11,13 @@
<div class="field"> <div class="field">
<div class="ui left icon input"> <div class="ui left icon input">
<i class="user icon"></i> <i class="user icon"></i>
<input type="text" name="username" placeholder="Username" v-model="credentials.username"> <input v-focus type="text" name="username" placeholder="Username" v-model="credentials.username">
</div> </div>
</div> </div>
<div class="field"> <div class="field">
<div class="ui left icon input"> <div class="ui left icon input">
<i class="lock icon"></i> <i class="lock icon"></i>
<input type="password" name="password" placeholder="Password" v-model="credentials.password"> <input type="password" name="password" placeholder="Password" v-model="credentials.password" @keyup.enter="submit">
</div> </div>
</div> </div>
<div class="ui fluid large blue submit button" @click="submit()">Login</div> <div class="ui fluid large blue submit button" @click="submit()">Login</div>
@ -78,6 +78,7 @@
<style scoped> <style scoped>
body { body {
background-color: #efefef; background-color: #efefef;
margin-top: -1em;
} }
body > .grid { body > .grid {
height: 100%; height: 100%;

View File

@ -42,14 +42,14 @@ Vue.component('modal', Modal)
// Paginate setup // Paginate setup
Vue.use(VuePaginate) Vue.use(VuePaginate)
/* // Globally set focus
webpack.ProvidePlugin({ Vue.directive('focus', {
// jquery // When the bound element is inserted into the DOM...
$: 'jquery', inserted: function (el) {
jQuery: 'jquery', // Focus the element
// semantic-ui el.focus()
semantic: 'semantic-ui-css' }
}) */ })
/* eslint-disable no-new */ /* eslint-disable no-new */
new Vue({ new Vue({