Ejemplo n.º 1
0
 def post(self):
     username = self.request.get('username')
     pw = self.request.get('password')
         
     if not (username and pw):
         self.write_form(err_msg = 'Username or password is missing.')
     elif not Users.exist_username(username):
         self.write_form(err_msg = 'The username you have entered does not match any account.')
     elif not Users.password_match(pw, Users.get_pwhash(username).password):
         self.write_form(err_msg = 'The password you have entered is incorrect.')
         
     else:
         pw_hash = Users.get_pwhash(username).password
         set_secure_cookie(self, 'username', str(username))
         set_secure_cookie(self, 'password', str(Users.get_pwhash(username).password))
         self.redirect('/')
Ejemplo n.º 2
0
    def post(self):
        fname = self.request.get('first_name')
        lname = self.request.get('last_name')
        username = self.request.get('username')
        email = self.request.get('email')
        pw = self.request.get('password')
        verify = self.request.get('verify')

        if not (fname and lname and username and pw and verify):
            self.write_form(err_msg = 'Required field missing',
                            fname = fname,
                            lname=lname,
                            username=username)     
        

        elif not self.valid_username(username):
            self.write_form(err_msg = 'Username should be at least 4 characters long.',
                            fname = fname,
                            lname = lname)

        elif Users.exist_username(username):
            self.write_form(err_msg = 'This username is already taken.',
                            fname = fname,
                            lname = lname)

        elif not self.valid_password(pw):
            self.write_form(err_msg = 'Password should be at least 6 characters long.',
                            fname = fname,
                            lname = lname,
                            username = username)
            
        elif  pw != verify:
            self.write_form(err_msg = 'Passwords did not match',
                            fname = fname,
                            lname = lname,
                            username = username)
                            
        else:
            pw_hash = Users.make_pw_hash(pw)
            Users.create_new_user(fname, lname, pw_hash, username, email)
            set_secure_cookie(self, 'username', str(username))
            set_secure_cookie(self, 'password', str(pw_hash))
            self.redirect('/')