using gravatar library instead of our own built-in func

This commit is contained in:
Brad Rydzewski 2015-04-16 00:31:17 -07:00
parent 433159e990
commit 110af2a196
4 changed files with 7 additions and 23 deletions

View File

@ -1,16 +0,0 @@
package gravatar
import (
"crypto/md5"
"fmt"
"strings"
)
// helper function to create a Gravatar Hash
// for the given Email address.
func Generate(email string) string {
email = strings.ToLower(strings.TrimSpace(email))
hash := md5.New()
hash.Write([]byte(email))
return fmt.Sprintf("%x", hash.Sum(nil))
}

View File

@ -6,10 +6,10 @@ import (
"time" "time"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/ungerik/go-gravatar"
log "github.com/Sirupsen/logrus" log "github.com/Sirupsen/logrus"
"github.com/drone/drone/common" "github.com/drone/drone/common"
"github.com/drone/drone/common/gravatar"
"github.com/drone/drone/common/httputil" "github.com/drone/drone/common/httputil"
"github.com/drone/drone/common/oauth2" "github.com/drone/drone/common/oauth2"
) )
@ -87,7 +87,7 @@ func GetLogin(c *gin.Context) {
u.Secret = login.Secret u.Secret = login.Secret
u.Name = login.Name u.Name = login.Name
u.Email = login.Email u.Email = login.Email
u.Gravatar = gravatar.Generate(u.Email) u.Gravatar = gravatar.Hash(u.Email)
// insert the user into the database // insert the user into the database
if err := store.SetUserNotExists(u); err != nil { if err := store.SetUserNotExists(u); err != nil {
@ -109,7 +109,7 @@ func GetLogin(c *gin.Context) {
u.Secret = login.Secret u.Secret = login.Secret
u.Name = login.Name u.Name = login.Name
u.Email = login.Email u.Email = login.Email
u.Gravatar = gravatar.Generate(u.Email) u.Gravatar = 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

@ -3,9 +3,9 @@ package server
import ( import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/gin-gonic/gin/binding" "github.com/gin-gonic/gin/binding"
"github.com/ungerik/go-gravatar"
"github.com/drone/drone/common" "github.com/drone/drone/common"
"github.com/drone/drone/common/gravatar"
) )
// GetUserCurr accepts a request to retrieve the // GetUserCurr accepts a request to retrieve the
@ -32,7 +32,7 @@ func PutUserCurr(c *gin.Context) {
return return
} }
user.Email = in.Email user.Email = in.Email
user.Gravatar = gravatar.Generate(in.Email) user.Gravatar = gravatar.Hash(in.Email)
err := store.SetUser(user) err := store.SetUser(user)
if err != nil { if err != nil {
c.Fail(400, err) c.Fail(400, err)

View File

@ -3,9 +3,9 @@ package server
import ( import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/gin-gonic/gin/binding" "github.com/gin-gonic/gin/binding"
"github.com/ungerik/go-gravatar"
"github.com/drone/drone/common" "github.com/drone/drone/common"
"github.com/drone/drone/common/gravatar"
) )
// GetUsers accepts a request to retrieve all users // GetUsers accepts a request to retrieve all users
@ -80,7 +80,7 @@ func PutUser(c *gin.Context) {
return return
} }
user.Email = in.Email user.Email = in.Email
user.Gravatar = gravatar.Generate(user.Email) user.Gravatar = gravatar.Hash(user.Email)
// an administrator must not be able to // an administrator must not be able to
// downgrade her own account. // downgrade her own account.