mirror of
https://github.com/thomiceli/opengist.git
synced 2025-06-12 13:37:13 +02:00
Add avatars to HTML
This commit is contained in:
@ -32,8 +32,6 @@ func emailProcess(ctx echo.Context) error {
|
||||
email := ctx.FormValue("email")
|
||||
var hash string
|
||||
|
||||
fmt.Println()
|
||||
|
||||
if email == "" {
|
||||
// generate random md5 string
|
||||
hash = fmt.Sprintf("%x", md5.Sum([]byte(time.Now().String())))
|
||||
|
@ -71,7 +71,8 @@ func gistInit(next echo.HandlerFunc) echo.HandlerFunc {
|
||||
|
||||
func allGists(ctx echo.Context) error {
|
||||
var err error
|
||||
fromUser := ctx.Param("user")
|
||||
fromUserStr := ctx.Param("user")
|
||||
|
||||
userLogged := getUserLogged(ctx)
|
||||
|
||||
pageInt := getPage(ctx)
|
||||
@ -99,30 +100,30 @@ func allGists(ctx echo.Context) error {
|
||||
} else {
|
||||
currentUserId = 0
|
||||
}
|
||||
if fromUser == "" {
|
||||
if fromUserStr == "" {
|
||||
setData(ctx, "htmlTitle", "All gists")
|
||||
fromUser = "all"
|
||||
fromUserStr = "all"
|
||||
gists, err = models.GetAllGistsForCurrentUser(currentUserId, pageInt-1, sort, order)
|
||||
} else {
|
||||
setData(ctx, "htmlTitle", "All gists from "+fromUser)
|
||||
setData(ctx, "fromUser", fromUser)
|
||||
setData(ctx, "htmlTitle", "All gists from "+fromUserStr)
|
||||
|
||||
var exists bool
|
||||
if exists, err = models.UserExists(fromUser); err != nil {
|
||||
fromUser, err := models.GetUserByUsername(fromUserStr)
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return notFound("User not found")
|
||||
}
|
||||
return errorRes(500, "Error fetching user", err)
|
||||
}
|
||||
setData(ctx, "fromUser", fromUser)
|
||||
|
||||
if !exists {
|
||||
return notFound("User not found")
|
||||
}
|
||||
|
||||
gists, err = models.GetAllGistsFromUser(fromUser, currentUserId, pageInt-1, sort, order)
|
||||
gists, err = models.GetAllGistsFromUser(fromUserStr, currentUserId, pageInt-1, sort, order)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return errorRes(500, "Error fetching gists", err)
|
||||
}
|
||||
|
||||
if err = paginate(ctx, gists, pageInt, 10, "gists", fromUser, 2, "&sort="+sort+"&order="+order); err != nil {
|
||||
if err = paginate(ctx, gists, pageInt, 10, "gists", fromUserStr, 2, "&sort="+sort+"&order="+order); err != nil {
|
||||
return errorRes(404, "Page not found", nil)
|
||||
}
|
||||
|
||||
|
@ -2,6 +2,7 @@ package web
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/md5"
|
||||
"fmt"
|
||||
"github.com/gorilla/sessions"
|
||||
"github.com/labstack/echo/v4"
|
||||
@ -100,8 +101,11 @@ func Start() {
|
||||
"slug": func(s string) string {
|
||||
return strings.Trim(re.ReplaceAllString(strings.ToLower(s), "-"), "-")
|
||||
},
|
||||
"avatarUrl": func(user *models.User) string {
|
||||
return "https://www.gravatar.com/avatar/" + user.MD5Hash + "?d=identicon&s=200"
|
||||
"avatarUrl": func(userHash string) string {
|
||||
return "https://www.gravatar.com/avatar/" + userHash + "?d=identicon&s=200"
|
||||
},
|
||||
"emailToMD5": func(email string) string {
|
||||
return fmt.Sprintf("%x", md5.Sum([]byte(strings.ToLower(strings.TrimSpace(email)))))
|
||||
},
|
||||
}).ParseGlob("templates/*/*.html")),
|
||||
}
|
||||
|
Reference in New Issue
Block a user