Added gravatar
This commit is contained in:
parent
5f6a7a992e
commit
9dba174ceb
|
@ -7,6 +7,7 @@
|
|||
<router-link to="/authors" class="item">Authors</router-link>
|
||||
<router-link to="/publishers" class="item">Publishers</router-link>
|
||||
<div class="right menu">
|
||||
<img v-bind:src="gravatar" class="menu-avatar"/>
|
||||
<a class="ui item" @click="logout()">
|
||||
Logout
|
||||
</a>
|
||||
|
@ -26,7 +27,8 @@ export default {
|
|||
name: 'app',
|
||||
data () {
|
||||
return {
|
||||
user: auth.user
|
||||
user: auth.user,
|
||||
gravatar: ''
|
||||
}
|
||||
},
|
||||
created () {
|
||||
|
@ -35,6 +37,9 @@ export default {
|
|||
this.logout()
|
||||
router.push({ name: 'login' })
|
||||
}
|
||||
|
||||
let user = auth.getUserInfos()
|
||||
this.gravatar = 'https://www.gravatar.com/avatar/' + user.avatar + '?s=40'
|
||||
},
|
||||
methods: {
|
||||
logout () {
|
||||
|
@ -52,4 +57,10 @@ export default {
|
|||
#app{
|
||||
margin: 2em 1em;
|
||||
}
|
||||
|
||||
.menu-avatar{
|
||||
-webkit-border-radius: 3px;
|
||||
-moz-border-radius: 3px;
|
||||
border-radius: 3px;
|
||||
}
|
||||
</style>
|
||||
|
|
|
@ -6,7 +6,8 @@ import router from '../router'
|
|||
export default {
|
||||
|
||||
user: {
|
||||
authenticated: false
|
||||
authenticated: false,
|
||||
infos: {}
|
||||
},
|
||||
|
||||
login (context, creds, redirect) {
|
||||
|
@ -48,14 +49,23 @@ export default {
|
|||
let jwt = localStorage.getItem('token')
|
||||
this.user.authenticated = false
|
||||
if (jwt) {
|
||||
let jwtinfos = this.parseJwt(jwt)
|
||||
let infos = this.getUserInfos()
|
||||
let ts = Math.round((new Date()).getTime() / 1000)
|
||||
if (jwtinfos.exp >= ts) {
|
||||
if (infos.exp >= ts) {
|
||||
this.user.authenticated = true
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
getUserInfos () {
|
||||
let jwt = localStorage.getItem('token')
|
||||
if (jwt) {
|
||||
return this.parseJwt(localStorage.getItem('token'))
|
||||
} else {
|
||||
return {}
|
||||
}
|
||||
},
|
||||
|
||||
parseJwt (token) {
|
||||
let base64Url = token.split('.')[1]
|
||||
let base64 = base64Url.replace('-', '+').replace('_', '/')
|
||||
|
|
|
@ -6,6 +6,8 @@ import (
|
|||
"github.com/labstack/echo"
|
||||
"net/http"
|
||||
"time"
|
||||
"crypto/md5"
|
||||
"encoding/hex"
|
||||
)
|
||||
|
||||
// Login is the login handler
|
||||
|
@ -33,6 +35,9 @@ func Login(c echo.Context) error {
|
|||
claims["id"] = user.ID
|
||||
claims["exp"] = time.Now().Add(time.Hour * 72).Unix()
|
||||
|
||||
avatar := md5.Sum([]byte(user.Email))
|
||||
claims["avatar"] = hex.EncodeToString(avatar[:])
|
||||
|
||||
// Generate encoded token and send it as response.
|
||||
t, err := token.SignedString(models.Config.JWTLoginSecret)
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in New Issue