예제 #1
0
파일: dj.py 프로젝트: hchapman/WBOR
  def post(self):
    if self.request.get("submit") != "Request Reset":
      self.session.add_flash("There was an error, please try again")
      self.redirect("/dj/reset/")
      return

    # Check that the user exists and information is valid
    username = self.request.get("username")
    email = self.request.get("email")
    reset_dj = None

    try:
      reset_dj = Dj.get_by_username(username)
    except NoSuchUsername as e:
      self.session.add_flash(str(e))
      self.redirect("/dj/reset")
      return
    if not reset_dj.email_matches(email):
      self.session.add_flash(
        "The email you have entered does not match our records. "
        "Check, and try, again.")

    # Generate a key to be sent to the user and add the
    # new password request to the database
    reset_key = ''.join(random.choice(string.ascii_letters +
                                      string.digits) for x in range(20))
    reset_url="%s/dj/reset/?username=%s&reset_key=%s"%(
      self.request.host_url, username, reset_dj.reset_password())
    mail.send_mail(
      sender="WBOR <*****@*****.**>",
      to=email.strip(),
      subject="You've requested to reset your password!",
      body="""
Hello!

Someone has requested to reset your password for wbor.org. In order to do so,
please click on the following link or paste it into your address bar:
%s

If you were not who requested this password reset, then please just ignore
this email.

Thank you!
The WBOR.org Team
"""%reset_url)
    self.session.add_flash(
      "Request successfully sent! Check your mail, and be sure to doublecheck "
      "the spam folder in case.")
    self.redirect("/")
예제 #2
0
파일: dj.py 프로젝트: hchapman/WBOR
  def post(self):
    if self.request.get("submit") != "Add DJ":
      self.session.add_flash("There was an error, please try again.")
      self.redirect("/dj/djs/")
    else:
      fullname = self.request.get("fullname")
      email = self.request.get("email")
      username = self.request.get("username")
      password = self.request.get("password")

      if not email:
        self.session.add_flash("Please enter a valid email address.")
        self.redirect("/dj/djs")
        return
      if not username:
        self.session.add_flash("Please enter a valid username.")
        self.redirect("/dj/djs")
        return
      if not fullname:
        self.session.add_flash("Please enter a valid full name.")
        self.redirect("/dj/djs")
        return
      if not password:
        self.session.add_flash("Please enter a valid password.")
        self.redirect("/dj/djs")
        return
      if not password == self.request.get("confirm"):
        self.session.add_flash("Passwords do not match.")
        self.redirect("/dj/djs")
        return

      try:
        dj = Dj.get_by_email(email)
      except NoSuchEmail:
        dj = None

      if dj is not None:
        self.session.add_flash(
          "A DJ with email address %s already exists: %s, username %s" %
          (dj.email, dj.fullname, dj.username))
        self.redirect("/dj/djs")
        return

      try:
        dj = Dj.get_by_username(username)
      except NoSuchUsername:
        dj = None

      if dj is not None:
        self.session.add_flash(
          "A DJ with username %s already exists: %s, email address %s" %
          (dj.username, dj.fullname, dj.email))
        self.redirect("/dj/djs")
        return

      # If both username and email address are new, then we can add them
      dj = Dj.new(fullname=fullname,
                  email=email,
                  username=username,
                  password=password)
      dj.put()

      self.session.add_flash(dj.fullname + " successfully added as a DJ.")
      self.redirect("/dj/djs/")