Exemplo n.º 1
0
    def post_login(self):
        try:
            self.logger.info("Login.")
            p_role_name = self.get_argument('username')
            p_role_password = self.get_argument('password')
            role_hash_password = hash_password(p_role_name, p_role_password)

            self.start_db_session()
            role = get_role_by_auth(self.db_session, p_role_name, role_hash_password)
            self.logger.info("Role '%s' authentificated." % (role.role_name))
            self.db_session.expunge_all()
            self.db_session.commit()
            self.db_session.close()
            sleep(1)
            self.logger.info("Done.")
            return HTMLAsyncResult(
                http_code = 302,
                redirection = self.get_secure_cookie('referer_uri') if self.get_secure_cookie('referer_uri') is not None else '/home',
                secure_cookie = { 'name': 'temboard', 'content': gen_cookie(role.role_name, role_hash_password)})
        except (TemboardUIError, Exception) as e:
            try:
                self.db_session.rollback()
                self.db_session.close()
            except Exception:
                pass
            self.logger.exception(str(e))
            self.logger.info("Failed.")
            sleep(1)
            return HTMLAsyncResult(
                http_code = 401,
                template_file = 'login.html',
                data = { 'nav': False , 'error': 'Wrong username/password.'})
Exemplo n.º 2
0
    def post_login(self):
        try:
            self.logger.info("Login (API).")
            post = tornado.escape.json_decode(self.request.body)
            p_role_name = post['username']
            p_role_password = post['password']
            role_hash_password = hash_password(p_role_name, p_role_password)

            self.start_db_session()
            role = get_role_by_auth(self.db_session, p_role_name, role_hash_password)
            self.logger.info("Role '%s' authentificated." % (role.role_name))
            self.db_session.expunge_all()
            self.db_session.commit()
            self.db_session.close()
            sleep(1)
            self.logger.info("Done.")

            return JSONAsyncResult(
                http_code = 200,
                data = { "message": "OK" },
                secure_cookie = { 'name': 'temboard', 'content': gen_cookie(role.role_name, role_hash_password)})

        except (TemboardUIError, Exception) as e:
            try:
                self.db_session.rollback()
                self.db_session.close()
            except Exception:
                pass
            self.logger.exception(str(e))
            self.logger.info("Failed.")
            sleep(1)
            return JSONAsyncResult(
                http_code = 401,
                data = { "error": "Wrong username/password."})