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