mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-30 20:27:30 +00:00
Run "make fmt" with go-1.6 (#1333)
This commit is contained in:
parent
888dee3b5f
commit
f73e734411
|
@ -12,9 +12,9 @@ import (
|
|||
)
|
||||
|
||||
var signupFormSample map[string][]string = map[string][]string{
|
||||
"Name": []string{"tester"},
|
||||
"Email": []string{"user1@example.com"},
|
||||
"Passwd": []string{"12345678"},
|
||||
"Name": {"tester"},
|
||||
"Email": {"user1@example.com"},
|
||||
"Passwd": {"12345678"},
|
||||
}
|
||||
|
||||
func signup(t *utils.T) error {
|
||||
|
|
|
@ -67,8 +67,10 @@ func TestGetParticipantsByIssueID(t *testing.T) {
|
|||
checkPartecipants := func(issueID int64, userIDs []int) {
|
||||
partecipants, err := GetParticipantsByIssueID(issueID)
|
||||
if assert.NoError(t, err) {
|
||||
partecipantsIDs := make([]int,len(partecipants))
|
||||
for i,u := range partecipants { partecipantsIDs[i] = int(u.ID) }
|
||||
partecipantsIDs := make([]int, len(partecipants))
|
||||
for i, u := range partecipants {
|
||||
partecipantsIDs[i] = int(u.ID)
|
||||
}
|
||||
sort.Ints(partecipantsIDs)
|
||||
sort.Ints(userIDs)
|
||||
assert.Equal(t, userIDs, partecipantsIDs)
|
||||
|
@ -79,6 +81,6 @@ func TestGetParticipantsByIssueID(t *testing.T) {
|
|||
// User 1 is issue1 poster (see fixtures/issue.yml)
|
||||
// User 2 only labeled issue1 (see fixtures/comment.yml)
|
||||
// Users 3 and 5 made actual comments (see fixtures/comment.yml)
|
||||
checkPartecipants(1, []int{3,5})
|
||||
checkPartecipants(1, []int{3, 5})
|
||||
|
||||
}
|
||||
|
|
|
@ -12,12 +12,11 @@ import (
|
|||
|
||||
// UserOpenID is the list of all OpenID identities of a user.
|
||||
type UserOpenID struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
UID int64 `xorm:"INDEX NOT NULL"`
|
||||
URI string `xorm:"UNIQUE NOT NULL"`
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
UID int64 `xorm:"INDEX NOT NULL"`
|
||||
URI string `xorm:"UNIQUE NOT NULL"`
|
||||
}
|
||||
|
||||
|
||||
func addUserOpenID(x *xorm.Engine) error {
|
||||
if err := x.Sync2(new(UserOpenID)); err != nil {
|
||||
return fmt.Errorf("Sync2: %v", err)
|
||||
|
|
|
@ -143,7 +143,7 @@ func (t *Team) removeRepository(e Engine, repo *Repository, recalculate bool) (e
|
|||
if err != nil {
|
||||
return fmt.Errorf("getTeamUsersByTeamID: %v", err)
|
||||
}
|
||||
for _, teamUser:= range teamUsers {
|
||||
for _, teamUser := range teamUsers {
|
||||
has, err := hasAccess(e, teamUser.UID, repo, AccessModeRead)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
@ -68,4 +68,3 @@ func UnfollowUser(userID, followID int64) (err error) {
|
|||
}
|
||||
return sess.Commit()
|
||||
}
|
||||
|
||||
|
|
|
@ -18,10 +18,10 @@ var (
|
|||
|
||||
// UserOpenID is the list of all OpenID identities of a user.
|
||||
type UserOpenID struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
UID int64 `xorm:"INDEX NOT NULL"`
|
||||
URI string `xorm:"UNIQUE NOT NULL"`
|
||||
Show bool `xorm:"DEFAULT false"`
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
UID int64 `xorm:"INDEX NOT NULL"`
|
||||
URI string `xorm:"UNIQUE NOT NULL"`
|
||||
Show bool `xorm:"DEFAULT false"`
|
||||
}
|
||||
|
||||
// GetUserOpenIDs returns all openid addresses that belongs to given user.
|
||||
|
@ -122,4 +122,3 @@ func GetUserByOpenID(uri string) (*User, error) {
|
|||
|
||||
return nil, ErrUserNotExist{0, uri, 0}
|
||||
}
|
||||
|
||||
|
|
|
@ -52,14 +52,14 @@ func TestGetUserByOpenID(t *testing.T) {
|
|||
func TestToggleUserOpenIDVisibility(t *testing.T) {
|
||||
assert.NoError(t, PrepareTestDatabase())
|
||||
oids, err := GetUserOpenIDs(int64(2))
|
||||
if ! assert.NoError(t, err) {
|
||||
if !assert.NoError(t, err) {
|
||||
return
|
||||
}
|
||||
assert.Len(t, oids, 1)
|
||||
assert.True(t, oids[0].Show)
|
||||
|
||||
err = ToggleUserOpenIDVisibility(oids[0].ID)
|
||||
if ! assert.NoError(t, err) {
|
||||
if !assert.NoError(t, err) {
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -69,12 +69,12 @@ func TestToggleUserOpenIDVisibility(t *testing.T) {
|
|||
assert.False(t, oids[0].Show)
|
||||
}
|
||||
err = ToggleUserOpenIDVisibility(oids[0].ID)
|
||||
if ! assert.NoError(t, err) {
|
||||
if !assert.NoError(t, err) {
|
||||
return
|
||||
}
|
||||
|
||||
oids, err = GetUserOpenIDs(int64(2))
|
||||
if ! assert.NoError(t, err) {
|
||||
if !assert.NoError(t, err) {
|
||||
return
|
||||
}
|
||||
assert.Len(t, oids, 1)
|
||||
|
|
|
@ -18,7 +18,7 @@ type timedDiscoveredInfo struct {
|
|||
|
||||
type timedDiscoveryCache struct {
|
||||
cache map[string]timedDiscoveredInfo
|
||||
ttl time.Duration
|
||||
ttl time.Duration
|
||||
mutex *sync.Mutex
|
||||
}
|
||||
|
||||
|
@ -56,4 +56,3 @@ func (s *timedDiscoveryCache) Get(id string) openid.DiscoveredInfo {
|
|||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -9,7 +9,8 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
type testDiscoveredInfo struct {}
|
||||
type testDiscoveredInfo struct{}
|
||||
|
||||
func (s *testDiscoveredInfo) ClaimedID() string {
|
||||
return "claimedID"
|
||||
}
|
||||
|
@ -21,7 +22,7 @@ func (s *testDiscoveredInfo) OpLocalID() string {
|
|||
}
|
||||
|
||||
func TestTimedDiscoveryCache(t *testing.T) {
|
||||
dc := newTimedDiscoveryCache(1*time.Second)
|
||||
dc := newTimedDiscoveryCache(1 * time.Second)
|
||||
|
||||
// Put some initial values
|
||||
dc.Put("foo", &testDiscoveredInfo{}) //openid.opEndpoint: "a", openid.opLocalID: "b", openid.claimedID: "c"})
|
||||
|
|
|
@ -17,8 +17,7 @@ import (
|
|||
// least
|
||||
// the nonceStore between them.
|
||||
var nonceStore = openid.NewSimpleNonceStore()
|
||||
var discoveryCache = newTimedDiscoveryCache(24*time.Hour)
|
||||
|
||||
var discoveryCache = newTimedDiscoveryCache(24 * time.Hour)
|
||||
|
||||
// Verify handles response from OpenID provider
|
||||
func Verify(fullURL string) (id string, err error) {
|
||||
|
@ -34,4 +33,3 @@ func Normalize(url string) (id string, err error) {
|
|||
func RedirectURL(id, callbackURL, realm string) (string, error) {
|
||||
return openid.RedirectURL(id, callbackURL, realm)
|
||||
}
|
||||
|
||||
|
|
|
@ -155,7 +155,7 @@ func (f *ChangePasswordForm) Validate(ctx *macaron.Context, errs binding.Errors)
|
|||
|
||||
// AddOpenIDForm is for changing openid uri
|
||||
type AddOpenIDForm struct {
|
||||
Openid string `binding:"Required;MaxSize(256)"`
|
||||
Openid string `binding:"Required;MaxSize(256)"`
|
||||
}
|
||||
|
||||
// Validate validates the fields
|
||||
|
|
|
@ -9,10 +9,9 @@ import (
|
|||
"gopkg.in/macaron.v1"
|
||||
)
|
||||
|
||||
|
||||
// SignInOpenIDForm form for signing in with OpenID
|
||||
type SignInOpenIDForm struct {
|
||||
Openid string `binding:"Required;MaxSize(256)"`
|
||||
Openid string `binding:"Required;MaxSize(256)"`
|
||||
Remember bool
|
||||
}
|
||||
|
||||
|
@ -42,4 +41,3 @@ type ConnectOpenIDForm struct {
|
|||
func (f *ConnectOpenIDForm) Validate(ctx *macaron.Context, errs binding.Errors) binding.Errors {
|
||||
return validate(errs, ctx.Data, f, ctx.Locale)
|
||||
}
|
||||
|
||||
|
|
|
@ -762,14 +762,14 @@ please consider changing to GITEA_CUSTOM`)
|
|||
EnableOpenIDSignIn = sec.Key("ENABLE_OPENID_SIGNIN").MustBool(true)
|
||||
EnableOpenIDSignUp = sec.Key("ENABLE_OPENID_SIGNUP").MustBool(true)
|
||||
pats := sec.Key("WHITELISTED_URIS").Strings(" ")
|
||||
if ( len(pats) != 0 ) {
|
||||
if len(pats) != 0 {
|
||||
OpenIDWhitelist = make([]*regexp.Regexp, len(pats))
|
||||
for i, p := range pats {
|
||||
OpenIDWhitelist[i] = regexp.MustCompilePOSIX(p)
|
||||
}
|
||||
}
|
||||
pats = sec.Key("BLACKLISTED_URIS").Strings(" ")
|
||||
if ( len(pats) != 0 ) {
|
||||
if len(pats) != 0 {
|
||||
OpenIDBlacklist = make([]*regexp.Regexp, len(pats))
|
||||
for i, p := range pats {
|
||||
OpenIDBlacklist[i] = regexp.MustCompilePOSIX(p)
|
||||
|
|
|
@ -102,23 +102,24 @@ func SignInOpenIDPost(ctx *context.Context, form auth.SignInOpenIDForm) {
|
|||
id, err := openid.Normalize(form.Openid)
|
||||
if err != nil {
|
||||
ctx.RenderWithErr(err.Error(), tplSignInOpenID, &form)
|
||||
return;
|
||||
return
|
||||
}
|
||||
form.Openid = id
|
||||
|
||||
log.Trace("OpenID uri: " + id)
|
||||
|
||||
err = allowedOpenIDURI(id); if err != nil {
|
||||
err = allowedOpenIDURI(id)
|
||||
if err != nil {
|
||||
ctx.RenderWithErr(err.Error(), tplSignInOpenID, &form)
|
||||
return;
|
||||
return
|
||||
}
|
||||
|
||||
redirectTo := setting.AppURL + "user/login/openid"
|
||||
url, err := openid.RedirectURL(id, redirectTo, setting.AppURL)
|
||||
if err != nil {
|
||||
if err != nil {
|
||||
ctx.RenderWithErr(err.Error(), tplSignInOpenID, &form)
|
||||
return;
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Request optional nickname and email info
|
||||
// NOTE: change to `openid.sreg.required` to require it
|
||||
|
@ -134,10 +135,10 @@ func SignInOpenIDPost(ctx *context.Context, form auth.SignInOpenIDForm) {
|
|||
// signInOpenIDVerify handles response from OpenID provider
|
||||
func signInOpenIDVerify(ctx *context.Context) {
|
||||
|
||||
log.Trace("Incoming call to: " + ctx.Req.Request.URL.String())
|
||||
log.Trace("Incoming call to: " + ctx.Req.Request.URL.String())
|
||||
|
||||
fullURL := setting.AppURL + ctx.Req.Request.URL.String()[1:]
|
||||
log.Trace("Full URL: " + fullURL)
|
||||
fullURL := setting.AppURL + ctx.Req.Request.URL.String()[1:]
|
||||
log.Trace("Full URL: " + fullURL)
|
||||
|
||||
var id, err = openid.Verify(fullURL)
|
||||
if err != nil {
|
||||
|
@ -154,7 +155,7 @@ func signInOpenIDVerify(ctx *context.Context) {
|
|||
|
||||
u, _ := models.GetUserByOpenID(id)
|
||||
if err != nil {
|
||||
if ! models.IsErrUserNotExist(err) {
|
||||
if !models.IsErrUserNotExist(err) {
|
||||
ctx.RenderWithErr(err.Error(), tplSignInOpenID, &auth.SignInOpenIDForm{
|
||||
Openid: id,
|
||||
})
|
||||
|
@ -188,12 +189,12 @@ func signInOpenIDVerify(ctx *context.Context) {
|
|||
email := values.Get("openid.sreg.email")
|
||||
nickname := values.Get("openid.sreg.nickname")
|
||||
|
||||
log.Trace("User has email=" + email + " and nickname=" + nickname)
|
||||
log.Trace("User has email=" + email + " and nickname=" + nickname)
|
||||
|
||||
if email != "" {
|
||||
u, _ = models.GetUserByEmail(email)
|
||||
if err != nil {
|
||||
if ! models.IsErrUserNotExist(err) {
|
||||
if !models.IsErrUserNotExist(err) {
|
||||
ctx.RenderWithErr(err.Error(), tplSignInOpenID, &auth.SignInOpenIDForm{
|
||||
Openid: id,
|
||||
})
|
||||
|
@ -208,7 +209,7 @@ func signInOpenIDVerify(ctx *context.Context) {
|
|||
if u == nil && nickname != "" {
|
||||
u, _ = models.GetUserByName(nickname)
|
||||
if err != nil {
|
||||
if ! models.IsErrUserNotExist(err) {
|
||||
if !models.IsErrUserNotExist(err) {
|
||||
ctx.RenderWithErr(err.Error(), tplSignInOpenID, &auth.SignInOpenIDForm{
|
||||
Openid: id,
|
||||
})
|
||||
|
@ -230,7 +231,7 @@ func signInOpenIDVerify(ctx *context.Context) {
|
|||
|
||||
ctx.Session.Set("openid_determined_username", nickname)
|
||||
|
||||
if u != nil || ! setting.EnableOpenIDSignUp {
|
||||
if u != nil || !setting.EnableOpenIDSignUp {
|
||||
ctx.Redirect(setting.AppSubURL + "/user/openid/connect")
|
||||
} else {
|
||||
ctx.Redirect(setting.AppSubURL + "/user/openid/register")
|
||||
|
@ -280,7 +281,7 @@ func ConnectOpenIDPost(ctx *context.Context, form auth.ConnectOpenIDForm) {
|
|||
}
|
||||
|
||||
// add OpenID for the user
|
||||
userOID := &models.UserOpenID{UID:u.ID, URI:oid}
|
||||
userOID := &models.UserOpenID{UID: u.ID, URI: oid}
|
||||
if err = models.AddUserOpenID(userOID); err != nil {
|
||||
if models.IsErrOpenIDAlreadyUsed(err) {
|
||||
ctx.RenderWithErr(ctx.Tr("form.openid_been_used", oid), tplConnectOID, &form)
|
||||
|
@ -299,7 +300,7 @@ func ConnectOpenIDPost(ctx *context.Context, form auth.ConnectOpenIDForm) {
|
|||
|
||||
// RegisterOpenID shows a form to create a new user authenticated via an OpenID URI
|
||||
func RegisterOpenID(ctx *context.Context) {
|
||||
if ! setting.EnableOpenIDSignUp {
|
||||
if !setting.EnableOpenIDSignUp {
|
||||
ctx.Error(403)
|
||||
return
|
||||
}
|
||||
|
@ -327,7 +328,7 @@ func RegisterOpenID(ctx *context.Context) {
|
|||
|
||||
// RegisterOpenIDPost handles submission of a form to create a new user authenticated via an OpenID URI
|
||||
func RegisterOpenIDPost(ctx *context.Context, cpt *captcha.Captcha, form auth.SignUpOpenIDForm) {
|
||||
if ! setting.EnableOpenIDSignUp {
|
||||
if !setting.EnableOpenIDSignUp {
|
||||
ctx.Error(403)
|
||||
return
|
||||
}
|
||||
|
@ -351,7 +352,9 @@ func RegisterOpenIDPost(ctx *context.Context, cpt *captcha.Captcha, form auth.Si
|
|||
}
|
||||
|
||||
len := setting.MinPasswordLength
|
||||
if len < 256 { len = 256 }
|
||||
if len < 256 {
|
||||
len = 256
|
||||
}
|
||||
password, err := base.GetRandomString(len)
|
||||
if err != nil {
|
||||
ctx.RenderWithErr(err.Error(), tplSignUpOID, form)
|
||||
|
@ -387,7 +390,7 @@ func RegisterOpenIDPost(ctx *context.Context, cpt *captcha.Captcha, form auth.Si
|
|||
log.Trace("Account created: %s", u.Name)
|
||||
|
||||
// add OpenID for the user
|
||||
userOID := &models.UserOpenID{UID:u.ID, URI:oid}
|
||||
userOID := &models.UserOpenID{UID: u.ID, URI: oid}
|
||||
if err = models.AddUserOpenID(userOID); err != nil {
|
||||
if models.IsErrOpenIDAlreadyUsed(err) {
|
||||
ctx.RenderWithErr(ctx.Tr("form.openid_been_used", oid), tplSignUpOID, &form)
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
package user
|
||||
|
||||
import (
|
||||
|
||||
"code.gitea.io/gitea/models"
|
||||
"code.gitea.io/gitea/modules/auth"
|
||||
"code.gitea.io/gitea/modules/auth/openid"
|
||||
|
@ -16,7 +15,7 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
tplSettingsOpenID base.TplName = "user/settings/openid"
|
||||
tplSettingsOpenID base.TplName = "user/settings/openid"
|
||||
)
|
||||
|
||||
// SettingsOpenID renders change user's openid page
|
||||
|
@ -64,10 +63,10 @@ func SettingsOpenIDPost(ctx *context.Context, form auth.AddOpenIDForm) {
|
|||
id, err := openid.Normalize(form.Openid)
|
||||
if err != nil {
|
||||
ctx.RenderWithErr(err.Error(), tplSettingsOpenID, &form)
|
||||
return;
|
||||
return
|
||||
}
|
||||
form.Openid = id
|
||||
log.Trace("Normalized id: " + id)
|
||||
log.Trace("Normalized id: " + id)
|
||||
|
||||
oids, err := models.GetUserOpenIDs(ctx.User.ID)
|
||||
if err != nil {
|
||||
|
@ -84,21 +83,20 @@ func SettingsOpenIDPost(ctx *context.Context, form auth.AddOpenIDForm) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
redirectTo := setting.AppURL + "user/settings/openid"
|
||||
url, err := openid.RedirectURL(id, redirectTo, setting.AppURL)
|
||||
if err != nil {
|
||||
if err != nil {
|
||||
ctx.RenderWithErr(err.Error(), tplSettingsOpenID, &form)
|
||||
return;
|
||||
}
|
||||
return
|
||||
}
|
||||
ctx.Redirect(url)
|
||||
}
|
||||
|
||||
func settingsOpenIDVerify(ctx *context.Context) {
|
||||
log.Trace("Incoming call to: " + ctx.Req.Request.URL.String())
|
||||
log.Trace("Incoming call to: " + ctx.Req.Request.URL.String())
|
||||
|
||||
fullURL := setting.AppURL + ctx.Req.Request.URL.String()[1:]
|
||||
log.Trace("Full URL: " + fullURL)
|
||||
fullURL := setting.AppURL + ctx.Req.Request.URL.String()[1:]
|
||||
log.Trace("Full URL: " + fullURL)
|
||||
|
||||
oids, err := models.GetUserOpenIDs(ctx.User.ID)
|
||||
if err != nil {
|
||||
|
@ -117,10 +115,10 @@ func settingsOpenIDVerify(ctx *context.Context) {
|
|||
|
||||
log.Trace("Verified ID: " + id)
|
||||
|
||||
oid := &models.UserOpenID{UID:ctx.User.ID, URI:id}
|
||||
oid := &models.UserOpenID{UID: ctx.User.ID, URI: id}
|
||||
if err = models.AddUserOpenID(oid); err != nil {
|
||||
if models.IsErrOpenIDAlreadyUsed(err) {
|
||||
ctx.RenderWithErr(ctx.Tr("form.openid_been_used", id), tplSettingsOpenID, &auth.AddOpenIDForm{ Openid: id })
|
||||
ctx.RenderWithErr(ctx.Tr("form.openid_been_used", id), tplSettingsOpenID, &auth.AddOpenIDForm{Openid: id})
|
||||
return
|
||||
}
|
||||
ctx.Handle(500, "AddUserOpenID", err)
|
||||
|
@ -155,4 +153,3 @@ func ToggleOpenIDVisibility(ctx *context.Context) {
|
|||
|
||||
ctx.Redirect(setting.AppSubURL + "/user/settings/openid")
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue