本文整理匯總了Golang中github.com/pritunl/pritunl-auth/database.Database.Accounts方法的典型用法代碼示例。如果您正苦於以下問題:Golang Database.Accounts方法的具體用法?Golang Database.Accounts怎麽用?Golang Database.Accounts使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/pritunl/pritunl-auth/database.Database
的用法示例。
在下文中一共展示了Database.Accounts方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Authorize
func Authorize(db *database.Database, state string,
code string) (acct *account.Account, tokn *oauth.Token, err error) {
coll := db.Accounts()
acct, tokn, err = conf.Authorize(db, state, code)
if err != nil {
return
}
client := &GoogleClient{
acct: acct,
}
err = client.Update(db)
if err != nil {
return
}
_, err = coll.Upsert(&bson.M{
"_id": acct.Id,
}, acct)
if err != nil {
err = database.ParseError(err)
return
}
return
}
示例2: Refresh
func (c *Oauth2Client) Refresh(db *database.Database) (err error) {
refreshed, err := c.Check()
if err != nil {
return
}
if !refreshed {
return
}
coll := db.Accounts()
c.Account.Oauth2AccTokn = c.AccessToken
c.Account.Oauth2RefTokn = c.RefreshToken
c.Account.Oauth2Exp = c.Expiry
if c.Account.Id == "" {
return
}
fields := set.NewSet("oauth2_acc_tokn", "oauth2_ref_tokn", "oauth2_exp")
err = coll.CommitFields(c.Account.Id, c.Account, fields)
if err != nil {
err = database.ParseError(err)
return
}
return
}
示例3: Update
func Update(db *database.Database, user string) (err error) {
coll := db.Accounts()
acct := &account.Account{}
err = coll.FindOneId(user, acct)
if err != nil {
return
}
client := &GoogleClient{
acct: acct,
}
err = client.Update(db)
if err != nil {
return
}
_, err = coll.Upsert(&bson.M{
"_id": acct.Id,
}, acct)
if err != nil {
err = database.ParseError(err)
return
}
return
}