func RegisterForm(w http.ResponseWriter, req *http.Request, ctx *models.Context) (err error) { if ctx.User != nil { http.Redirect(w, req, reverse("logout"), http.StatusSeeOther) return nil } ctx.Data["title"] = "Register" ctx.Data["cap"] = captcha.New() return T("register.html").Execute(w, map[string]interface{}{ "ctx": ctx, "fbLoginLink": FbConfig().AuthCodeURL(models.GenUUID()), "glLoginLink": GlConfig().AuthCodeURL(models.GenUUID()), }) }
func Photos(w http.ResponseWriter, req *http.Request, ctx *models.Context) error { id := req.URL.Query().Get(":id") if !bson.IsObjectIdHex(id) { return perform_status(w, req, http.StatusNotFound) } var photos []*models.Photo if err := ctx.C(P).Find(bson.M{"user": bson.ObjectIdHex(id), "active": true}).All(&photos); err != nil { return perform_status(w, req, http.StatusNotFound) } user := new(models.User) if err := ctx.C("users").FindId(bson.ObjectIdHex(id)).One(user); err != nil { return perform_status(w, req, http.StatusNotFound) } // find the index of the photo photoId := req.URL.Query().Get(":photo") ctx.Data["index"] = 0 var pIds []bson.ObjectId for i, p := range photos { if p.Id.Hex() == photoId { ctx.Data["index"] = i } pIds = append(pIds, p.Id) } return AJAX("galleria.html").Execute(w, map[string]interface{}{ "photos": photos, "user": user, "hash": models.GenUUID(), "ctx": ctx, }) }
func ResetPassword(w http.ResponseWriter, req *http.Request, ctx *models.Context) error { // should not be logged in if ctx.User != nil { ctx.Session.AddFlash(models.F(models.SUCCESS, trans("Already logged in!", ctx))) http.Redirect(w, req, reverse("index"), http.StatusSeeOther) return nil } form := models.UserForm form.Fields = form.Fields[2:3] r := (&form).Load(req) ctx.Data["result"] = r if r.Err != nil { ctx.Session.AddFlash(models.F(models.ERROR, trans("Problem reseting password:"******"csrf_token") != ctx.Session.Values["csrf_token"] { return perform_status(w, req, http.StatusForbidden) } if len(r.Errors) != 0 { return ResetPasswordForm(w, req, ctx) } email := r.Values["email"] u := &models.User{} err := ctx.C(U).Find(bson.M{"email": email}).One(&u) if err == nil { pt := &models.PasswordToken{ Uuid: models.GenUUID(), User: u.Id, CreatedOn: time.Now(), } // set new password to database if err := ctx.C(PT).Insert(pt); err != nil { ctx.Session.AddFlash(models.F(models.ERROR, trans("Problem reseting password:"******"Subject: lov3ly.me password reset\r\n\r\nChange password link: http://%s\n\nIf you have NOT requested this, please ignore. Link available for 24 hours.\n\nHave fun,\nlov3ly.me Team", req.Host+reverse("change_token", "uuid", pt.Uuid)) go func() { err := models.SendEmail([]byte(body), email) if err != nil { models.Log("Error sending mail: ", err.Error()) } }() ctx.Session.AddFlash(models.F(models.SUCCESS, trans("Email sent succesfully!", ctx))) } else { ctx.Session.AddFlash(models.F(models.NOTICE, trans("Email not in our database:", ctx), err.Error())) } http.Redirect(w, req, reverse("login"), http.StatusSeeOther) return nil }