support set gravatar as user avatar provider
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
package utils
|
||||
|
||||
import "fmt"
|
||||
|
||||
const gravatarUrlFormat = "https://www.gravatar.com/avatar/%s"
|
||||
|
||||
// GetGravatarUrl returns the Gravatar url according to the specified user email address
|
||||
func GetGravatarUrl(email string) string {
|
||||
emailMd5 := MD5EncodeToString([]byte(email))
|
||||
return fmt.Sprintf(gravatarUrlFormat, emailMd5)
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"crypto/rand"
|
||||
"crypto/sha256"
|
||||
"encoding/base64"
|
||||
"encoding/hex"
|
||||
"strings"
|
||||
"unicode"
|
||||
|
||||
@@ -133,6 +134,12 @@ func MD5Encode(data []byte) []byte {
|
||||
return m.Sum(nil)
|
||||
}
|
||||
|
||||
// MD5EncodeToString returns a hashed string by md5
|
||||
func MD5EncodeToString(data []byte) string {
|
||||
hash := MD5Encode(data)
|
||||
return hex.EncodeToString(hash)
|
||||
}
|
||||
|
||||
// AESGCMEncrypt returns a encrypted string by aes-gcm
|
||||
func AESGCMEncrypt(key []byte, plainText []byte) ([]byte, error) {
|
||||
block, err := aes.NewCipher(key)
|
||||
|
||||
Reference in New Issue
Block a user