当前位置: 首页>>代码示例>>Golang>>正文


Golang Render.Redirect方法代码示例

本文整理汇总了Golang中github.com/martini-contrib/render.Render.Redirect方法的典型用法代码示例。如果您正苦于以下问题:Golang Render.Redirect方法的具体用法?Golang Render.Redirect怎么用?Golang Render.Redirect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/martini-contrib/render.Render的用法示例。


在下文中一共展示了Render.Redirect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: Login

func Login(session sessions.Session, su models.User, r render.Render, p *models.Page) {

	// Check if we are already logged in
	if su.Id > 0 {
		r.Redirect(strings.Join([]string{utils.AppCfg.Url(), "albums"}, "/"), http.StatusFound)
		return
	}

	session.Set("loggedin", "false")

	// Init error holder
	errs := make(map[string]string)

	err_flash := session.Get("flash")
	if err_flash != nil {
		errs["flash"] = err_flash.(string)
		session.Set("flash", nil)
	}

	genform := utils.GenerateForm(&forms.Login{}, "/login", "POST", errs)

	p.SetUser(su)
	p.SetTitle("Login")
	p.Data = LoginVars{Form: genform}

	encoder.Render(p.Encoding, 200, "login", p, r)
}
开发者ID:szwork2013,项目名称:gopixelrelay,代码行数:27,代码来源:login.go

示例2: Login

func Login(session sessions.Session, re render.Render, r *http.Request) {
	client_id := common.Config.OAuth2Client_ID

	letters := []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")

	b := make([]rune, 10)
	for i := range b {
		b[i] = letters[rand.Intn(len(letters))]
	}
	session.AddFlash(string(b), "state")

	redirectBack := r.URL.Query().Get("redirect_back")
	ref := r.Referer()

	if redirectBack == "true" && ref != "" {
		session.Set("redirect_to", ref)
	} else {
		session.Set("redirect_to", nil)
	}

	query := url.Values{}
	query.Set("client_id", client_id)
	query.Set("state", string(b))
	query.Set("scope", "repo")

	dest := url.URL{
		Scheme:   "https",
		Host:     "github.com",
		Path:     "/login/oauth/authorize",
		RawQuery: query.Encode(),
	}
	re.Redirect(dest.String())
}
开发者ID:SemQuery,项目名称:web,代码行数:33,代码来源:session.go

示例3: getLoginPage

func getLoginPage(user sessionauth.User, r render.Render) {
	if user.IsAuthenticated() {
		r.Redirect(INDEX_PAGE)
		return
	}
	r.HTML(200, LOGIN_PAGE, nil)
}
开发者ID:jmptrader,项目名称:chatgo,代码行数:7,代码来源:user.go

示例4: UpdatePlant

func UpdatePlant(ren render.Render, mediaManager *media.Manager, r *http.Request, db *sql.DB, params martini.Params, sessionMessages *template.Messages) {
	id, _ := strconv.ParseInt(params["id"], 10, 64)

	plant := entity.NewPlant()

	plant.Populate(getPlantMap(r, params["id"]))

	val, errors := validation.ValidateDefaultEntity(plant, db, PLANT)

	if val {
		_, err := repository.UpdatePlant(plant, db, params["id"])

		if err != nil {
			log.Println(err)
			sessionMessages.AddDanger("Failed to update plant.")
		} else {
			sessionMessages.AddSuccess("Successfully update plant.")

			updatePopularNames(db, id, PLANT, plant.GetPopularNames().GetValues())
			createMedia(r, mediaManager, db, sessionMessages, PLANT, id)
		}

		ren.Redirect("/plant/")
	} else {
		for k, msg := range errors {
			sessionMessages.AddDanger(k + ": " + msg)
		}

		ren.Redirect("/plant/" + params["id"])
	}
}
开发者ID:peteraba,项目名称:go-blah,代码行数:31,代码来源:plant.go

示例5: upload_battle

func upload_battle(w http.ResponseWriter, r *http.Request, out render.Render) {
	file, _, err := r.FormFile("txtUpload")

	if err != nil {
		fmt.Fprintln(w, err)
		return
	}

	defer file.Close()

	scanner := bufio.NewScanner(file)
	for scanner.Scan() {
		str := scanner.Text()

		//fmt.Println(str)

		beg := strings.Index(str, "\"")
		end := strings.LastIndex(str, "\"")
		if beg != -1 && end != -1 {
			jsonString := strings.Replace(str[beg+1:end], "\\\"", "\"", -1)
			saveBattle(jsonString)
		}
	}

	if err = scanner.Err(); err != nil {
		//fmt.Fprintln(w, err)
		fmt.Println(err)
	}

	out.Redirect("/")
}
开发者ID:chrisabruce,项目名称:RBGAssistant-API,代码行数:31,代码来源:battle_handler.go

示例6: Random

