diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2014-03-06 16:24:08 +0800 |
---|---|---|
committer | Lunny Xiao <xiaolunwen@gmail.com> | 2014-03-06 16:24:08 +0800 |
commit | e878bfb80f52c334a18fbf7b18f79359f7d373af (patch) | |
tree | 01e2cb1b5fcd5aeb2380bda2a5e5b28f3933ce15 /routers | |
parent | 245e806679ddb0e24391ae43cd0b78a3d1cbf730 (diff) | |
download | gitea-e878bfb80f52c334a18fbf7b18f79359f7d373af.tar.gz gitea-e878bfb80f52c334a18fbf7b18f79359f7d373af.zip |
add SignedInId & SignedInUser funcs
Diffstat (limited to 'routers')
-rw-r--r-- | routers/user/user.go | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/routers/user/user.go b/routers/user/user.go index ac482ad66f..ccbbd01b44 100644 --- a/routers/user/user.go +++ b/routers/user/user.go @@ -26,14 +26,18 @@ func Profile(r render.Render) { } func IsSignedIn(session sessions.Session) bool { - id := session.Get("userId") - if id == nil { - return false + return SignedInId(session) > 0 +} + +func SignedInId(session sessions.Session) int64 { + userId := session.Get("userId") + if userId == nil { + return 0 } - if s, ok := id.(int64); ok && s > 0 { - return true + if s, ok := userId.(int64); ok { + return s } - return false + return 0 } func SignedInName(session sessions.Session) string { @@ -47,6 +51,19 @@ func SignedInName(session sessions.Session) string { return "" } +func SignedInUser(session sessions.Session) *models.User { + id := SignedInId(session) + if id <= 0 { + return nil + } + + user, err := models.GetUserById(id) + if err != nil { + return nil + } + return user +} + func SignIn(req *http.Request, r render.Render, session sessions.Session) { var ( errString string |