本文整理汇总了Golang中github.com/astaxie/beego/context.Context.Redirect方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.Redirect方法的具体用法?Golang Context.Redirect怎么用?Golang Context.Redirect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/astaxie/beego/context.Context
的用法示例。
在下文中一共展示了Context.Redirect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: FilterUser
func FilterUser(ctx *context.Context) {
if (ctx.Input.IsGet() || ctx.Input.IsPost()) && (ctx.Input.URL() == loginPageURL || ctx.Input.URL() == logoutPageURL) {
// Don't redirect itself to prevent the circle
} else {
user, ok := ctx.Input.Session("user").(*rbac.User)
if ok == false {
if guiMessage := guimessagedisplay.GetGUIMessageFromContext(ctx); guiMessage != nil {
guiMessage.AddDanger("Unauthorized")
}
ctx.Redirect(302, loginPageURL)
} else {
// Authorize
if user.HasPermission(componentName, ctx.Input.Method(), ctx.Input.URL()) == false {
if guiMessage := guimessagedisplay.GetGUIMessageFromContext(ctx); guiMessage != nil {
guiMessage.AddDanger("User is not authorized to this page. Please use another user with priviledge.")
}
ctx.Redirect(302, loginPageURL)
}
// Resource check is in another place since GUI doesn't place the resource name in url
// Audit log
go func() {
sendAuditLog(ctx, user.Name, true)
}()
}
}
}
示例2: HandleAccess
func HandleAccess(ctx *context.Context) {
token := ctx.GetCookie("epic_user_token")
ok, _ := tools.VerifyToken(token)
if len(token) != 0 && ok {
ctx.Redirect(302, "/succeed")
}
}
示例3: ViewLogin
func ViewLogin(c *context.Context) {
cookie := c.GetCookie("MtimeCIUserId")
if len(cookie) <= 0 {
c.Redirect(302, "/login?url="+url.QueryEscape(c.Input.Uri()))
}
beego.Informational(cookie)
}
示例4: checkLogin
// 检测登录,跳转登录界面
func checkLogin(c *context.Context) {
uid, ok := c.Input.Session("uid").(int64)
if !ok || uid <= 0 {
if c.Request.RequestURI != "/login" {
c.Redirect(302, "/login")
}
}
}
示例5: FilterAuth
// FilterAuth prevents the user from accessing protected pages if they are not
// logged in.
func FilterAuth(ctx *context.Context) {
if ctx.Input.GetData("user") == nil {
ctx.Redirect(302, fmt.Sprintf(
"%s?redirect=%s",
beego.URLFor("UserController.Login"),
url.QueryEscape(ctx.Request.URL.Path),
))
}
}
示例6: loginFilter
func loginFilter(ctx *context.Context) {
user := ctx.Input.CruSession.Get("user")
//user := this.GetSession("user")
fmt.Println("loginFilter user")
fmt.Println(user)
if user == nil && ctx.Request.RequestURI != "/" && ctx.Request.RequestURI != "/login" {
ctx.Redirect(302, "/")
}
}
示例7: OAuthAccess
func OAuthAccess(ctx *context.Context) {
redirect, _, err := setting.SocialAuth.OAuthAccess(ctx)
if err != nil {
beego.Error("OAuthAccess", err)
}
if len(redirect) > 0 {
ctx.Redirect(302, redirect)
}
}
示例8: HandleRedirect
func HandleRedirect(ctx *context.Context) {
redirect, err := SocialAuth.OAuthRedirect(ctx)
if err != nil {
beego.Error("SocialAuth.handleRedirect", err)
}
if len(redirect) > 0 {
ctx.Redirect(302, redirect)
}
}
示例9: handleAccess
// general use of redirect callback
func (this *SocialAuth) handleAccess(ctx *context.Context) {
redirect, _, err := this.OAuthAccess(ctx)
if err != nil {
beego.Error("SocialAuth.handleAccess", err)
}
if len(redirect) > 0 {
ctx.Redirect(302, redirect)
}
}
示例10: FilterUser
func FilterUser(ctx *context.Context) {
adminUrl := []string{"organizations", "users", "reports"}
for _, url := range adminUrl {
if strings.Contains(ctx.Request.RequestURI, url) {
if adminUser, ok := ctx.Input.Session("adminUser").(string); !ok || adminUser != beego.AppConfig.String("conf::admin_user") {
ctx.Redirect(302, "/login")
}
return
}
}
}
示例11: CheckLogin
func CheckLogin(ctx *context.Context) {
if ctx.Request.RequestURI != "/login" {
sess, err := models.GlobalSessions.SessionStart(ctx.ResponseWriter, ctx.Request)
if err != nil || sess == nil {
ctx.Abort(401, "session nil")
}
sessioner := sess.Get("gosessionkey")
beego.Debug("session:", sess)
beego.Debug("check login gosessionkey:", sessioner)
if fmt.Sprintf("%v", sessioner) != "beego1234" {
ctx.Redirect(401, "/login")
}
}
}
示例12: filterUser
func filterUser(ctx *context.Context) {
u, ok := ctx.Input.Session("current_user").(*goth.User)
if !ok {
ctx.Redirect(302, "/login")
}
if gu := ctx.Input.GetData("github_user"); gu == nil {
g, err := github.GetCurrentUser(u.AccessToken)
if err != nil {
ctx.Redirect(302, "/404.html")
}
ctx.Input.SetData("github_user", g)
}
}
示例13: HandleAccess
func HandleAccess(ctx *context.Context) {
redirect, userSocial, err := SocialAuth.OAuthAccess(ctx)
if err != nil {
beego.Error("SocialAuth.handleAccess", err)
}
if userSocial != nil {
SetInfoToSession(ctx, userSocial)
}
if len(redirect) > 0 {
ctx.Redirect(302, redirect)
}
}
示例14: HandleAccess
func HandleAccess(ctx *context.Context) {
redirect, userSocial, err := SocialAuth.OAuthAccess(ctx)
if err != nil {
beego.Error("SocialAuth.handleAccess", err)
}
if userSocial != nil {
fmt.Println("Identify: %s, AccessToken: %s", userSocial.Identify, userSocial.Data.AccessToken)
}
ctx.Input.CruSession.Set("custom_userSocial_identify", userSocial.Identify)
if len(redirect) > 0 {
ctx.Redirect(302, redirect)
}
}
示例15: FilterCheckLogin
func FilterCheckLogin(ctx *context.Context) {
url := ctx.Request.RequestURI
if strings.HasPrefix(url, "/user") || "" == url || strings.HasPrefix(url, "/api") {
return
}
userId, ok := ctx.Input.Session(cache.SESSION_UID).(int64)
user := models.GetUserById(userId)
if !ok || nil == user {
ctx.Output.Session("originURL", ctx.Request.RequestURI)
ctx.Redirect(302, "/user/login")
} else if strings.HasPrefix(url, "/root") && "ADMIN" != user.RoleName {
ctx.Redirect(302, "/user/nopermission")
}
}