示例#1
0
文件: bloggy.py 项目: domtn/cs253
  def post(self):
    self.logout()
    input_username = self.request.get('username')
    input_password = self.request.get('password')
    input_verify = self.request.get('verify')
    input_email = self.request.get('email')

    err_username = ""
    err_pwd = ""
    err_verify = ""
    err_email = ""

    validated_username = html_util.escape_html(input_username)
    validated_pwd = input_password
    validated_verify = input_verify
    validated_email = html_util.escape_html(input_email)

    # Check if username contains valid characters
    if not signuputil.is_username_valid(input_username):
      err_username = "******"

    # Check if username has been taken by someone else
    if User.by_username(validated_username):
      err_username = "******"
    
    # Check if password contains valid characters
    if not signuputil.is_password_valid(input_password):
      err_pwd = "Invalid password"
      validated_pwd = ""
      validated_verify = ""

    # Check if input password is same as input_verify
    if input_password != input_verify:
      err_verify = "Does not match the password you entered"

    # Check if username is valid
    if not signuputil.is_email_valid(input_email):
      err_email = "Invalid email"

    # If email is empty, make it empty
    if input_email.strip() == "":
      validated_email = None

    if err_username == "" and \
       err_pwd == "" and \
       err_verify == "" and \
       err_email == "":
      user = User.register(username=validated_username, 
                           pw=validated_pwd,
                           email=validated_email) 
      user.put()
      self.login(user)
      self.redirect(APP_PATH + CORE_PATH)
    else:
      self.render_page(validated_username, err_username,
                      validated_pwd, err_pwd,
                      validated_verify, err_verify,
                      validated_email, err_email)
示例#2
0
  def post(self):
    input_username = self.request.get('username')
    input_password = self.request.get('password')
    input_verify = self.request.get('verify')
    input_email = self.request.get('email')

    err_username = ""
    err_password = ""
    err_verify = ""
    err_email = ""

    output_username = html_util.escape_html(input_username)
    output_password = input_password
    output_verify = input_verify
    output_email = html_util.escape_html(input_email)

    if not signuputil.is_username_valid(input_username):
      err_username = "******"

    if User.by_username(output_username):
      err_username = "******"
    
    if not signuputil.is_password_valid(input_password):
      err_password = "******"
      output_password = ""
      output_verify = ""

    if input_password != input_verify:
      err_verify = "Does not match the password you entered"

    if not signuputil.is_email_valid(input_email):
      err_email = "Invalid email"

    if input_email == "":
      output_email = None

    if err_username == "" and \
       err_password == "" and \
       err_verify == "" and \
       err_email == "":
      user = User.register(username=output_username, 
                           pw=output_password,
                           email=output_email) 
      user.put()
      self.login(user)
      self.redirect(APP_PATH + CORE_PATH)
    else:
      self.render_page(output_username, err_username,
                      output_password, err_password,
                      output_verify, err_verify,
                      output_email, err_email)
示例#3
0
文件: signup.py 项目: domtn/cs253
  def post(self):
    input_username = self.request.get('username')
    input_password = self.request.get('password')
    input_verify = self.request.get('verify')
    input_email = self.request.get('email')

    err_username = ""
    err_password = ""
    err_verify = ""
    err_email = ""

    output_username = html_util.escape_html(input_username)
    output_password = input_password
    output_verify = input_verify
    output_email = html_util.escape_html(input_email)

    if not signuputil.is_username_valid(input_username):
      err_username = "******"
    
    if not signuputil.is_password_valid(input_password):
      err_password = "******"
      output_password = ""
      output_verify = ""

    if input_password != input_verify:
      err_verify = "Does not match the password you entered"

    if not signuputil.is_email_valid(input_email):
      err_email = "Invalid email"

    if err_username == "" and \
       err_password == "" and \
       err_verify == "" and \
       err_email == "":
      newurl = 'welcome?' + urllib.urlencode({'username':output_username})
      self.redirect(newurl)
    else:
      self.write_form(output_username, err_username,
                      output_password, err_password,
                      output_verify, err_verify,
                      output_email, err_email)
示例#4
0
文件: authen.py 项目: domtn/cs253
    def post(self):
        input_username = self.request.get("username")
        input_password = self.request.get("password")
        input_verify = self.request.get("verify")
        input_email = self.request.get("email")

        err_username = ""
        err_password = ""
        err_verify = ""
        err_email = ""

        output_username = html_util.escape_html(input_username)
        output_password = input_password
        output_verify = input_verify
        output_email = html_util.escape_html(input_email)

        if not signuputil.is_username_valid(input_username):
            err_username = "******"

        query = (
            "SELECT * FROM User \
               WHERE username = '******'"
        )
        users = db.GqlQuery(query)
        if users.count() > 0:
            err_username = "******"

        if not signuputil.is_password_valid(input_password):
            err_password = "******"
            output_password = ""
            output_verify = ""

        if input_password != input_verify:
            err_verify = "Does not match the password you entered"

        if not signuputil.is_email_valid(input_email):
            err_email = "Invalid email"

        if err_username == "" and err_password == "" and err_verify == "" and err_email == "":

            if output_email == "":
                output_email = None
            user = User(
                username=output_username,
                password_hash=hashutil.make_pw_hash(output_username, output_password),
                email=output_email,
            )
            user.put()
            user_id = user.key().id()
            self.response.headers.add_header("Set-Cookie", "user_id=%s" % hashutil.make_secure_val(str(user_id)))
            self.redirect(APP_PATH + CORE_PATH)
        else:
            self.render_page(
                output_username,
                err_username,
                output_password,
                err_password,
                output_verify,
                err_verify,
                output_email,
                err_email,
            )