summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--integrations/signup_test.go6
-rw-r--r--models/issue_test.go8
-rw-r--r--models/migrations/v23.go7
-rw-r--r--models/org_team.go2
-rw-r--r--models/user_follow.go1
-rw-r--r--models/user_openid.go9
-rw-r--r--models/user_openid_test.go8
-rw-r--r--modules/auth/openid/discovery_cache.go3
-rw-r--r--modules/auth/openid/discovery_cache_test.go5
-rw-r--r--modules/auth/openid/openid.go4
-rw-r--r--modules/auth/user_form.go2
-rw-r--r--modules/auth/user_form_auth_openid.go4
-rw-r--r--modules/setting/setting.go4
-rw-r--r--routers/user/auth_openid.go41
-rw-r--r--routers/user/setting_openid.go25
15 files changed, 62 insertions, 67 deletions
diff --git a/integrations/signup_test.go b/integrations/signup_test.go
index c317b88d10..55ae64c373 100644
--- a/integrations/signup_test.go
+++ b/integrations/signup_test.go
@@ -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 {
diff --git a/models/issue_test.go b/models/issue_test.go
index 52724d07d4..71ce92ea7e 100644
--- a/models/issue_test.go
+++ b/models/issue_test.go
@@ -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})
}
diff --git a/models/migrations/v23.go b/models/migrations/v23.go
index efde684104..4aadf7ef0d 100644
--- a/models/migrations/v23.go
+++ b/models/migrations/v23.go
@@ -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)
diff --git a/models/org_team.go b/models/org_team.go
index db25e61547..115e13feab 100644
--- a/models/org_team.go
+++ b/models/org_team.go
@@ -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
diff --git a/models/user_follow.go b/models/user_follow.go
index ac0cf0a8f3..2d64d05473 100644
--- a/models/user_follow.go
+++ b/models/user_follow.go
@@ -68,4 +68,3 @@ func UnfollowUser(userID, followID int64) (err error) {
}
return sess.Commit()
}
-
diff --git a/models/user_openid.go b/models/user_openid.go
index 18e847d89d..db84e2e08f 100644
--- a/models/user_openid.go
+++ b/models/user_openid.go
@@ -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}
}
-
diff --git a/models/user_openid_test.go b/models/user_openid_test.go
index 74e3cf6f00..e4734cc428 100644
--- a/models/user_openid_test.go
+++ b/models/user_openid_test.go
@@ -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)
diff --git a/modules/auth/openid/discovery_cache.go b/modules/auth/openid/discovery_cache.go
index cf9f5ae70c..68cd7a8756 100644
--- a/modules/auth/openid/discovery_cache.go
+++ b/modules/auth/openid/discovery_cache.go
@@ -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
}
-
diff --git a/modules/auth/openid/discovery_cache_test.go b/modules/auth/openid/discovery_cache_test.go
index 9de65a57bb..2e37058cc3 100644
--- a/modules/auth/openid/discovery_cache_test.go
+++ b/modules/auth/openid/discovery_cache_test.go
@@ -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"})
diff --git a/modules/auth/openid/openid.go b/modules/auth/openid/openid.go
index aebdf15155..ffe0aba2b6 100644
--- a/modules/auth/openid/openid.go
+++ b/modules/auth/openid/openid.go
@@ -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)
}
-
diff --git a/modules/auth/user_form.go b/modules/auth/user_form.go
index 9c6e38c460..bac9622fcc 100644
--- a/modules/auth/user_form.go
+++ b/modules/auth/user_form.go
@@ -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
diff --git a/modules/auth/user_form_auth_openid.go b/modules/auth/user_form_auth_openid.go
index 582c6dc69f..0ef821dd9e 100644
--- a/modules/auth/user_form_auth_openid.go
+++ b/modules/auth/user_form_auth_openid.go
@@ -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)
}
-
diff --git a/modules/setting/setting.go b/modules/setting/setting.go
index a7e93c36fc..8c45e61e81 100644
--- a/modules/setting/setting.go
+++ b/modules/setting/setting.go
@@ -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)
diff --git a/routers/user/auth_openid.go b/routers/user/auth_openid.go
index 19c1548399..c5575814f1 100644
--- a/routers/user/auth_openid.go
+++ b/routers/user/auth_openid.go
@@ -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)
diff --git a/routers/user/setting_openid.go b/routers/user/setting_openid.go
index e33ab144ed..b39278d7c3 100644
--- a/routers/user/setting_openid.go
+++ b/routers/user/setting_openid.go
@@ -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")
}
-