socialnetworknews-api

git clone git://archive.git.mtrnord.blog/SocialNetworkNews/socialnetworknews-api.git
Log | Files | Refs | LICENSE

commit 6b40a4caacd181d2cc73a4324ae4fd11d8670d60
parent 1d500ab9fff048312fdaef8e6d47eb63fbd33f62
Author: MTRNord <mtrnord1@gmail.com>
Date:   Tue, 10 Apr 2018 20:47:49 +0200

Return userID on check request

Diffstat:
Mapi/login/twitter.go | 15++++++++++++++-
1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/api/login/twitter.go b/api/login/twitter.go @@ -128,7 +128,7 @@ func IssueSession() http.Handler { b, err := json.Marshal(twitterUser) if err != nil { - fmt.Println("error:", err) + http.Error(w, err.Error(), http.StatusInternalServerError) } SErr := saveTUser(twitterUser.IDStr, accessToken, accessSecret, twitterUser.ScreenName, b) @@ -176,6 +176,19 @@ func IsAuthenticated(req *http.Request) bool { // IsAuthenticatedHandleFunc returns 200 if the user has a signed session cookie. func IsAuthenticatedHandleFunc(w http.ResponseWriter, req *http.Request) { if IsAuthenticated(req) { + Reqsession, err := sessionStore.Get(req, sessionName) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + twitterUserID := Reqsession.Values[sessionUserKey] + // We know this is a string + uuidS, err := getUserUUID(twitterUserID.(string)) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + w.Header().Set("UUID", uuidS) w.WriteHeader(http.StatusOK) } else { w.WriteHeader(http.StatusUnauthorized)