mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00:00
more APIs on #12
This commit is contained in:
@@ -60,9 +60,9 @@ func SignedInId(req *http.Request, sess session.Store) int64 {
|
||||
}
|
||||
|
||||
// SignedInUser returns the user object of signed user.
|
||||
func SignedInUser(req *http.Request, sess session.Store) *models.User {
|
||||
func SignedInUser(req *http.Request, sess session.Store) (*models.User, bool) {
|
||||
if !models.HasEngine {
|
||||
return nil
|
||||
return nil, false
|
||||
}
|
||||
|
||||
uid := SignedInId(req, sess)
|
||||
@@ -76,9 +76,9 @@ func SignedInUser(req *http.Request, sess session.Store) *models.User {
|
||||
if err != models.ErrUserNotExist {
|
||||
log.Error(4, "GetUserByName: %v", err)
|
||||
}
|
||||
return nil
|
||||
return nil, false
|
||||
}
|
||||
return u
|
||||
return u, false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,23 +93,23 @@ func SignedInUser(req *http.Request, sess session.Store) *models.User {
|
||||
if err != models.ErrUserNotExist {
|
||||
log.Error(4, "GetUserByName: %v", err)
|
||||
}
|
||||
return nil
|
||||
return nil, false
|
||||
}
|
||||
|
||||
if u.ValidtePassword(passwd) {
|
||||
return u
|
||||
return u, true
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
return nil, false
|
||||
}
|
||||
|
||||
u, err := models.GetUserById(uid)
|
||||
if err != nil {
|
||||
log.Error(4, "GetUserById: %v", err)
|
||||
return nil
|
||||
return nil, false
|
||||
}
|
||||
return u
|
||||
return u, false
|
||||
}
|
||||
|
||||
type Form interface {
|
||||
|
@@ -76,3 +76,12 @@ func ApiReqToken() macaron.Handler {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func ApiReqBasicAuth() macaron.Handler {
|
||||
return func(ctx *Context) {
|
||||
if !ctx.IsBasicAuth {
|
||||
ctx.Error(403)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -34,8 +34,9 @@ type Context struct {
|
||||
Flash *session.Flash
|
||||
Session session.Store
|
||||
|
||||
User *models.User
|
||||
IsSigned bool
|
||||
User *models.User
|
||||
IsSigned bool
|
||||
IsBasicAuth bool
|
||||
|
||||
Repo struct {
|
||||
IsOwner bool
|
||||
@@ -172,7 +173,7 @@ func Contexter() macaron.Handler {
|
||||
ctx.Data["PageStartTime"] = time.Now()
|
||||
|
||||
// Get user from session if logined.
|
||||
ctx.User = auth.SignedInUser(ctx.Req.Request, ctx.Session)
|
||||
ctx.User, ctx.IsBasicAuth = auth.SignedInUser(ctx.Req.Request, ctx.Session)
|
||||
|
||||
if ctx.User != nil {
|
||||
ctx.IsSigned = true
|
||||
|
Reference in New Issue
Block a user