Ejemplo n.º 1
0
    def post(self):
        email = self.get_argument('email', '')
        password = self.get_argument('password', '')
        error = False

        if not email or not password:
            error = True

        user = models.User.objects(email=email).first()

        if not user:
            error = True

        t = time.time()
        if user and not util.check_pwd(password, user.password):
            error = True
        t2 = time.time()
        logging.debug('check_pwd took {}'.format(t2 - t))

        if error:
            error_text = "Yo! You gave an invalid username or incorrect password!"
            self.render('login.html', page_title='Log In', user=None, error=error_text)
            self.tf.send({'users.logins.failure': 1}, lambda x: x)
            return
        
        self.set_secure_cookie('user', str(user.id))
        self.tf.send({'users.logins.success': 1}, lambda x: x)
        self.redirect('/')
Ejemplo n.º 2
0
    def post(self):
        email = self.get_argument('email', '').lower()
        password = self.get_argument('password', '')
        error = False

        if not email or not password:
            error = True

        user = yield models.get_user_by_email(self.redis, email)

        if not user:
            error = True

        t = time.time()
        if user and not util.check_pwd(password, user.password):
            error = True
        t2 = time.time()
        logging.debug('check_pwd took {}'.format(t2 - t))

        if error:
            error_text = "Yo! You gave an invalid username or incorrect password!"
            self.render('login.html', page_title='Log In',
                        user=None, error=error_text)
            self.tf.send({'users.logins.failure': 1}, lambda x: x)
            return

        cookie_args = {'httponly': True}

        logging.debug('request.protocol is {}'.format(self.request.protocol))
        if self.request.protocol == 'https':
            cookie_args['secure'] = True

        self.set_secure_cookie('user', str(user.id), **cookie_args)
        self.tf.send({'users.logins.success': 1}, lambda x: x)
        self.redirect('/')
Ejemplo n.º 3
0
    def post(self):
        email = self.get_argument('email', '')
        password = self.get_argument('password', '')
        error = False

        if not email or not password:
            error = True

        user = models.User.objects(email=email).first()

        if not user:
            error = True

        if not util.check_pwd(password, user.password):
            error = True

        if error:
            self.write('invalid username or password incorrect<br />') 
            self.write('Plase <a href="/login">try again.</a>')
            self.finish()
            return
        
        self.set_secure_cookie('user', str(user.id))
        self.redirect('/')