def POST(self): if len(self.request.id) == 10: recipe = rm.Recipe.find(self.request.id) elif len(self.request.id) == 36: recipe = rm.Recipe(self.request.id) else: recipe = None if recipe is None or recipe.deleted: return NotFound() if recipe.user.id != self.session.id: if not recipe.public: return Unauthorized() recipe.title = self.request.get_param("title") recipe.tags = self.request.get_param("tags") recipe.public = self.request.get_param("public", False) recipe.country = self.request.get_param("country") recipe.description = self.request.get_param("description") recipe.ingredients = self.request.get_param("ingredients") recipe.steps = self.request.get_param("steps") recipe.save() searcher = rs.RecipeSearcher() searcher.update(recipe) searcher.save() return Redirect("/recipes/{}".format(recipe.short_code))
def POST(self): if not self.session.has_group("phots"): return Unauthorized() new_name = self.request.get_param("name") tags = self.request.get_param("tags") if tags: tag = tags.split(",") else: tag = [] phot = self.request.id if len(phot.rsplit(".")) == 1: f = r.table(pm.Phot.table).filter({"short_code": phot})\ .coerce_to("array").run() else: f = r.table(pm.Phot.table).filter({"filename": phot})\ .coerce_to("array").run() if f: photo = pm.Phot(**f[0]) photo.title = new_name photo.tags = tag photo.save() searcher = PhotSearcher() searcher.update(photo) searcher.save() return Redirect("/phots/" + photo.short_code) else: return NotFound()
def POST(self): stuff = self.request.get_param("url", None) or self.request.get_file("file") title = self.request.get_param("title", "") tags = self.request.get_param("tags", "") if tags: if type(tags) is str: tag = tags.split(",") else: tag = tags else: tag = [] title = title.rstrip().lstrip().lower() found = r.table(pm.Phot.table).filter({"filename": title}).count().run() if found: title = "_".join([title, str(arrow.utcnow().timestamp)]) self.session.push_alert("That image name is already in use; timestamp appened to image name.") phot = pm.Phot.new_phot(self.session.id, stuff=stuff, title=title, tags=tag) searcher = PhotSearcher() searcher.update(phot) searcher.save() return Redirect("/phots/%s" % phot.short_code)
def POST(self): email = em.Email(self.request.id) email.queue() self.session.push_alert("Email queued to be resent.") return Redirect("/admin/emails")
def POST(self): error = False user = um.User(self.session.id) email = self.request.get_param("email") password = self.request.get_param("password") if email and email != user.email: found = r.table(um.User.table).filter({"email": email})\ .map(lambda u: u["id"]).coerce_to("array").run() if email in found: error = True self.view.data = { "error": "email", "msg": "That email is already registered, please choose another." } else: user.email = email if password: user.set_password(password) self.session.push_alert( "Password updated, please make sure to use it :)", level="warning") user.save() if error: return self.view return Redirect("/account")
def POST(self): email = self.request.get_param("email") if email: im.Invite.new(email) self.session.push_alert("Invite sent!") return Redirect("/admin/invites")
def GET(self): search_term = self.request.get_param("s") all_tags = r.table(rm.Recipe.table)\ .concat_map(lambda doc: doc["tags"])\ .distinct()\ .coerce_to('array').run() self.view.data = {"tags": all_tags, "recipes": None} if search_term: if "recipe:" in search_term: parts = search_term.split(" ") for part in parts: if "recipe:" in part: recipe = rm.Recipe.find(part[7:]) if recipe is not None: return Redirect("/recipes/{}".format(part[7:])) search_term = search_term.replace("tag:", "tags:") searcher = RecipeSearcher() if self.session.id: allow = q.Or([ q.And([ q.Term("user", self.session.id), q.Term("deleted", False), q.Term("reported", False) ]), q.And([ q.Term("public", True), q.Term("deleted", False), q.Term("reported", False) ]) ]) else: allow = q.And([ q.Term("public", True), q.Term("deleted", False), q.Term("reported", False) ]) ids = searcher.search(search_term, collection=True, allow=allow) if ids is not None: ids.fetch() page = Paginate(ids, self.request, "title", sort_direction_default="desc") self.view.data = {"recipes": page} self.view.template = "public/recipes/search/results" return self.view
def POST(self): status = self.request.get_param("status", False) message = self.request.get_param("message") start = self.request.get_param("start") end = self.request.get_param("end") self.announcements.new_announcement(message, status, start, end) return Redirect("/admin/announcements")
def POST(self): title = self.request.get_param("title") contents = self.request.get_param("contents") public = self.request.get_param("public", False) draft = self.request.get_param("draft", False) toc = self.request.get_param("toc", False) comments = self.request.get_param("comments", False) tags = self.request.get_param("tags") theme = self.request.get_param("theme", "default") tag = [] if tags: tag = [ bit.lstrip().rstrip().replace(" ", "_").lower() for bit in tags.split(",") ] f = r.table(nm.Note.table)\ .filter({"short_code": self.request.id})\ .coerce_to("array")\ .run() if f: note = nm.Note(f[0]["id"]) if note.author.id != self.session.id: self.session.push_alert( "You don't own that note, you can't edit it!", level="danger") return Unauthorized() if not "notes" in self.session.groups and note.disable: return NotFound() if note.reported: self.view.template = "public/notes/reported" return self.view note.title = title note.contents = contents note.public = public note.tags = tag note.table_of_contents = toc note.draft = draft note.has_comments = comments note.theme = theme note.save() searcher = NoteSearcher() searcher.update(note) searcher.save() return Redirect("/notes/%s" % note.short_code) else: return NotFound()
def GET(self): """ Simply log the user out. Nothing much to do here. redirect to login page after we're done. """ if self.session.logout(): self.session.push_alert("Come back soon!", "B'ahBye...", "info") return Redirect("/login")
def POST(self): title = self.request.get_param("title") contents = self.request.get_param("contents") public = self.request.get_param("public", False) draft = self.request.get_param("draft", False) toc = self.request.get_param("toc", False) comments = self.request.get_param("comments", False) tags = self.request.get_param("tags") theme = self.request.get_param("theme") if tags: tag = [ bit.lstrip().rstrip().replace(" ", "_").lower() for bit in tags.split(",") ] else: tag = [] try: note = nm.Note.new_note(user=self.session.id, title=title, contents=contents, public=public, tags=tag, toc=toc, has_comments=comments, draft=draft, theme=theme) searcher = NoteSearcher() searcher.add(note) searcher.save() except Exception as e: print e self.session.push_alert("That note could not be created! %s" % e.message, level="error") return Redirect("/new/note") return Redirect("/notes/%s" % note.short_code)
def GET(self): code = self.request.get_param("c") if not code: self.view.template = "public/reset/request" return self.view found = r.table(um.User.table).filter({ "reset_code": code }).count().run() if found: return self.view else: self.session.push_alert( "That code isn't in the database, want to try requesting a new one?", level="danger") return Redirect("/reset")
def POST(self): scrn = self.request.get_file("file") if scrn: date = str(arrow.utcnow().timestamp) + "_" path = ''.join([c.dirs.screenshots, date, scrn.filename]) try: with open(path, 'w+b') as f: f.write(scrn.read()) self.session.push_alert("Screenshot uploaded...", level="success") except IOError as e: self.session.push_alert( "There was a problem executing that: {}".format(str(e)), level="error") return Redirect("/screenshots")
def POST(self): try: user = um.User(self.request.id) except NotFoundError: return NotFound() password = self.request.get_param("password") disable = self.request.get_param("disable", False) email = self.request.get_param("email") groups = self.request.get_param("groups") clear_reset = self.request.get_param("clear_reset", False) if type(groups) is not list: groups = [groups] groups = [ group.strip(" ").replace(" ", "_").lower() for group in groups if group ] user.groups = groups if password: user.set_password(password) self.session.push_alert( "Password updated, please let the user know the new password", level="warning") if email and email != user.email: # TODO: Only allow change if email isn't in the database yet user.email = email if clear_reset: del user.reset_code user.disable = disable user.save() return Redirect("/admin/users/" + self.request.id)
def POST(self): name = self.request.get_param("title") tags = self.request.get_param("tags") public = self.request.get_param("public", False) country = self.request.get_param("country") description = self.request.get_param("description") ingredients = self.request.get_param("ingredients") steps = self.request.get_param("steps") recipe = rm.Recipe.new_recipe(self.session.id, title=name, tags=tags, public=public, country=country, description=description, ingredients=ingredients, steps=steps) searcher = rs.RecipeSearcher() searcher.add(recipe) searcher.save() return Redirect("/recipes/{}".format(recipe.short_code))
def POST(self): passwd = self.request.get_param("password") name = self.request.get_param("username") if not passwd and not name: self.view.partial("about", "public/about/about") return self.view exc = "" try: self.session.login(name, passwd) self.session.push_alert("Welcome back, %s!" % name, "Ohia!", "success") where = self.request.get_param("return-to", "/") return Redirect(where) except se.UsernameError as e: exc = e self.view.data = {"username": name} self.view.data = {"usernameError": True} except se.PasswordError as e: exc = e self.view.data = {"username": name} self.view.data = {"passwordError": True} except se.DisableError as e: exc = e self.view.data = {"banError": True} exc = unicode(exc).strip("'") self.session.push_alert("%s <br/>Please try again." % exc, "Uh oh...", "error") return self.view
def GET(self): if self.session.id: return self.view else: return Redirect("/phots")
def POST(self): code = self.request.get_param("c") username = self.request.get_param("username") password = self.request.get_param("password") try: user = um.User.from_email(username) except NotFoundError: self.session.push_alert( "That email wasn't found in our system. Are you sure its correct?", level="danger") return Redirect("/reset") if not code: user.reset_code = sc.rand_short_code() tmpl = PartialTemplate("emails/password_reset") tmpl.data = {"user": user} content = tmpl.render() e = em.Email.new()\ .send_to(user.id)\ .send_from("noreply")\ .set_subject("transientBug.com - Password Reset")\ .set_text(content)\ .set_html(content)\ .queue() user.save() self.session.push_alert( "Password reset email sent. Please check your email.") self.view.template = "public/reset/sent" return self.view found = r.table(um.User.table).filter({ "reset_code": code }).count().run() if found: if hasattr(user, "reset_code"): if user.reset_code == code: user.set_password(password) self.session.push_alert( "Password reset, please login with it now to make sure it works :)" ) return Redirect("/login") else: self.session.push_alert("That isn't your reset code!", level="danger") return Redirect("/reset") else: self.session.push_alert( "That email doesn't have a reset request!", level="danger") return Redirect("/reset") else: self.session.push_alert( "That code isn't in the database, want to try requesting a new one?", level="danger") return Redirect("/reset")
def POST(self): code = self.request.get_param("c") username = self.request.get_param("username") email = self.request.get_param("email") password = self.request.get_param("password") if code: found = r.table(im.Invite.table).filter({ "short_code": code }).coerce_to("array").run() if found: invite = im.Invite(**found[0]) if email != invite.email_address: self.session.push_alert( "Your email doesn't match the email for that invite!") self.view.template = "public/register/closed" return self.view if invite.closed: self.view.template = "public/register/closed" self.session.push_alert( "That invite has already been used!") return self.view try: user = um.User.new_user(username=username, password=password, email=email, groups=["default", "recipes"]) user.email = email invite.user = user tmpl = PartialTemplate("emails/account_registered") tmpl.data = {"user": user} content = tmpl.render() em.Email.new()\ .send_to(user.id)\ .send_from("noreply")\ .set_subject("transientBug.com - Account Registered!")\ .set_text(content)\ .set_html(content)\ .queue() invite.save() user.save() self.session.push_alert( "Account registered. Please login to make sure everything is okay!" ) return Redirect("/login") except UsernameError: self.view.data = { "error": "username", "error_msg": "That username is already in use, please choose another one." } return self.view except EmailError: self.view.data = { "error": "email", "error_msg": "That email is already registered. Maybe try logging in?" } return self.view self.view.template = "public/register/closed" return self.view