本文整理汇总了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
}