func Random(db model.Model, r render.Render, req *http.Request, isJson IsJson) {
	qs := req.URL.Query()

	search := qs.Get("query")

	maxLines, err := strconv.Atoi(qs.Get("max-lines"))
	if err != nil || maxLines < 1 {
		maxLines = 0
	}

	quotes, err := db.GetQuotes(model.Query{
		Limit:       1,
		Search:      search,
		MaxLines:    maxLines,
		OrderBy:     []string{"rand()"},
		IncludeTags: qs["tags"],
		ExcludeTags: qs["exclude-tags"],
	})

	if err != nil || len(quotes) == 0 {
		RenderError(r, 500, isJson, fmt.Sprint("quote not found", err))
		return
	}

	quote := quotes[0]

	if isJson {
		r.JSON(200, quote)
	} else {
		r.Redirect(fmt.Sprintf("/quote/%d", quote.ID))
	}
}
开发者ID:firba1,项目名称:irq,代码行数:32,代码来源:random.go

示例7: EditPlant

func EditPlant(ren render.Render, db *sql.DB, params martini.Params, t *template.TemplateData) {
	var plant_id string = params["id"]

	if plant_id != "new" {
		plant, err := repository.GetPlant(db, plant_id)

		if err != nil || plant == nil {
			t.SessionMessage.AddDanger("Failed to load plant.")

			ren.Redirect("/plant")

			return
		}

		id, _ := strconv.ParseInt(params["id"], 10, 64)

		plant.PopularNames.Names, err = repository.GetPopularNames(db, id, PLANT)

		t.Data = plant

		t.MediaList = getMediaList(db, PLANT, id)

		ren.HTML(200, "blah/plant/edit", t)
	} else {
		ren.HTML(200, "blah/plant/edit", nil)
	}
}
开发者ID:peteraba,项目名称:go-blah,代码行数:27,代码来源:plant.go

示例8: CreateInvertebrate

func CreateInvertebrate(ren render.Render, mediaManager *media.Manager, r *http.Request, db *sql.DB, params martini.Params, sessionMessages *template.Messages) {
	invertebrate := entity.NewInvertebrate()

	invertebrate.Populate(getInvertebrateMap(r, ""))

	val, errors := validation.ValidateDefaultEntity(invertebrate, db, INVERTEBRATE)

	if val {
		res, err := repository.InsertInvertebrate(invertebrate, db)

		if err != nil {
			log.Println(err)
			sessionMessages.AddDanger("Failed to create invertebrate.")
		} else {
			sessionMessages.AddSuccess("Successfully created invertebrate.")

			id, _ := res.LastInsertId()

			insertPopularNames(db, id, INVERTEBRATE, invertebrate.GetPopularNames().GetValues())
			createMedia(r, mediaManager, db, sessionMessages, INVERTEBRATE, id)
		}

		ren.Redirect("/invertebrate")
	} else {
		for k, msg := range errors {
			sessionMessages.AddDanger(k + ": " + msg)
		}

		ren.Redirect("/invertebrate/new")
	}
}
开发者ID:peteraba,项目名称:go-blah,代码行数:31,代码来源:invertebrate.go

示例9: UpdateInvertebrate

func UpdateInvertebrate(ren render.Render, mediaManager *media.Manager, r *http.Request, db *sql.DB, params martini.Params, sessionMessages *template.Messages) {
	id, _ := strconv.ParseInt(params["id"], 10, 64)

	invertebrate := entity.NewInvertebrate()

	invertebrate.Populate(getInvertebrateMap(r, params["id"]))

	val, errors := validation.ValidateDefaultEntity(invertebrate, db, INVERTEBRATE)

	if val {
		_, err := repository.UpdateInvertebrate(invertebrate, db, params["id"])

		if err != nil {
			log.Println(err)
			sessionMessages.AddDanger("Failed to upload invertebrate.")
		} else {
			sessionMessages.AddSuccess("Successfully upload invertebrate.")

			updatePopularNames(db, id, INVERTEBRATE, invertebrate.GetPopularNames().GetValues())
			createMedia(r, mediaManager, db, sessionMessages, INVERTEBRATE, id)
		}

		ren.Redirect("/invertebrate")
	} else {
		for k, msg := range errors {
			sessionMessages.AddDanger(k + ": " + msg)
		}

		ren.Redirect("/invertebrate/" + params["id"])
	}
}
开发者ID:peteraba,项目名称:go-blah,代码行数:31,代码来源:invertebrate.go

示例10: UpdateCoral

func UpdateCoral(ren render.Render, mediaManager *media.Manager, r *http.Request, db *sql.DB, params martini.Params, sessionMessages *template.Messages) {
	id, _ := strconv.ParseInt(params["id"], 10, 64)

	coral := entity.NewCoral()

	coral.Populate(getCoralMap(r, params["id"]))

	val, errors := validation.ValidateCoral(coral, db, CORAL)

	if val {
		_, err := repository.UpdateCoral(coral, db, params["id"])

		if err != nil {
			log.Println(err)
			sessionMessages.AddDanger("Failed to update coral.")
		} else {
			sessionMessages.AddSuccess("Successfully update coral.")

			updatePopularNames(db, id, CORAL, coral.GetPopularNames().GetValues())
			createMedia(r, mediaManager, db, sessionMessages, CORAL, id)
		}

		ren.Redirect("/coral")
	} else {
		for k, msg := range errors {
			sessionMessages.AddDanger(k + ": " + msg)
		}

		ren.Redirect("/coral/" + params["id"])
	}
}
开发者ID:peteraba,项目名称:go-blah,代码行数:31,代码来源:coral.go

