本文整理匯總了Golang中einvite/framework.WebContext.FrameworkError方法的典型用法代碼示例。如果您正苦於以下問題:Golang WebContext.FrameworkError方法的具體用法?Golang WebContext.FrameworkError怎麽用?Golang WebContext.FrameworkError使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類einvite/framework.WebContext
的用法示例。
在下文中一共展示了WebContext.FrameworkError方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: AuthCallback
// Function that handles the callback from the Google server
func (this *FacebookController) AuthCallback(ctx framework.WebContext) framework.WebResult {
//Get the code from the response
code, _ := ctx.Param("code")
t := &oauth.Transport{Config: this.oauthCfg}
// Exchange the received code for a token
t.Exchange(code)
//now get user data based on the Transport which has the token
resp, err := t.Client().Get(this.profileInfoURL)
if err != nil {
log.Println(err)
return ctx.FrameworkError(framework.ToError(framework.Error_Web_UnableToAuthenticate, err))
}
userprofile := make(map[string]interface{})
decoder := json.NewDecoder(resp.Body)
err = decoder.Decode(&userprofile)
if err != nil {
log.Println(err)
return ctx.FrameworkError(framework.ToError(framework.Error_Web_UnableToAuthenticate, err))
}
fmt.Println(userprofile)
email := userprofile["email"].(string)
name := userprofile["name"].(string)
userDto := &contracts.User{Email: email, Name: name}
userCredentialsDto := &contracts.UserAuthCredentials{
Type: framework.AuthType_Facebook,
AccessToken: t.Token.AccessToken,
RefreshToken: t.Token.RefreshToken,
Expiry: t.Token.Expiry,
}
user, err2 := this.userService.SaveWithCredentials(userDto, userCredentialsDto)
if err2 != nil {
return ctx.Error(err2)
}
ctx.Session().SetUser(&framework.SessionUser{
UserId: user.Email,
AuthType: framework.AuthType_Facebook,
AuthData: t.AccessToken,
})
return ctx.Template(userInfoTemplate, fmt.Sprintf("Name: %s Email: %s", name, email))
}