Exemple #1
0
    def post(self):
        have_error = False
        user_username = self.request.get('username')
        user_password = self.request.get('password')
        user_verify = self.request.get('verify')
        user_email = self.request.get('email')
        
        check_username = valid_helpers.valid_username(user_username)
        check_password = valid_helpers.valid_password(user_password)
        check_verify = valid_helpers.valid_verify(user_verify, user_password)
        check_email = valid_helpers.valid_email(user_email)

        params = dict(user_username = user_username, user_email = user_email)

        # Try to retrieve user from database if it already exits
        query = User.all(keys_only = True).filter('username', user_username)
        if not(check_username):
            params['error_username'] = "******"
            have_error = True
        if not(check_password):
            params['error_password'] = "******"
            have_error = True
        if not(check_verify):
            params['error_verify'] = "Your passwords didn't match."
            have_error = True
        if not(check_email):
            params['error_email'] = "That's not a valid email."
            have_error = True
        if not have_error:
            # query database only if no other errors exist
            existing_user = query.get()
            if existing_user:
                # if the user exists, the give error
                params['error_username'] = "******"
                have_error = True
        if have_error:
            self.render("signup_form.html", **params)
        else:
            #set cookies here and save user to database
            #encrypt the pass before saving
            encrypted_pass = auth_helpers.make_pw_hash(user_username, user_password)
            user = User(username = user_username, email = user_email, encrypted_pass = encrypted_pass)
            user.put() # save the user
            existing_user = query.get() # get the user from the database
            user_id = existing_user.id()
            user_hash = auth_helpers.make_secure_val(str(user_id))
            self.response.headers.add_header("Set-Cookie", "user = %s" % str(user_hash))
            self.redirect("/unit3/welcome")
Exemple #2
0
    def post(self):
        have_error = False
        self.user_username = self.request.get('username')
        self.user_password = self.request.get('password')
        self.user_verify = self.request.get('verify')
        self.user_email = self.request.get('email')

        check_username = valid_helpers.valid_username(self.user_username)
        check_password = valid_helpers.valid_password(self.user_password)
        check_verify = valid_helpers.valid_verify(self.user_verify,
                                                  self.user_password)
        check_email = valid_helpers.valid_email(self.user_email)

        params = dict(user_username=self.user_username,
                      user_email=self.user_email)

        if not (check_username):
            params['error_username'] = "******"
            have_error = True
        if not (check_password):
            params['error_password'] = "******"
            have_error = True
        if not (check_verify):
            params['error_verify'] = "Your passwords didn't match."
            have_error = True
        if not (check_email):
            params['error_email'] = "That's not a valid email."
            have_error = True
        if not have_error:
            existing_user = User.by_name(self.user_username)
            if existing_user:
                params['error_username'] = "******"
                have_error = True

        if have_error:
            self.render("signup_form.html", **params)
        else:
            self.done()
Exemple #3
0
    def post(self):
        have_error = False
        self.user_username = self.request.get('username')
        self.user_password = self.request.get('password')
        self.user_verify = self.request.get('verify')
        self.user_email = self.request.get('email')
        
        check_username = valid_helpers.valid_username(self.user_username)
        check_password = valid_helpers.valid_password(self.user_password)
        check_verify = valid_helpers.valid_verify(self.user_verify, self.user_password)
        check_email = valid_helpers.valid_email(self.user_email)

        params = dict(user_username = self.user_username, user_email = self.user_email)

        if not(check_username):
            params['error_username'] = "******"
            have_error = True
        if not(check_password):
            params['error_password'] = "******"
            have_error = True
        if not(check_verify):
            params['error_verify'] = "Your passwords didn't match."
            have_error = True
        if not(check_email):
            params['error_email'] = "That's not a valid email."
            have_error = True
        if not have_error:
            existing_user = User.by_name(self.user_username)
            if existing_user:
                params['error_username'] = "******"
                have_error = True

        if have_error:
            self.render("signup_form.html", **params)
        else:
            self.done()