From 110af2a1961a91cb17c70046f4dac6d3cc9cecca Mon Sep 17 00:00:00 2001 From: Brad Rydzewski Date: Thu, 16 Apr 2015 00:31:17 -0700 Subject: [PATCH] using gravatar library instead of our own built-in func --- common/gravatar/gravatar.go | 16 ---------------- server/login.go | 6 +++--- server/user.go | 4 ++-- server/users.go | 4 ++-- 4 files changed, 7 insertions(+), 23 deletions(-) delete mode 100644 common/gravatar/gravatar.go diff --git a/common/gravatar/gravatar.go b/common/gravatar/gravatar.go deleted file mode 100644 index e13666dad..000000000 --- a/common/gravatar/gravatar.go +++ /dev/null @@ -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)) -} diff --git a/server/login.go b/server/login.go index d804092f4..af4e1c283 100644 --- a/server/login.go +++ b/server/login.go @@ -6,10 +6,10 @@ import ( "time" "github.com/gin-gonic/gin" + "github.com/ungerik/go-gravatar" log "github.com/Sirupsen/logrus" "github.com/drone/drone/common" - "github.com/drone/drone/common/gravatar" "github.com/drone/drone/common/httputil" "github.com/drone/drone/common/oauth2" ) @@ -87,7 +87,7 @@ func GetLogin(c *gin.Context) { u.Secret = login.Secret u.Name = login.Name u.Email = login.Email - u.Gravatar = gravatar.Generate(u.Email) + u.Gravatar = gravatar.Hash(u.Email) // insert the user into the database if err := store.SetUserNotExists(u); err != nil { @@ -109,7 +109,7 @@ func GetLogin(c *gin.Context) { u.Secret = login.Secret u.Name = login.Name u.Email = login.Email - u.Gravatar = gravatar.Generate(u.Email) + u.Gravatar = gravatar.Hash(u.Email) if err := store.SetUser(u); err != nil { log.Errorf("cannot update %s. %s", u.Login, err) diff --git a/server/user.go b/server/user.go index 02aee3132..607b8f461 100644 --- a/server/user.go +++ b/server/user.go @@ -3,9 +3,9 @@ package server import ( "github.com/gin-gonic/gin" "github.com/gin-gonic/gin/binding" + "github.com/ungerik/go-gravatar" "github.com/drone/drone/common" - "github.com/drone/drone/common/gravatar" ) // GetUserCurr accepts a request to retrieve the @@ -32,7 +32,7 @@ func PutUserCurr(c *gin.Context) { return } user.Email = in.Email - user.Gravatar = gravatar.Generate(in.Email) + user.Gravatar = gravatar.Hash(in.Email) err := store.SetUser(user) if err != nil { c.Fail(400, err) diff --git a/server/users.go b/server/users.go index 18b2bac02..72adaae1f 100644 --- a/server/users.go +++ b/server/users.go @@ -3,9 +3,9 @@ package server import ( "github.com/gin-gonic/gin" "github.com/gin-gonic/gin/binding" + "github.com/ungerik/go-gravatar" "github.com/drone/drone/common" - "github.com/drone/drone/common/gravatar" ) // GetUsers accepts a request to retrieve all users @@ -80,7 +80,7 @@ func PutUser(c *gin.Context) { return } user.Email = in.Email - user.Gravatar = gravatar.Generate(user.Email) + user.Gravatar = gravatar.Hash(user.Email) // an administrator must not be able to // downgrade her own account.