move avatar put to login
This commit is contained in:
@@ -6,6 +6,9 @@ import (
|
||||
|
||||
"github.com/gorilla/sessions"
|
||||
|
||||
"log"
|
||||
|
||||
"github.com/umputun/remark/app/rest/avatar"
|
||||
"github.com/umputun/remark/app/rest/common"
|
||||
"github.com/umputun/remark/app/store"
|
||||
)
|
||||
@@ -29,7 +32,7 @@ var devUser = store.User{
|
||||
}
|
||||
|
||||
// Auth middleware adds auth from session and populates user info
|
||||
func Auth(sessionStore sessions.Store, admins []string, modes []Mode) func(http.Handler) http.Handler {
|
||||
func Auth(sessionStore sessions.Store, avatarProxy avatar.Proxy, admins []string, modes []Mode) func(http.Handler) http.Handler {
|
||||
|
||||
inModes := func(mode Mode) bool {
|
||||
for _, m := range modes {
|
||||
@@ -79,6 +82,12 @@ func Auth(sessionStore sessions.Store, admins []string, modes []Mode) func(http.
|
||||
}
|
||||
}
|
||||
|
||||
if avatarURL, e := avatarProxy.Put(user); e == nil {
|
||||
user.Picture = avatarURL
|
||||
} else {
|
||||
log.Printf("[WARN] failed to proxy avatar, %s", e)
|
||||
}
|
||||
|
||||
ctx := r.Context()
|
||||
ctx = context.WithValue(ctx, common.ContextKey("user"), user)
|
||||
r = r.WithContext(ctx)
|
||||
|
||||
@@ -62,6 +62,7 @@ func NewGithub(p Params) Provider {
|
||||
|
||||
// NewFacebook makes facebook oauth2 provider
|
||||
func NewFacebook(p Params) Provider {
|
||||
|
||||
return initProvider(p, Provider{
|
||||
Name: "facebook",
|
||||
Endpoint: facebook.Endpoint,
|
||||
@@ -79,7 +80,7 @@ func NewFacebook(p Params) Provider {
|
||||
}
|
||||
userInfo.ID = "facebook_" + userInfo.ID
|
||||
|
||||
// picture under picture[data[url]] TODO: make this horror simpler
|
||||
// picture under picture[data[url]]
|
||||
if p, ok := data["picture"]; ok {
|
||||
if picMap, ok := p.(map[string]interface{}); ok {
|
||||
if d, ok := picMap["data"]; ok {
|
||||
|
||||
@@ -153,12 +153,6 @@ func (s *Server) createCommentCtrl(w http.ResponseWriter, r *http.Request) {
|
||||
// render markdown
|
||||
comment.Text = string(blackfriday.Run([]byte(comment.Text), blackfriday.WithNoExtensions()))
|
||||
|
||||
if avatarURL, e := s.AvatarProxy.Put(user); e == nil {
|
||||
comment.User.Picture = avatarURL
|
||||
} else {
|
||||
log.Printf("[WARN] failed to proxy avatar, %s", e)
|
||||
}
|
||||
|
||||
log.Printf("[DEBUG] create comment %+v", comment)
|
||||
|
||||
// check if user blocked
|
||||
|
||||
Reference in New Issue
Block a user