Keep user tokens, fix user info loading
This commit is contained in:
parent
aff38168b7
commit
954e140dfd
|
@ -27,8 +27,8 @@ func authCallbackHandler(w http.ResponseWriter, r *http.Request) {
|
|||
code := r.FormValue("code")
|
||||
log.Printf("Got code %q\n", code)
|
||||
|
||||
if _, login, err := task.Authenticate(code); err == nil {
|
||||
req.authorize(login)
|
||||
if token, login, err := task.Authenticate(code); err == nil {
|
||||
req.authorize(token, login)
|
||||
} else {
|
||||
panic(err)
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ type (
|
|||
r *http.Request
|
||||
w http.ResponseWriter
|
||||
sid string
|
||||
token string
|
||||
login string
|
||||
}
|
||||
statRequest struct {
|
||||
|
@ -32,16 +33,19 @@ type (
|
|||
func parseRequest(w http.ResponseWriter, r *http.Request) (*request, *statRequest) {
|
||||
sid := sessionID(w, r)
|
||||
login, _ := redis.String(redisPool.Get().Do("HGET", "sessions", sid))
|
||||
token, _ := redis.String(redisPool.Get().Do("HGET", "tokens", sid))
|
||||
req := &request{
|
||||
r: r,
|
||||
w: w,
|
||||
sid: sid,
|
||||
token: token,
|
||||
login: login,
|
||||
}
|
||||
return req, parseStatRequest(r)
|
||||
}
|
||||
|
||||
func (r *request) authorize(login string) {
|
||||
func (r *request) authorize(token, login string) {
|
||||
redisPool.Get().Do("HSET", "tokens", r.sid, token)
|
||||
redisPool.Get().Do("HSET", "sessions", r.sid, login)
|
||||
}
|
||||
|
||||
|
|
14
task/user.go
14
task/user.go
|
@ -18,11 +18,21 @@ func FetchUserInfo(token, login string) (u *db.User, err error) {
|
|||
}
|
||||
saveResponseMeta(token, resp)
|
||||
|
||||
name := ""
|
||||
if n := user.Name; n != nil {
|
||||
name = *user.Name
|
||||
}
|
||||
|
||||
avatarURL := ""
|
||||
if url := user.AvatarURL; url != nil {
|
||||
avatarURL = *user.AvatarURL
|
||||
}
|
||||
|
||||
u = &db.User{
|
||||
Login: *user.Login,
|
||||
Name: *user.Name,
|
||||
Name: name,
|
||||
ID: uint64(*user.ID),
|
||||
AvatarURL: *user.AvatarURL,
|
||||
AvatarURL: avatarURL,
|
||||
}
|
||||
|
||||
return
|
||||
|
|
Loading…
Reference in New Issue