mirror of
https://github.com/muety/wakapi.git
synced 2023-08-10 21:12:56 +03:00
chore: include avatar rendering into wakapi itself
This commit is contained in:
35
routes/api/avatar.go
Normal file
35
routes/api/avatar.go
Normal file
@ -0,0 +1,35 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"codeberg.org/Codeberg/avatars"
|
||||
"github.com/gorilla/mux"
|
||||
conf "github.com/muety/wakapi/config"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type AvatarHandler struct {
|
||||
config *conf.Config
|
||||
}
|
||||
|
||||
func NewAvatarHandler() *AvatarHandler {
|
||||
return &AvatarHandler{config: conf.Get()}
|
||||
}
|
||||
|
||||
func (h *AvatarHandler) RegisterRoutes(router *mux.Router) {
|
||||
r := router.PathPrefix("/avatar/{hash}.svg").Subrouter()
|
||||
r.Path("").Methods(http.MethodGet).HandlerFunc(h.Get)
|
||||
}
|
||||
|
||||
func (h *AvatarHandler) Get(w http.ResponseWriter, r *http.Request) {
|
||||
vars := mux.Vars(r)
|
||||
|
||||
if vars["hash"] == "" {
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
w.Write([]byte{})
|
||||
return
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "image/svg+xml")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.Write([]byte(avatars.MakeMaleAvatar(vars["hash"])))
|
||||
}
|
@ -299,12 +299,11 @@ func (h *LoginHandler) PostResetPassword(w http.ResponseWriter, r *http.Request)
|
||||
|
||||
func (h *LoginHandler) buildViewModel(r *http.Request) *view.LoginViewModel {
|
||||
numUsers, _ := h.userSrvc.Count()
|
||||
allowSignup := h.config.Security.AllowSignup
|
||||
|
||||
return &view.LoginViewModel{
|
||||
Success: r.URL.Query().Get("success"),
|
||||
Error: r.URL.Query().Get("error"),
|
||||
TotalUsers: int(numUsers),
|
||||
AllowSignup: allowSignup,
|
||||
AllowSignup: h.config.IsDev() || h.config.Security.AllowSignup,
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user