|
|
@ -1,3 +1,7 @@ |
|
|
|
|
|
|
|
// Copyright 2014 The Gogs 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 |
|
|
|
package models |
|
|
|
|
|
|
|
|
|
|
|
import "errors" |
|
|
|
import "errors" |
|
|
@ -16,7 +20,7 @@ var ( |
|
|
|
|
|
|
|
|
|
|
|
type Oauth2 struct { |
|
|
|
type Oauth2 struct { |
|
|
|
Id int64 |
|
|
|
Id int64 |
|
|
|
Uid int64 `xorm:"pk"` // userId
|
|
|
|
Uid int64 // userId
|
|
|
|
User *User `xorm:"-"` |
|
|
|
User *User `xorm:"-"` |
|
|
|
Type int `xorm:"pk unique(oauth)"` // twitter,github,google...
|
|
|
|
Type int `xorm:"pk unique(oauth)"` // twitter,github,google...
|
|
|
|
Identity string `xorm:"pk unique(oauth)"` // id..
|
|
|
|
Identity string `xorm:"pk unique(oauth)"` // id..
|
|
|
@ -31,18 +35,14 @@ func AddOauth2(oa *Oauth2) (err error) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func GetOauth2(identity string) (oa *Oauth2, err error) { |
|
|
|
func GetOauth2(identity string) (oa *Oauth2, err error) { |
|
|
|
oa = &Oauth2{} |
|
|
|
oa = &Oauth2{Identity: identity} |
|
|
|
oa.Identity = identity |
|
|
|
isExist, err := orm.Get(oa) |
|
|
|
exists, err := orm.Get(oa) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} else if !isExist { |
|
|
|
if !exists { |
|
|
|
|
|
|
|
return nil, ErrOauth2RecordNotExists |
|
|
|
return nil, ErrOauth2RecordNotExists |
|
|
|
} |
|
|
|
} else if oa.Uid == 0 { |
|
|
|
if oa.Uid == 0 { |
|
|
|
|
|
|
|
return oa, ErrOauth2NotAssociatedWithUser |
|
|
|
return oa, ErrOauth2NotAssociatedWithUser |
|
|
|
} |
|
|
|
} |
|
|
|
oa.User, err = GetUserById(oa.Uid) |
|
|
|
return GetUserById(oa.Uid) |
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|