Browse Source

Gravatar user profile icon in menu

Vova Tkach 6 years ago
parent
commit
b52c0a7bf1

+ 20 - 18
engine/backend/backend.go

@@ -19,15 +19,16 @@ type Backend struct {
 }
 
 type TmplData struct {
-	Title         string
-	UserId        int
-	UserFirstName string
-	UserLastName  string
-	UserEmail     string
-	UserPassword  string
-	SidebarLeft   template.HTML
-	Content       template.HTML
-	SidebarRight  template.HTML
+	Title          string
+	UserId         int
+	UserFirstName  string
+	UserLastName   string
+	UserEmail      string
+	UserPassword   string
+	UserAvatarLink string
+	SidebarLeft    template.HTML
+	Content        template.HTML
+	SidebarRight   template.HTML
 }
 
 func New(wrapper *wrapper.Wrapper, db *sql.DB) *Backend {
@@ -117,15 +118,16 @@ func (this *Backend) Run() bool {
 	page := this.wrapper.TmplParseToString(templates.CpBase, wrapper.TmplDataAll{
 		System: this.wrapper.TmplGetSystemData(),
 		Data: TmplData{
-			Title:         "Fave " + constants.ServerVersion,
-			UserId:        this.user.A_id,
-			UserFirstName: this.user.A_first_name,
-			UserLastName:  this.user.A_last_name,
-			UserEmail:     this.user.A_email,
-			UserPassword:  "",
-			SidebarLeft:   template.HTML(sidebar_left),
-			Content:       template.HTML("Content"),
-			SidebarRight:  template.HTML("Sidebar right"),
+			Title:          "Fave " + constants.ServerVersion,
+			UserId:         this.user.A_id,
+			UserFirstName:  this.user.A_first_name,
+			UserLastName:   this.user.A_last_name,
+			UserEmail:      this.user.A_email,
+			UserPassword:   "",
+			UserAvatarLink: "https://s.gravatar.com/avatar/" + utils.GetMd5(this.user.A_email) + "?s=80&r=g",
+			SidebarLeft:    template.HTML(sidebar_left),
+			Content:        template.HTML("Content"),
+			SidebarRight:   template.HTML("Sidebar right"),
 		},
 	})
 	(*this.wrapper.W).Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")

File diff suppressed because it is too large
+ 0 - 0
engine/wrapper/resources/templates/cp.base.go


+ 1 - 1
engine/wrapper/resources/templates/cp.base.html

@@ -77,7 +77,7 @@
 				<ul class="navbar-nav ml-auto">
 					<li class="nav-item dropdown">
 						<a class="nav-link dropdown-toggle" href="javascript:;" id="nbAccountDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
-							<img class="rounded-circle" src="data:image/gif;base64,R0lGODlhAQABAIAAAHd3dwAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==">{{$.Data.UserEmail}}
+							<img class="rounded-circle" src="{{$.Data.UserAvatarLink}}">{{$.Data.UserEmail}}
 						</a>
 						<div class="dropdown-menu dropdown-menu-right" aria-labelledby="nbAccountDropdown">
 							<a class="dropdown-item" href="javascript:;" data-toggle="modal" data-target="#sys-modal-user-settings">Settings</a>

+ 8 - 0
engine/wrapper/utils/utils.go

@@ -1,6 +1,8 @@
 package utils
 
 import (
+	"crypto/md5"
+	"encoding/hex"
 	"regexp"
 )
 
@@ -8,3 +10,9 @@ func EmailIsValid(email string) bool {
 	regexpe := regexp.MustCompile(`^[a-z0-9._%+\-]+@[a-z0-9.\-]+\.[a-z]{2,4}$`)
 	return regexpe.MatchString(email)
 }
+
+func GetMd5(str string) string {
+	hasher := md5.New()
+	hasher.Write([]byte(str))
+	return hex.EncodeToString(hasher.Sum(nil))
+}

Some files were not shown because too many files changed in this diff