本文整理匯總了Golang中github.com/revel/revel.Controller.Redirect方法的典型用法代碼示例。如果您正苦於以下問題:Golang Controller.Redirect方法的具體用法?Golang Controller.Redirect怎麽用?Golang Controller.Redirect使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/revel/revel.Controller
的用法示例。
在下文中一共展示了Controller.Redirect方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: AuthInterceptor
func AuthInterceptor(c *revel.Controller) revel.Result {
// 全部變成首字大寫
/*
var controller = strings.Title(c.Name)
var method = strings.Title(c.MethodName)
// 是否需要驗證?
if !needValidate(controller, method) {
return nil
}
*/
// 驗證是否已登錄
// 必須是管理員
if username, ok := c.Session["Username"]; ok && username == configService.GetAdminUsername() {
return nil // 已登錄
}
// 沒有登錄, 判斷是否是ajax操作
if c.Request.Header.Get("X-Requested-With") == "XMLHttpRequest" {
re := info.NewRe()
re.Msg = "NOTLOGIN"
return c.RenderJson(re)
}
return c.Redirect("/login")
}
示例2: CheckUserAuth
func CheckUserAuth(controller *revel.Controller) revel.Result {
if controller.Action == "Static.Serve" ||
controller.Action == "App.Login" ||
controller.Action == "User.Login" ||
controller.Action == "User.Logout" {
return nil
}
var (
userAuth = new(security.UserAuth)
username string
sessionData = *security.GetSessionData(&controller.Session)
)
security.AuthCache.Get(controller.Session.Id(), userAuth)
if v, ok := sessionData["username"]; ok {
username = v.(string)
}
if userAuth != nil && username != "" && userAuth.Equal(security.UserAuthGenerate(controller.Request)) {
return nil
}
controller.Flash.Error("Please log in first")
controller.Response.Out.Header().Set("Requires-Auth", "1")
// controller.Response.Status = 401
return controller.Redirect((*User).Login)
}
示例3: checkUser
func checkUser(c *revel.Controller) revel.Result {
if _, ok := c.Session["user"]; ok {
return nil
}
c.Flash.Error(c.Message("login.message.notloggedin"))
return c.Redirect(routes.App.Login())
}
示例4: adminOnly
func adminOnly(c *revel.Controller) revel.Result {
if c.Session["usertype"] == "ADMIN" {
return nil
}
c.Flash.Error(c.Message("access.message.notallowed"))
return c.Redirect(routes.App.Index())
}
示例5: CheckLoginAdmin
func CheckLoginAdmin(c *revel.Controller) revel.Result {
if c.Session[LOGIN_USERID] == "" || models.Role(c.Session[LOGIN_USERROLE]) != models.ROLE_SUPER_ADMIN {
return c.Redirect(
revel.MainRouter.Reverse("Auth.Login", map[string]string{}).Url,
)
}
return nil
}
示例6: CheckLogin
// func init() {
// revel.InterceptFunc(CheckLogin, revel.BEFORE, &App{})
// }
func CheckLogin(c *revel.Controller) revel.Result {
if c.Session[LOGIN_USERID] == "" {
return c.Redirect(
revel.MainRouter.Reverse("Auth.Login", map[string]string{}).Url,
)
}
return nil
}
示例7: Search
// search certain content
func Search(key string, c *revel.Controller) revel.Result {
var problems []models.Problem
err := engine.Where("title = ? ", key).Find(&problems)
if err != nil {
c.Flash.Error("error %s", err.Error())
c.Redirect(routes.Notice.Crash())
}
return c.Render(problems)
}
示例8: authenticate
//authentication check
func authenticate(c *revel.Controller) revel.Result {
if inStringSlice(strings.ToLower(c.Action),
adminPermission) {
if !adminAuthentication(c) {
c.Flash.Error("you are not admin")
return c.Redirect("/")
}
}
if inStringSlice(strings.ToLower(c.Action),
userPermission) {
if ok := connected(c); !ok {
c.Flash.Error("please login first")
return c.Redirect(routes.Account.Login())
} else {
return nil
}
}
if inStringSlice(strings.ToLower(c.Action),
logoutCheck) {
if ok := connected(c); ok {
c.Flash.Error("can not repeat login")
return c.Redirect("/")
} else {
return nil
}
}
return nil
}
示例9: CheckLogin
//檢測登陸
func CheckLogin(c *revel.Controller) revel.Result {
//登陸頁麵,CSS, JS, Ajax, 驗證碼頁麵 都不進行登陸驗證
if c.Name == "User" && c.MethodName == "Login" || c.Name == "Ajax" || c.Name == "Static" || c.Name == "Captcha" || c.Name == "Kindeditor" {
if LANG, ok := c.Session["Lang"]; ok {
//設置語言
c.RenderArgs["currentLocale"] = LANG
} else {
//設置默認語言
c.RenderArgs["currentLocale"] = "zh"
}
return nil
} else {
UserID := utils.GetSession("UserID", c.Session)
if len(UserID) > 0 {
UserID, err := strconv.ParseInt(UserID, 10, 64)
if err != nil {
revel.WARN.Println(err)
return c.Redirect("/Login/")
}
admin := new(models.Admin)
admin_info := admin.GetById(UserID)
if admin_info.Id <= 0 {
return c.Redirect("/Login/")
}
//控製器
c.RenderArgs["Controller"] = c.Name
//動作
c.RenderArgs["action"] = c.Action
//模型
c.RenderArgs["Model"] = c.MethodName
//登陸信息
c.RenderArgs["admin_info"] = admin_info
//設置語言
c.RenderArgs["currentLocale"] = admin_info.Lang
} else {
//控製器
c.RenderArgs["Controller"] = c.Name
//動作
c.RenderArgs["action"] = c.Action
//模型
c.RenderArgs["Model"] = c.MethodName
return c.Redirect("/Login/")
}
}
return nil
}
示例10: checkRole
func checkRole(this *revel.Controller) revel.Result {
pv := models.PV{
IP: this.Request.Host,
Page: this.Action,
TimeStamp: time.Now().Format("2006-01-02 15:04:05")}
addPV(pv)
// 設置遊客的訪問權限
if this.Session["administrator"] == "" {
if this.Action == "Admin.SignIn" ||
this.Action == "Picture.Show" ||
this.Action == "Picture.Search" ||
this.Action == "Picture.AddComment" ||
this.Action == "Picture.UploadForCheck" ||
this.Action == "Picture.PostUploadForCheck" ||
this.Action == "Picture.UniversityPictureNums" {
return nil
} else {
this.Flash.Success("需要管理員身份才能訪問該頁麵。")
log.Println("遊客訪問了 " + this.Action + " 頁麵,已自動跳轉到首頁")
return this.Redirect(controllers.App.Index)
}
}
// 設置管理員的訪問權限
if this.Session["administrator"] == "true" {
if this.Action == "Admin.SignIn" {
this.Flash.Success("您已經登錄,請先注銷再登錄。")
log.Println("管理員訪問了登錄頁麵,已自動跳轉到首頁")
return this.Redirect(controllers.App.Index)
} else {
log.Println("管理員 " + this.Session["administrator"] + " 訪問了 " + this.Action + " 頁麵")
return nil
}
}
return this.Redirect(controllers.Admin.SignIn)
}