mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00:00
Add postgres support, clean code, code review
This commit is contained in:
@@ -18,6 +18,7 @@ import (
|
||||
"github.com/gogits/gogs/modules/log"
|
||||
)
|
||||
|
||||
// SignedInId returns the id of signed in user.
|
||||
func SignedInId(session sessions.Session) int64 {
|
||||
userId := session.Get("userId")
|
||||
if userId == nil {
|
||||
@@ -32,6 +33,7 @@ func SignedInId(session sessions.Session) int64 {
|
||||
return 0
|
||||
}
|
||||
|
||||
// SignedInName returns the name of signed in user.
|
||||
func SignedInName(session sessions.Session) string {
|
||||
userName := session.Get("userName")
|
||||
if userName == nil {
|
||||
@@ -43,6 +45,7 @@ func SignedInName(session sessions.Session) string {
|
||||
return ""
|
||||
}
|
||||
|
||||
// SignedInUser returns the user object of signed user.
|
||||
func SignedInUser(session sessions.Session) *models.User {
|
||||
id := SignedInId(session)
|
||||
if id <= 0 {
|
||||
@@ -57,6 +60,7 @@ func SignedInUser(session sessions.Session) *models.User {
|
||||
return user
|
||||
}
|
||||
|
||||
// IsSignedIn check if any user has signed in.
|
||||
func IsSignedIn(session sessions.Session) bool {
|
||||
return SignedInId(session) > 0
|
||||
}
|
||||
|
@@ -4,8 +4,6 @@
|
||||
|
||||
package base
|
||||
|
||||
import ()
|
||||
|
||||
type (
|
||||
// Type TmplData represents data in the templates.
|
||||
TmplData map[string]interface{}
|
||||
|
@@ -48,6 +48,7 @@ func init() {
|
||||
fmt.Printf("Cannot load config file '%s'\n", cfgPath)
|
||||
os.Exit(2)
|
||||
}
|
||||
Cfg.BlockMode = false
|
||||
|
||||
cfgPath = filepath.Join(workDir, "custom/conf/app.ini")
|
||||
if com.IsFile(cfgPath) {
|
||||
|
@@ -8,6 +8,7 @@ import (
|
||||
"github.com/codegangsta/martini"
|
||||
)
|
||||
|
||||
// SignInRequire requires user to sign in.
|
||||
func SignInRequire(redirect bool) martini.Handler {
|
||||
return func(ctx *Context) {
|
||||
if !ctx.IsSigned {
|
||||
@@ -19,6 +20,7 @@ func SignInRequire(redirect bool) martini.Handler {
|
||||
}
|
||||
}
|
||||
|
||||
// SignOutRequire requires user to sign out.
|
||||
func SignOutRequire() martini.Handler {
|
||||
return func(ctx *Context) {
|
||||
if ctx.IsSigned {
|
||||
|
Reference in New Issue
Block a user