本文整理匯總了Golang中github.com/tsuru/tsuru/auth.User.CreateOnGandalf方法的典型用法代碼示例。如果您正苦於以下問題:Golang User.CreateOnGandalf方法的具體用法?Golang User.CreateOnGandalf怎麽用?Golang User.CreateOnGandalf使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/tsuru/tsuru/auth.User
的用法示例。
在下文中一共展示了User.CreateOnGandalf方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: createUser
func createUser(w http.ResponseWriter, r *http.Request) error {
registrationEnabled, _ := config.GetBool("auth:user-registration")
if !registrationEnabled {
token := r.Header.Get("Authorization")
t, err := app.AuthScheme.Auth(token)
if err != nil {
return createDisabledErr
}
user, err := t.User()
if err != nil {
return createDisabledErr
}
if !user.IsAdmin() {
return createDisabledErr
}
}
var u auth.User
err := json.NewDecoder(r.Body).Decode(&u)
if err != nil {
return &errors.HTTP{Code: http.StatusBadRequest, Message: err.Error()}
}
_, err = app.AuthScheme.Create(&u)
if err != nil {
return handleAuthError(err)
}
err = u.CreateOnGandalf()
if err != nil {
return err
}
rec.Log(u.Email, "create-user")
w.WriteHeader(http.StatusCreated)
return nil
}
示例2: PutToken
func (c *DBTokenCache) PutToken(t *goauth2.Token) error {
if t.AccessToken == "" {
return ErrEmptyAccessToken
}
var email string
if t.Extra == nil || t.Extra["email"] == "" {
conf, err := c.scheme.loadConfig()
if err != nil {
return err
}
transport := &goauth2.Transport{Config: &conf}
transport.Token = t
client := transport.Client()
response, err := client.Get(c.scheme.InfoUrl)
if err != nil {
return err
}
email, err = c.scheme.Parser.Parse(response)
if email == "" {
return ErrEmptyUserEmail
}
_, err = auth.GetUserByEmail(email)
if err != nil {
if err != auth.ErrUserNotFound {
return err
}
registrationEnabled, _ := config.GetBool("auth:user-registration")
if !registrationEnabled {
return err
}
user := auth.User{Email: email}
err := user.Create()
if err != nil {
return err
}
err = user.CreateOnGandalf()
if err != nil {
return err
}
}
t.Extra = make(map[string]string)
t.Extra["email"] = email
}
return makeToken(t).save()
}
示例3: createUser
func createUser(w http.ResponseWriter, r *http.Request) error {
var u auth.User
err := json.NewDecoder(r.Body).Decode(&u)
if err != nil {
return &errors.HTTP{Code: http.StatusBadRequest, Message: err.Error()}
}
_, err = app.AuthScheme.Create(&u)
if err != nil {
return handleAuthError(err)
}
err = u.CreateOnGandalf()
if err != nil {
return err
}
rec.Log(u.Email, "create-user")
w.WriteHeader(http.StatusCreated)
return nil
}