persist avatar_url instead of gravatar_id

This commit is contained in:
Brad Rydzewski 2015-08-02 23:50:08 -07:00
parent 0c68b116ab
commit a3b6759cf9
9 changed files with 29 additions and 15 deletions

View file

@ -3,7 +3,7 @@
<ul>
<li>
<img ng-src="{{ user.gravatar_id | gravatar }}" />
<img ng-src="{{ user.avatar }}" />
</li>
<li ng-init="show=false">
<a href="#" ng-click="show=true">

View file

@ -28,7 +28,7 @@
<ul class="list cozy user-list">
<li class="row row-user" ng-repeat="user in users | orderBy:'login' | filter: search_text">
<div class="column-avatar">
<img ng-src="{{ user.gravatar_id | gravatar }}" />
<img ng-src="{{ user.avatar || 'https://www.gravatar.com/avatar/00000000000000000000000000000000?d=mm&f=y' }}" />
</div>
<div class="column-fill">
<h2>{{ user.login }} <small ng-if="user.admin" class="label label-success">Admin</small></h2>

View file

@ -1,7 +1,7 @@
{
"name": "Octocat",
"email": "octocat@github.com",
"gravatar_id": "7194e8d48fa1d2b689f99443b767316c",
"avatar": "https://www.gravatar.com/avatar/7194e8d48fa1d2b689f99443b767316c",
"admin": false,
"active": true
}

View file

@ -2,7 +2,7 @@
{
"name": "Octocat",
"email": "octocat@github.com",
"gravatar_id": "7194e8d48fa1d2b689f99443b767316c",
"avatar": "https://www.gravatar.com/avatar/7194e8d48fa1d2b689f99443b767316c",
"admin": false,
"active": true
}

View file

@ -769,7 +769,7 @@ definitions:
type: string
email:
type: string
gravatar_id:
avatar:
type: string
admin:
type: boolean

View file

@ -80,6 +80,7 @@ func (g *GitHub) Login(token, secret string) (*common.User, error) {
user.Email = *login.Email
user.Token = token
user.Secret = secret
user.Avatar = *login.AvatarURL
return &user, nil
}

View file

@ -81,7 +81,13 @@ func GetLogin(c *gin.Context) {
u.Token = login.Token
u.Secret = login.Secret
u.Email = login.Email
u.Avatar = gravatar.Hash(u.Email)
u.Avatar = login.Avatar
// TODO: remove this once gitlab implements setting
// avatar in the remote package, similar to github
if len(u.Avatar) == 0 {
u.Avatar = gravatar.Hash(u.Email)
}
// insert the user into the database
if err := store.AddUser(u); err != nil {
@ -102,7 +108,13 @@ func GetLogin(c *gin.Context) {
u.Token = login.Token
u.Secret = login.Secret
u.Email = login.Email
u.Avatar = gravatar.Hash(u.Email)
u.Avatar = login.Avatar
// TODO: remove this once gitlab implements setting
// avatar in the remote package, similar to github
if len(u.Avatar) == 0 {
u.Avatar = gravatar.Hash(u.Email)
}
if err := store.SetUser(u); err != nil {
log.Errorf("cannot update %s. %s", u.Login, err)

View file

@ -31,6 +31,7 @@ func PutUserCurr(c *gin.Context) {
if !c.BindWith(in, binding.JSON) {
return
}
// TODO: we are no longer auto-generating avatar
user.Email = in.Email
user.Avatar = gravatar.Hash(in.Email)
err := store.SetUser(user)

View file

@ -1,12 +1,12 @@
package types
type User struct {
ID int64 `meddler:"user_id,pk" json:"id"`
Login string `meddler:"user_login" json:"login,omitempty" sql:"unique:ux_user_login"`
Token string `meddler:"user_token" json:"-"`
Secret string `meddler:"user_secret" json:"-"`
Email string `meddler:"user_email" json:"email,omitempty"`
Avatar string `meddler:"user_gravatar" json:"gravatar_id,omitempty"`
Active bool `meddler:"user_active" json:"active,omitempty"`
Admin bool `meddler:"user_admin" json:"admin,omitempty"`
ID int64 `json:"id"`
Login string `json:"login,omitempty" sql:"unique:ux_user_login"`
Token string `json:"-"`
Secret string `json:"-"`
Email string `json:"email,omitempty"`
Avatar string `json:"avatar,omitempty"`
Active bool `json:"active,omitempty"`
Admin bool `json:"admin,omitempty"`
}