Exemplo n.º 1
0
    def post(self):
        # retrieve user input
        username = self.request.get('username')
        password = self.request.get('password')
        vpassword = self.request.get('vpassword')
        email = self.request.get('email')

        # validate inputs
        usernameError = Credential.checkUsername(username)
        passError = Credential.checkPassword(password)
        vpassError = Credential.checkVPassword(password, vpassword)
        isUserRegistered = User.checkRegistration(username)

        # proceed if no error
        if usernameError == '' and passError == '' and vpassError == '' and isUserRegistered is False:
            user = self.saveUser(username, password, email)
            self.login(user)
            self.redirect('/author/%s' % username)

        # if error found, display them
        else:
            if isUserRegistered is True:
                usernameError = 'user is already registered!'
            self.render('signup.html',
                        user=self.user,
                        username=username,
                        email=email,
                        usernameError=usernameError,
                        passError=passError,
                        vpassError=vpassError)
Exemplo n.º 2
0
    def post(self):
        username = self.request.get('username')
        password = self.request.get('password')
        # validate user input
        userError = Credential.checkUsername(username)
        passError = Credential.checkPassword(password)

        # math username with password
        if userError == '' and passError == '':
            user = User.getUserByUsername(username)
            # username not found in db -> show error
            if user is None:
                self.render('signin.html',
                            user=self.user,
                            userError='username not found!')
                return
            hashPass = user.password
            isPassValid = Credential.isCredValid(password, hashPass)

            # username matched with password -> login
            if isPassValid:
                self.setCookie('user_id', user.key().id())
                self.setCookie('username', user.username)
                self.redirect('/author/%s' % user.username)
            # username did not match with password -> show error
            else:
                self.render('signin.html',
                            user=self.user,
                            passError='username or password wrong!')
        else:
            self.render('signin.html',
                        user=self.user,
                        userError=userError,
                        passError=passError)