示例11: EditInvertebrate

func EditInvertebrate(ren render.Render, db *sql.DB, params martini.Params, t *template.TemplateData) {
	var invertebrate_id string = params["id"]

	if invertebrate_id != "new" {
		invertebrate, err := repository.GetInvertebrate(db, invertebrate_id)

		if err != nil || invertebrate == nil {
			t.SessionMessage.AddDanger("Failed to load invertebrate.")

			ren.Redirect("/invertebrate")

			return
		}

		id, _ := strconv.ParseInt(params["id"], 10, 64)

		invertebrate.PopularNames.Names, err = repository.GetPopularNames(db, id, INVERTEBRATE)

		t.Data = invertebrate

		t.MediaList = getMediaList(db, INVERTEBRATE, id)

		ren.HTML(200, "blah/invertebrate/edit", t)
	} else {
		ren.HTML(200, "blah/invertebrate/edit", nil)
	}
}
开发者ID:peteraba,项目名称:go-blah,代码行数:27,代码来源:invertebrate.go

示例12: CreateCoral

func CreateCoral(ren render.Render, mediaManager *media.Manager, r *http.Request, db *sql.DB, params martini.Params, sessionMessages *template.Messages) {
	coral := entity.NewCoral()

	coral.Populate(getCoralMap(r, ""))

	val, errors := validation.ValidateCoral(coral, db, CORAL)

	if val {
		res, err := repository.InsertCoral(coral, db)

		if err != nil {
			log.Println(err)
			sessionMessages.AddDanger("Failed to create coral.")
		} else {
			sessionMessages.AddSuccess("Successfully created coral.")

			id, _ := res.LastInsertId()

			insertPopularNames(db, id, CORAL, coral.GetPopularNames().GetValues())
			createMedia(r, mediaManager, db, sessionMessages, CORAL, id)
		}

		ren.Redirect("/coral")
	} else {
		for k, msg := range errors {
			sessionMessages.AddDanger(k + ": " + msg)
		}

		ren.Redirect("/coral/new")
	}
}
开发者ID:peteraba,项目名称:go-blah,代码行数:31,代码来源:coral.go

示例13: EditCoral

func EditCoral(ren render.Render, db *sql.DB, params martini.Params, t *template.TemplateData) {
	var coral_id string = params["id"]

	if coral_id != "new" {
		coral, err := repository.GetCoral(db, coral_id)

		if err != nil || coral == nil {
			t.SessionMessage.AddDanger("Failed to load coral.")

			ren.Redirect("/coral")

			return
		}

		id, _ := strconv.ParseInt(params["id"], 10, 64)

		coral.PopularNames.Names, err = repository.GetPopularNames(db, id, CORAL)

		t.Data = coral

		t.MediaList = getMediaList(db, CORAL, id)

		ren.HTML(200, "blah/coral/edit", t)
	} else {
		ren.HTML(200, "blah/coral/edit", nil)
	}
}
开发者ID:peteraba,项目名称:go-blah,代码行数:27,代码来源:coral.go

示例14: LoginPost

func LoginPost(lu forms.Login, session sessions.Session, r render.Render, dbh *db.Dbh) {
	errs := ValidateLogin(&lu)
	if len(errs) > 0 {
		log.Printf("errors: %+v\n", errs)
	}

	user := dbh.GetUserByEmail(lu.Email)

	match := auth.MatchPassword(lu.Password, user.Password, user.Salt)

	if match {
		sessionkey := SessionKey(user.Email, user.Password, user.Salt)

		session.Set("loggedin", "true")
		session.Set("uid", user.Id)
		session.Set("email", user.Email)
		session.Set("key", sessionkey)

		dbh.CreateSession(models.UserSession{UserId: user.Id, SessionKey: sessionkey, Active: true, Timestamp: time.Now().Unix()})

		r.Redirect(strings.Join([]string{utils.AppCfg.Url(), "albums"}, "/"), http.StatusFound)
		return
	}

	session.Set("flash", "Invalid Email or Password")

	r.Redirect(strings.Join([]string{utils.AppCfg.Url(), "login"}, "/"), http.StatusFound)
}
开发者ID:szwork2013,项目名称:gopixelrelay,代码行数:28,代码来源:login.go

示例15: RequireLogin

// Handler to require a user to log in. If the user is currently logged in
// nothing happens. Otherwise clear existing session and redirect the user
// to the login page
func RequireLogin(s sessions.Session, r render.Render) {
	session := s.Get("user_session")
	if session == nil {
		s.Clear()
		r.Redirect("/login")
	}
}
开发者ID:sausheong,项目名称:goauthserv,代码行数:10,代码来源:routes.go


注:本文中的github.com/martini-contrib/render.Render.Redirect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。