forked from forgejo/forgejo
Clean repo code
This commit is contained in:
parent
bbdfe25769
commit
6e3dba2cc5
13 changed files with 96 additions and 154 deletions
|
@ -267,7 +267,10 @@ func validateStruct(errors *BindingErrors, obj interface{}) {
|
|||
break
|
||||
}
|
||||
case rule == "Url":
|
||||
if !urlPattern.MatchString(fmt.Sprintf("%v", fieldValue)) {
|
||||
str := fmt.Sprintf("%v", fieldValue)
|
||||
if len(str) == 0 {
|
||||
continue
|
||||
} else if !urlPattern.MatchString(str) {
|
||||
errors.Fields[field.Name] = BindingUrlError
|
||||
break
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ package middleware
|
|||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
"github.com/go-martini/martini"
|
||||
|
@ -238,3 +239,17 @@ func RepoAssignment(redirect bool, args ...bool) martini.Handler {
|
|||
ctx.Data["IsRepositoryWatching"] = ctx.Repo.IsWatching
|
||||
}
|
||||
}
|
||||
|
||||
func RequireOwner() martini.Handler {
|
||||
return func(ctx *Context) {
|
||||
if !ctx.Repo.IsOwner {
|
||||
if !ctx.IsSigned {
|
||||
ctx.SetCookie("redirect_to", "/"+url.QueryEscape(ctx.Req.RequestURI))
|
||||
ctx.Redirect("/user/login")
|
||||
return
|
||||
}
|
||||
ctx.Handle(404, ctx.Req.RequestURI, nil)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue