mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 08:30:25 +08:00 
			
		
		
		
	first works oauth2(github). need to login with /user/login/github
This commit is contained in:
		@@ -1,6 +1,6 @@
 | 
			
		||||
package models
 | 
			
		||||
 | 
			
		||||
import "time"
 | 
			
		||||
import "fmt"
 | 
			
		||||
 | 
			
		||||
// OT: Oauth2 Type
 | 
			
		||||
const (
 | 
			
		||||
@@ -10,9 +10,30 @@ const (
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type Oauth2 struct {
 | 
			
		||||
	Uid         int64     `xorm:"pk"`               // userId
 | 
			
		||||
	Type        int       `xorm:"pk unique(oauth)"` // twitter,github,google...
 | 
			
		||||
	Identity    string    `xorm:"pk unique(oauth)"` // id..
 | 
			
		||||
	Token       string    `xorm:"VARCHAR(200) not null"`
 | 
			
		||||
	RefreshTime time.Time `xorm:"created"`
 | 
			
		||||
	Uid      int64  `xorm:"pk"`               // userId
 | 
			
		||||
	Type     int    `xorm:"pk unique(oauth)"` // twitter,github,google...
 | 
			
		||||
	Identity string `xorm:"pk unique(oauth)"` // id..
 | 
			
		||||
	Token    string `xorm:"VARCHAR(200) not null"`
 | 
			
		||||
	//RefreshTime time.Time `xorm:"created"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func AddOauth2(oa *Oauth2) (err error) {
 | 
			
		||||
	if _, err = orm.Insert(oa); err != nil {
 | 
			
		||||
		return err
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func GetOauth2User(identity string) (u *User, err error) {
 | 
			
		||||
	oa := &Oauth2{}
 | 
			
		||||
	oa.Identity = identity
 | 
			
		||||
	exists, err := orm.Get(oa)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	if !exists {
 | 
			
		||||
		err = fmt.Errorf("not exists oauth2: %s", identity)
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	return GetUserById(oa.Uid)
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user