本文整理汇总了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)
}
示例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())
}
示例3: getLoginPage
func getLoginPage(user sessionauth.User, r render.Render) {
if user.IsAuthenticated() {
r.Redirect(INDEX_PAGE)
return
}
r.HTML(200, LOGIN_PAGE, nil)
}
示例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"])
}
}
示例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("/")
}
示例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))
}
}
示例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)
}
}
示例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")
}
}
示例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"])
}
}
示例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"])
}
}
示例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)
}
}
示例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")
}
}
示例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)
}
}
示例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)
}
示例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")
}
}