mirror of
https://github.com/go-gitea/gitea
synced 2024-12-22 12:54:04 +01:00
Move user follow and openid into models/user/ (#17613)
* Move UserRedirect into models/user/ * Fix lint & test * Fix lint * Fix lint * remove nolint comment * Fix lint * Move user follow and openid into models/user * Ignore the lint * Ignore the lint * Fix test * ignore stutters lint on UserOpenID
This commit is contained in:
parent
adda27668b
commit
95d3266bee
17 changed files with 155 additions and 143 deletions
|
@ -111,3 +111,6 @@ issues:
|
||||||
linters:
|
linters:
|
||||||
- staticcheck
|
- staticcheck
|
||||||
text: "svc.IsAnInteractiveSession is deprecated: Use IsWindowsService instead."
|
text: "svc.IsAnInteractiveSession is deprecated: Use IsWindowsService instead."
|
||||||
|
- path: models/user/openid.go
|
||||||
|
linters:
|
||||||
|
- golint
|
||||||
|
|
|
@ -11,12 +11,13 @@ import (
|
||||||
|
|
||||||
"code.gitea.io/gitea/models"
|
"code.gitea.io/gitea/models"
|
||||||
"code.gitea.io/gitea/models/unittest"
|
"code.gitea.io/gitea/models/unittest"
|
||||||
|
user_model "code.gitea.io/gitea/models/user"
|
||||||
)
|
)
|
||||||
|
|
||||||
func assertUserDeleted(t *testing.T, userID int64) {
|
func assertUserDeleted(t *testing.T, userID int64) {
|
||||||
unittest.AssertNotExistsBean(t, &models.User{ID: userID})
|
unittest.AssertNotExistsBean(t, &models.User{ID: userID})
|
||||||
unittest.AssertNotExistsBean(t, &models.Follow{UserID: userID})
|
unittest.AssertNotExistsBean(t, &user_model.Follow{UserID: userID})
|
||||||
unittest.AssertNotExistsBean(t, &models.Follow{FollowID: userID})
|
unittest.AssertNotExistsBean(t, &user_model.Follow{FollowID: userID})
|
||||||
unittest.AssertNotExistsBean(t, &models.Repository{OwnerID: userID})
|
unittest.AssertNotExistsBean(t, &models.Repository{OwnerID: userID})
|
||||||
unittest.AssertNotExistsBean(t, &models.Access{UserID: userID})
|
unittest.AssertNotExistsBean(t, &models.Access{UserID: userID})
|
||||||
unittest.AssertNotExistsBean(t, &models.OrgUser{UID: userID})
|
unittest.AssertNotExistsBean(t, &models.OrgUser{UID: userID})
|
||||||
|
|
|
@ -155,21 +155,6 @@ func (err ErrUserInactive) Error() string {
|
||||||
return fmt.Sprintf("user is inactive [uid: %d, name: %s]", err.UID, err.Name)
|
return fmt.Sprintf("user is inactive [uid: %d, name: %s]", err.UID, err.Name)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ErrOpenIDAlreadyUsed represents a "OpenIDAlreadyUsed" kind of error.
|
|
||||||
type ErrOpenIDAlreadyUsed struct {
|
|
||||||
OpenID string
|
|
||||||
}
|
|
||||||
|
|
||||||
// IsErrOpenIDAlreadyUsed checks if an error is a ErrOpenIDAlreadyUsed.
|
|
||||||
func IsErrOpenIDAlreadyUsed(err error) bool {
|
|
||||||
_, ok := err.(ErrOpenIDAlreadyUsed)
|
|
||||||
return ok
|
|
||||||
}
|
|
||||||
|
|
||||||
func (err ErrOpenIDAlreadyUsed) Error() string {
|
|
||||||
return fmt.Sprintf("OpenID already in use [oid: %s]", err.OpenID)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ErrUserOwnRepos represents a "UserOwnRepos" kind of error.
|
// ErrUserOwnRepos represents a "UserOwnRepos" kind of error.
|
||||||
type ErrUserOwnRepos struct {
|
type ErrUserOwnRepos struct {
|
||||||
UID int64
|
UID int64
|
||||||
|
|
|
@ -7,6 +7,7 @@ package models
|
||||||
import (
|
import (
|
||||||
"code.gitea.io/gitea/models/db"
|
"code.gitea.io/gitea/models/db"
|
||||||
"code.gitea.io/gitea/models/login"
|
"code.gitea.io/gitea/models/login"
|
||||||
|
user_model "code.gitea.io/gitea/models/user"
|
||||||
"code.gitea.io/gitea/models/webhook"
|
"code.gitea.io/gitea/models/webhook"
|
||||||
"code.gitea.io/gitea/modules/setting"
|
"code.gitea.io/gitea/modules/setting"
|
||||||
)
|
)
|
||||||
|
@ -92,7 +93,7 @@ func GetStatistic() (stats Statistic) {
|
||||||
|
|
||||||
stats.Counter.Comment, _ = e.Count(new(Comment))
|
stats.Counter.Comment, _ = e.Count(new(Comment))
|
||||||
stats.Counter.Oauth = 0
|
stats.Counter.Oauth = 0
|
||||||
stats.Counter.Follow, _ = e.Count(new(Follow))
|
stats.Counter.Follow, _ = e.Count(new(user_model.Follow))
|
||||||
stats.Counter.Mirror, _ = e.Count(new(Mirror))
|
stats.Counter.Mirror, _ = e.Count(new(Mirror))
|
||||||
stats.Counter.Release, _ = e.Count(new(Release))
|
stats.Counter.Release, _ = e.Count(new(Release))
|
||||||
stats.Counter.LoginSource = login.CountSources()
|
stats.Counter.LoginSource = login.CountSources()
|
||||||
|
|
|
@ -25,6 +25,7 @@ import (
|
||||||
"code.gitea.io/gitea/models/login"
|
"code.gitea.io/gitea/models/login"
|
||||||
"code.gitea.io/gitea/models/unit"
|
"code.gitea.io/gitea/models/unit"
|
||||||
user_model "code.gitea.io/gitea/models/user"
|
user_model "code.gitea.io/gitea/models/user"
|
||||||
|
"code.gitea.io/gitea/modules/auth/openid"
|
||||||
"code.gitea.io/gitea/modules/base"
|
"code.gitea.io/gitea/modules/base"
|
||||||
"code.gitea.io/gitea/modules/git"
|
"code.gitea.io/gitea/modules/git"
|
||||||
"code.gitea.io/gitea/modules/log"
|
"code.gitea.io/gitea/modules/log"
|
||||||
|
@ -359,7 +360,7 @@ func (u *User) GetFollowers(listOptions db.ListOptions) ([]*User, error) {
|
||||||
|
|
||||||
// IsFollowing returns true if user is following followID.
|
// IsFollowing returns true if user is following followID.
|
||||||
func (u *User) IsFollowing(followID int64) bool {
|
func (u *User) IsFollowing(followID int64) bool {
|
||||||
return IsFollowing(u.ID, followID)
|
return user_model.IsFollowing(u.ID, followID)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetFollowing returns range of user's following.
|
// GetFollowing returns range of user's following.
|
||||||
|
@ -469,7 +470,7 @@ func (u *User) isVisibleToUser(e db.Engine, viewer *User) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
// If they follow - they see each over
|
// If they follow - they see each over
|
||||||
follower := IsFollowing(u.ID, viewer.ID)
|
follower := user_model.IsFollowing(u.ID, viewer.ID)
|
||||||
if follower {
|
if follower {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -1212,12 +1213,12 @@ func deleteUser(e db.Engine, u *User) error {
|
||||||
&Access{UserID: u.ID},
|
&Access{UserID: u.ID},
|
||||||
&Watch{UserID: u.ID},
|
&Watch{UserID: u.ID},
|
||||||
&Star{UID: u.ID},
|
&Star{UID: u.ID},
|
||||||
&Follow{UserID: u.ID},
|
&user_model.Follow{UserID: u.ID},
|
||||||
&Follow{FollowID: u.ID},
|
&user_model.Follow{FollowID: u.ID},
|
||||||
&Action{UserID: u.ID},
|
&Action{UserID: u.ID},
|
||||||
&IssueUser{UID: u.ID},
|
&IssueUser{UID: u.ID},
|
||||||
&user_model.EmailAddress{UID: u.ID},
|
&user_model.EmailAddress{UID: u.ID},
|
||||||
&UserOpenID{UID: u.ID},
|
&user_model.UserOpenID{UID: u.ID},
|
||||||
&Reaction{UserID: u.ID},
|
&Reaction{UserID: u.ID},
|
||||||
&TeamUser{UID: u.ID},
|
&TeamUser{UID: u.ID},
|
||||||
&Collaboration{UserID: u.ID},
|
&Collaboration{UserID: u.ID},
|
||||||
|
@ -1798,3 +1799,29 @@ func IterateUser(f func(user *User) error) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetUserByOpenID returns the user object by given OpenID if exists.
|
||||||
|
func GetUserByOpenID(uri string) (*User, error) {
|
||||||
|
if len(uri) == 0 {
|
||||||
|
return nil, ErrUserNotExist{0, uri, 0}
|
||||||
|
}
|
||||||
|
|
||||||
|
uri, err := openid.Normalize(uri)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Trace("Normalized OpenID URI: " + uri)
|
||||||
|
|
||||||
|
// Otherwise, check in openid table
|
||||||
|
oid := &user_model.UserOpenID{}
|
||||||
|
has, err := db.GetEngine(db.DefaultContext).Where("uri=?", uri).Get(oid)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if has {
|
||||||
|
return GetUserByID(oid.UID)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil, ErrUserNotExist{0, uri, 0}
|
||||||
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
// Use of this source code is governed by a MIT-style
|
// Use of this source code is governed by a MIT-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
package models
|
package user
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"code.gitea.io/gitea/models/db"
|
"code.gitea.io/gitea/models/db"
|
22
models/user/follow_test.go
Normal file
22
models/user/follow_test.go
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
// Copyright 2020 The Gitea Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a MIT-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package user
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"code.gitea.io/gitea/models/unittest"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestIsFollowing(t *testing.T) {
|
||||||
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||||
|
assert.True(t, IsFollowing(4, 2))
|
||||||
|
assert.False(t, IsFollowing(2, 4))
|
||||||
|
assert.False(t, IsFollowing(5, unittest.NonexistentID))
|
||||||
|
assert.False(t, IsFollowing(unittest.NonexistentID, 5))
|
||||||
|
assert.False(t, IsFollowing(unittest.NonexistentID, unittest.NonexistentID))
|
||||||
|
}
|
|
@ -15,5 +15,7 @@ func TestMain(m *testing.M) {
|
||||||
unittest.MainTest(m, filepath.Join("..", ".."),
|
unittest.MainTest(m, filepath.Join("..", ".."),
|
||||||
"email_address.yml",
|
"email_address.yml",
|
||||||
"user_redirect.yml",
|
"user_redirect.yml",
|
||||||
|
"follow.yml",
|
||||||
|
"user_open_id.yml",
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,21 +2,21 @@
|
||||||
// Use of this source code is governed by a MIT-style
|
// Use of this source code is governed by a MIT-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
package models
|
package user
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
"code.gitea.io/gitea/models/db"
|
"code.gitea.io/gitea/models/db"
|
||||||
"code.gitea.io/gitea/modules/auth/openid"
|
|
||||||
"code.gitea.io/gitea/modules/log"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// ErrOpenIDNotExist openid is not known
|
// ErrOpenIDNotExist openid is not known
|
||||||
var ErrOpenIDNotExist = errors.New("OpenID is unknown")
|
var ErrOpenIDNotExist = errors.New("OpenID is unknown")
|
||||||
|
|
||||||
// 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 {
|
// Since this is a middle table, name it OpenID is not suitable, so we ignore the lint here
|
||||||
|
type UserOpenID struct { //revive:disable-line:exported
|
||||||
ID int64 `xorm:"pk autoincr"`
|
ID int64 `xorm:"pk autoincr"`
|
||||||
UID int64 `xorm:"INDEX NOT NULL"`
|
UID int64 `xorm:"INDEX NOT NULL"`
|
||||||
URI string `xorm:"UNIQUE NOT NULL"`
|
URI string `xorm:"UNIQUE NOT NULL"`
|
||||||
|
@ -49,6 +49,21 @@ func isOpenIDUsed(e db.Engine, uri string) (bool, error) {
|
||||||
return e.Get(&UserOpenID{URI: uri})
|
return e.Get(&UserOpenID{URI: uri})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ErrOpenIDAlreadyUsed represents a "OpenIDAlreadyUsed" kind of error.
|
||||||
|
type ErrOpenIDAlreadyUsed struct {
|
||||||
|
OpenID string
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsErrOpenIDAlreadyUsed checks if an error is a ErrOpenIDAlreadyUsed.
|
||||||
|
func IsErrOpenIDAlreadyUsed(err error) bool {
|
||||||
|
_, ok := err.(ErrOpenIDAlreadyUsed)
|
||||||
|
return ok
|
||||||
|
}
|
||||||
|
|
||||||
|
func (err ErrOpenIDAlreadyUsed) Error() string {
|
||||||
|
return fmt.Sprintf("OpenID already in use [oid: %s]", err.OpenID)
|
||||||
|
}
|
||||||
|
|
||||||
// NOTE: make sure openid.URI is normalized already
|
// NOTE: make sure openid.URI is normalized already
|
||||||
func addUserOpenID(e db.Engine, openid *UserOpenID) error {
|
func addUserOpenID(e db.Engine, openid *UserOpenID) error {
|
||||||
used, err := isOpenIDUsed(e, openid.URI)
|
used, err := isOpenIDUsed(e, openid.URI)
|
||||||
|
@ -95,29 +110,3 @@ func ToggleUserOpenIDVisibility(id int64) (err error) {
|
||||||
_, err = db.GetEngine(db.DefaultContext).Exec("update `user_open_id` set `show` = not `show` where `id` = ?", id)
|
_, err = db.GetEngine(db.DefaultContext).Exec("update `user_open_id` set `show` = not `show` where `id` = ?", id)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetUserByOpenID returns the user object by given OpenID if exists.
|
|
||||||
func GetUserByOpenID(uri string) (*User, error) {
|
|
||||||
if len(uri) == 0 {
|
|
||||||
return nil, ErrUserNotExist{0, uri, 0}
|
|
||||||
}
|
|
||||||
|
|
||||||
uri, err := openid.Normalize(uri)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
log.Trace("Normalized OpenID URI: " + uri)
|
|
||||||
|
|
||||||
// Otherwise, check in openid table
|
|
||||||
oid := &UserOpenID{}
|
|
||||||
has, err := db.GetEngine(db.DefaultContext).Where("uri=?", uri).Get(oid)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if has {
|
|
||||||
return GetUserByID(oid.UID)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil, ErrUserNotExist{0, uri, 0}
|
|
||||||
}
|
|
|
@ -2,7 +2,7 @@
|
||||||
// Use of this source code is governed by a MIT-style
|
// Use of this source code is governed by a MIT-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
package models
|
package user
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -30,25 +30,6 @@ func TestGetUserOpenIDs(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetUserByOpenID(t *testing.T) {
|
|
||||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
|
||||||
|
|
||||||
_, err := GetUserByOpenID("https://unknown")
|
|
||||||
if assert.Error(t, err) {
|
|
||||||
assert.True(t, IsErrUserNotExist(err))
|
|
||||||
}
|
|
||||||
|
|
||||||
user, err := GetUserByOpenID("https://user1.domain1.tld")
|
|
||||||
if assert.NoError(t, err) {
|
|
||||||
assert.Equal(t, int64(1), user.ID)
|
|
||||||
}
|
|
||||||
|
|
||||||
user, err = GetUserByOpenID("https://domain1.tld/user2/")
|
|
||||||
if assert.NoError(t, err) {
|
|
||||||
assert.Equal(t, int64(2), user.ID)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestToggleUserOpenIDVisibility(t *testing.T) {
|
func TestToggleUserOpenIDVisibility(t *testing.T) {
|
||||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||||
oids, err := GetUserOpenIDs(int64(2))
|
oids, err := GetUserOpenIDs(int64(2))
|
|
@ -1,50 +0,0 @@
|
||||||
// Copyright 2020 The Gitea Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a MIT-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
package models
|
|
||||||
|
|
||||||
import (
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"code.gitea.io/gitea/models/unittest"
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestIsFollowing(t *testing.T) {
|
|
||||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
|
||||||
assert.True(t, IsFollowing(4, 2))
|
|
||||||
assert.False(t, IsFollowing(2, 4))
|
|
||||||
assert.False(t, IsFollowing(5, unittest.NonexistentID))
|
|
||||||
assert.False(t, IsFollowing(unittest.NonexistentID, 5))
|
|
||||||
assert.False(t, IsFollowing(unittest.NonexistentID, unittest.NonexistentID))
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestFollowUser(t *testing.T) {
|
|
||||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
|
||||||
|
|
||||||
testSuccess := func(followerID, followedID int64) {
|
|
||||||
assert.NoError(t, FollowUser(followerID, followedID))
|
|
||||||
unittest.AssertExistsAndLoadBean(t, &Follow{UserID: followerID, FollowID: followedID})
|
|
||||||
}
|
|
||||||
testSuccess(4, 2)
|
|
||||||
testSuccess(5, 2)
|
|
||||||
|
|
||||||
assert.NoError(t, FollowUser(2, 2))
|
|
||||||
|
|
||||||
unittest.CheckConsistencyFor(t, &User{})
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestUnfollowUser(t *testing.T) {
|
|
||||||
assert.NoError(t, unittest.PrepareTestDatabase())
|
|
||||||
|
|
||||||
testSuccess := func(followerID, followedID int64) {
|
|
||||||
assert.NoError(t, UnfollowUser(followerID, followedID))
|
|
||||||
unittest.AssertNotExistsBean(t, &Follow{UserID: followerID, FollowID: followedID})
|
|
||||||
}
|
|
||||||
testSuccess(4, 2)
|
|
||||||
testSuccess(5, 2)
|
|
||||||
testSuccess(2, 2)
|
|
||||||
|
|
||||||
unittest.CheckConsistencyFor(t, &User{})
|
|
||||||
}
|
|
|
@ -560,3 +560,51 @@ func TestNewUserRedirect3(t *testing.T) {
|
||||||
RedirectUserID: user.ID,
|
RedirectUserID: user.ID,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestFollowUser(t *testing.T) {
|
||||||
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||||
|
|
||||||
|
testSuccess := func(followerID, followedID int64) {
|
||||||
|
assert.NoError(t, user_model.FollowUser(followerID, followedID))
|
||||||
|
unittest.AssertExistsAndLoadBean(t, &user_model.Follow{UserID: followerID, FollowID: followedID})
|
||||||
|
}
|
||||||
|
testSuccess(4, 2)
|
||||||
|
testSuccess(5, 2)
|
||||||
|
|
||||||
|
assert.NoError(t, user_model.FollowUser(2, 2))
|
||||||
|
|
||||||
|
unittest.CheckConsistencyFor(t, &User{})
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestUnfollowUser(t *testing.T) {
|
||||||
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||||
|
|
||||||
|
testSuccess := func(followerID, followedID int64) {
|
||||||
|
assert.NoError(t, user_model.UnfollowUser(followerID, followedID))
|
||||||
|
unittest.AssertNotExistsBean(t, &user_model.Follow{UserID: followerID, FollowID: followedID})
|
||||||
|
}
|
||||||
|
testSuccess(4, 2)
|
||||||
|
testSuccess(5, 2)
|
||||||
|
testSuccess(2, 2)
|
||||||
|
|
||||||
|
unittest.CheckConsistencyFor(t, &User{})
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGetUserByOpenID(t *testing.T) {
|
||||||
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||||
|
|
||||||
|
_, err := GetUserByOpenID("https://unknown")
|
||||||
|
if assert.Error(t, err) {
|
||||||
|
assert.True(t, IsErrUserNotExist(err))
|
||||||
|
}
|
||||||
|
|
||||||
|
user, err := GetUserByOpenID("https://user1.domain1.tld")
|
||||||
|
if assert.NoError(t, err) {
|
||||||
|
assert.Equal(t, int64(1), user.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
user, err = GetUserByOpenID("https://domain1.tld/user2/")
|
||||||
|
if assert.NoError(t, err) {
|
||||||
|
assert.Equal(t, int64(2), user.ID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -9,6 +9,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"code.gitea.io/gitea/models"
|
"code.gitea.io/gitea/models"
|
||||||
|
user_model "code.gitea.io/gitea/models/user"
|
||||||
"code.gitea.io/gitea/modules/context"
|
"code.gitea.io/gitea/modules/context"
|
||||||
"code.gitea.io/gitea/modules/convert"
|
"code.gitea.io/gitea/modules/convert"
|
||||||
api "code.gitea.io/gitea/modules/structs"
|
api "code.gitea.io/gitea/modules/structs"
|
||||||
|
@ -239,7 +240,7 @@ func Follow(ctx *context.APIContext) {
|
||||||
if ctx.Written() {
|
if ctx.Written() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err := models.FollowUser(ctx.User.ID, target.ID); err != nil {
|
if err := user_model.FollowUser(ctx.User.ID, target.ID); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "FollowUser", err)
|
ctx.Error(http.StatusInternalServerError, "FollowUser", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -265,7 +266,7 @@ func Unfollow(ctx *context.APIContext) {
|
||||||
if ctx.Written() {
|
if ctx.Written() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err := models.UnfollowUser(ctx.User.ID, target.ID); err != nil {
|
if err := user_model.UnfollowUser(ctx.User.ID, target.ID); err != nil {
|
||||||
ctx.Error(http.StatusInternalServerError, "UnfollowUser", err)
|
ctx.Error(http.StatusInternalServerError, "UnfollowUser", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,7 @@ import (
|
||||||
"net/url"
|
"net/url"
|
||||||
|
|
||||||
"code.gitea.io/gitea/models"
|
"code.gitea.io/gitea/models"
|
||||||
|
user_model "code.gitea.io/gitea/models/user"
|
||||||
"code.gitea.io/gitea/modules/auth/openid"
|
"code.gitea.io/gitea/modules/auth/openid"
|
||||||
"code.gitea.io/gitea/modules/base"
|
"code.gitea.io/gitea/modules/base"
|
||||||
"code.gitea.io/gitea/modules/context"
|
"code.gitea.io/gitea/modules/context"
|
||||||
|
@ -302,9 +303,9 @@ func ConnectOpenIDPost(ctx *context.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// add OpenID for the user
|
// add OpenID for the user
|
||||||
userOID := &models.UserOpenID{UID: u.ID, URI: oid}
|
userOID := &user_model.UserOpenID{UID: u.ID, URI: oid}
|
||||||
if err = models.AddUserOpenID(userOID); err != nil {
|
if err = user_model.AddUserOpenID(userOID); err != nil {
|
||||||
if models.IsErrOpenIDAlreadyUsed(err) {
|
if user_model.IsErrOpenIDAlreadyUsed(err) {
|
||||||
ctx.RenderWithErr(ctx.Tr("form.openid_been_used", oid), tplConnectOID, &form)
|
ctx.RenderWithErr(ctx.Tr("form.openid_been_used", oid), tplConnectOID, &form)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -430,9 +431,9 @@ func RegisterOpenIDPost(ctx *context.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// add OpenID for the user
|
// add OpenID for the user
|
||||||
userOID := &models.UserOpenID{UID: u.ID, URI: oid}
|
userOID := &user_model.UserOpenID{UID: u.ID, URI: oid}
|
||||||
if err = models.AddUserOpenID(userOID); err != nil {
|
if err = user_model.AddUserOpenID(userOID); err != nil {
|
||||||
if models.IsErrOpenIDAlreadyUsed(err) {
|
if user_model.IsErrOpenIDAlreadyUsed(err) {
|
||||||
ctx.RenderWithErr(ctx.Tr("form.openid_been_used", oid), tplSignUpOID, &form)
|
ctx.RenderWithErr(ctx.Tr("form.openid_been_used", oid), tplSignUpOID, &form)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -131,7 +131,7 @@ func Profile(ctx *context.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Show OpenID URIs
|
// Show OpenID URIs
|
||||||
openIDs, err := models.GetUserOpenIDs(ctxUser.ID)
|
openIDs, err := user_model.GetUserOpenIDs(ctxUser.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("GetUserOpenIDs", err)
|
ctx.ServerError("GetUserOpenIDs", err)
|
||||||
return
|
return
|
||||||
|
@ -355,9 +355,9 @@ func Action(ctx *context.Context) {
|
||||||
var err error
|
var err error
|
||||||
switch ctx.Params(":action") {
|
switch ctx.Params(":action") {
|
||||||
case "follow":
|
case "follow":
|
||||||
err = models.FollowUser(ctx.User.ID, u.ID)
|
err = user_model.FollowUser(ctx.User.ID, u.ID)
|
||||||
case "unfollow":
|
case "unfollow":
|
||||||
err = models.UnfollowUser(ctx.User.ID, u.ID)
|
err = user_model.UnfollowUser(ctx.User.ID, u.ID)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -10,6 +10,7 @@ import (
|
||||||
|
|
||||||
"code.gitea.io/gitea/models"
|
"code.gitea.io/gitea/models"
|
||||||
"code.gitea.io/gitea/models/login"
|
"code.gitea.io/gitea/models/login"
|
||||||
|
user_model "code.gitea.io/gitea/models/user"
|
||||||
"code.gitea.io/gitea/modules/base"
|
"code.gitea.io/gitea/modules/base"
|
||||||
"code.gitea.io/gitea/modules/context"
|
"code.gitea.io/gitea/modules/context"
|
||||||
"code.gitea.io/gitea/modules/setting"
|
"code.gitea.io/gitea/modules/setting"
|
||||||
|
@ -107,7 +108,7 @@ func loadSecurityData(ctx *context.Context) {
|
||||||
}
|
}
|
||||||
ctx.Data["AccountLinks"] = sources
|
ctx.Data["AccountLinks"] = sources
|
||||||
|
|
||||||
openid, err := models.GetUserOpenIDs(ctx.User.ID)
|
openid, err := user_model.GetUserOpenIDs(ctx.User.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("GetUserOpenIDs", err)
|
ctx.ServerError("GetUserOpenIDs", err)
|
||||||
return
|
return
|
||||||
|
|
|
@ -7,7 +7,7 @@ package setting
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"code.gitea.io/gitea/models"
|
user_model "code.gitea.io/gitea/models/user"
|
||||||
"code.gitea.io/gitea/modules/auth/openid"
|
"code.gitea.io/gitea/modules/auth/openid"
|
||||||
"code.gitea.io/gitea/modules/context"
|
"code.gitea.io/gitea/modules/context"
|
||||||
"code.gitea.io/gitea/modules/log"
|
"code.gitea.io/gitea/modules/log"
|
||||||
|
@ -45,7 +45,7 @@ func OpenIDPost(ctx *context.Context) {
|
||||||
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 := user_model.GetUserOpenIDs(ctx.User.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.ServerError("GetUserOpenIDs", err)
|
ctx.ServerError("GetUserOpenIDs", err)
|
||||||
return
|
return
|
||||||
|
@ -89,9 +89,9 @@ 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 := &user_model.UserOpenID{UID: ctx.User.ID, URI: id}
|
||||||
if err = models.AddUserOpenID(oid); err != nil {
|
if err = user_model.AddUserOpenID(oid); err != nil {
|
||||||
if models.IsErrOpenIDAlreadyUsed(err) {
|
if user_model.IsErrOpenIDAlreadyUsed(err) {
|
||||||
ctx.RenderWithErr(ctx.Tr("form.openid_been_used", id), tplSettingsSecurity, &forms.AddOpenIDForm{Openid: id})
|
ctx.RenderWithErr(ctx.Tr("form.openid_been_used", id), tplSettingsSecurity, &forms.AddOpenIDForm{Openid: id})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -106,7 +106,7 @@ func settingsOpenIDVerify(ctx *context.Context) {
|
||||||
|
|
||||||
// DeleteOpenID response for delete user's openid
|
// DeleteOpenID response for delete user's openid
|
||||||
func DeleteOpenID(ctx *context.Context) {
|
func DeleteOpenID(ctx *context.Context) {
|
||||||
if err := models.DeleteUserOpenID(&models.UserOpenID{ID: ctx.FormInt64("id"), UID: ctx.User.ID}); err != nil {
|
if err := user_model.DeleteUserOpenID(&user_model.UserOpenID{ID: ctx.FormInt64("id"), UID: ctx.User.ID}); err != nil {
|
||||||
ctx.ServerError("DeleteUserOpenID", err)
|
ctx.ServerError("DeleteUserOpenID", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -120,7 +120,7 @@ func DeleteOpenID(ctx *context.Context) {
|
||||||
|
|
||||||
// ToggleOpenIDVisibility response for toggle visibility of user's openid
|
// ToggleOpenIDVisibility response for toggle visibility of user's openid
|
||||||
func ToggleOpenIDVisibility(ctx *context.Context) {
|
func ToggleOpenIDVisibility(ctx *context.Context) {
|
||||||
if err := models.ToggleUserOpenIDVisibility(ctx.FormInt64("id")); err != nil {
|
if err := user_model.ToggleUserOpenIDVisibility(ctx.FormInt64("id")); err != nil {
|
||||||
ctx.ServerError("ToggleUserOpenIDVisibility", err)
|
ctx.ServerError("ToggleUserOpenIDVisibility", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue