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

View file

@ -28,7 +28,7 @@
<ul class="list cozy user-list"> <ul class="list cozy user-list">
<li class="row row-user" ng-repeat="user in users | orderBy:'login' | filter: search_text"> <li class="row row-user" ng-repeat="user in users | orderBy:'login' | filter: search_text">
<div class="column-avatar"> <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>
<div class="column-fill"> <div class="column-fill">
<h2>{{ user.login }} <small ng-if="user.admin" class="label label-success">Admin</small></h2> <h2>{{ user.login }} <small ng-if="user.admin" class="label label-success">Admin</small></h2>

View file

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

View file

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

View file

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

View file

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

View file

@ -81,7 +81,13 @@ func GetLogin(c *gin.Context) {
u.Token = login.Token u.Token = login.Token
u.Secret = login.Secret u.Secret = login.Secret
u.Email = login.Email u.Email = login.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) u.Avatar = gravatar.Hash(u.Email)
}
// insert the user into the database // insert the user into the database
if err := store.AddUser(u); err != nil { if err := store.AddUser(u); err != nil {
@ -102,7 +108,13 @@ func GetLogin(c *gin.Context) {
u.Token = login.Token u.Token = login.Token
u.Secret = login.Secret u.Secret = login.Secret
u.Email = login.Email u.Email = login.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) u.Avatar = gravatar.Hash(u.Email)
}
if err := store.SetUser(u); err != nil { if err := store.SetUser(u); err != nil {
log.Errorf("cannot update %s. %s", u.Login, err) 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) { if !c.BindWith(in, binding.JSON) {
return return
} }
// TODO: we are no longer auto-generating avatar
user.Email = in.Email user.Email = in.Email
user.Avatar = gravatar.Hash(in.Email) user.Avatar = gravatar.Hash(in.Email)
err := store.SetUser(user) err := store.SetUser(user)

View file

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