Beispiel #1
0
 def track(self):
     logging.info('MainHandler:track() => Geting user_id ...')
     u_id = self.check_cookie()
     logging.info('MainHandler:track() => user_id = %s' % u_id)
     if u_id:
         logging.info('MainHandler:track() => Geting Login object from DB ...')
         logging.info('MainHandler:track() => Login instanse: %s' % Login.get_by_id(int(u_id)))
         return Login.get_by_id(int(u_id))
     else:
         self.delete_cookie()
         logging.info('MainHandler:track() => No valid cookie, return None')
         return None
Beispiel #2
0
    def post(self):

        logging.info('LoginHandler:post() => Start POST')
        username = self.request.get('username')
        raw_password = self.request.get('password')

        if not (username and raw_password):

            logging.error('LoginHandler:post() => User or password blank, render form with error msg ...')

            self.render('login.jinja2', error='Login or password fail')
            return

        logging.info('LoginHandler:post() => Login and password verify ...')
        logging.info('LoginHandler:post() => Call Login.check_user_password() method ...')

        u = Login.check_user_password(login=username, raw_password=raw_password)
        if u:

            logging.info('LoginHandler:post() => Login success, user in DB. Set cookie')

            self.set_cookie(u.make_cookie())

            logging.error('LoginHandler:post() => Redirecting to main page')

            self.redirect('/')
        else:

            logging.error('LoginHandler:post() => User or passwprd fail. No user in DB, or wrong password')

            self.delete_cookie()

            logging.error('LoginHandler:post() => User or password FAIL, render form with error msg ...')
            self.render('login.jinja2', error='Login or password fail')
Beispiel #3
0
    def post(self):

        username = self.request.get('username')
        password = self.request.get('password')
        verify = self.request.get('verify')
        email = self.request.get('email')

        errors_form = validation_form(username=username,
                                      password=password,
                                      verify=verify,
                                      email=email)

        if errors_form:
            logging.error('SignupHandler: Error by parsing form. Render form with error msg ...')
            self.render('signup.jinja2', **errors_form)
            return

        logging.info('SignupHandler: Check if user registred. Making DB QUERY')
        u = Login.get_by_username(username)

        logging.warning('SignupHandler: from DB by username %s get => %s' % (username, u))

        if u:
            logging.error('SignupHandler: User registred. Set error message')
            self.render('signup.jinja2', error_username='******')
            return

        logging.info('SignupHandler: Make a user')
        u = Login.create_user(username=username,
                              raw_password=password,
                              email=email)

        logging.info('SignupHandler: Put user to DB')
        u.put()

        logging.info('SignupHandler: Make token and set cookie for current user')
        self.set_cookie(u.make_cookie())

        self.redirect('/')