Пример #1
0
    def get_api_token(cls, access_token):

        connection = get_connection()
        with connection.cursor() as cursor:
            sql = "select api_token from users FULL OUTER JOIN tokens where %s = token"
            cursor.execute(sql, [access_token])
            result = cursor.fetchone()
        return result('api_token')
Пример #2
0
    def get_api_token(cls, access_token):

        connection = get_connection()
        with connection.cursor() as cursor:
            sql = "select api_token from users FULL OUTER JOIN tokens where %s = token"
            cursor.execute(sql, [access_token])
            result = cursor.fetchone()
        return result('api_token')
Пример #3
0
    def check_login(cls, email, password):

        connection = get_connection()
        with connection.cursor() as cursor:
            sql = "select email, password from users where email = %s"
            cursor.execute(sql, [email])
            result = cursor.fetchone()
            if cursor.rowcount == 1:
                if password == result['password']:
                    return True
        return False
Пример #4
0
    def check_login(cls, email, password):

        connection = get_connection()
        with connection.cursor() as cursor:
            sql = "select email, password from users where email = %s"
            cursor.execute(sql, [email])
            result = cursor.fetchone()
            if cursor.rowcount == 1:
                if password == result['password']:
                    return True
        return False
Пример #5
0
 def checkToken(cls, token):
     connection = get_connection()
     try:
         with connection.cursor() as cursor:
             sql = 'SELECT token from tokens WHERE token = %s'
             cursor.execute(sql, [token])
             result = cursor.fetchone()
             if result['token'] == token:
                 return True
         return False
     except:
         return False
     finally:
         connection.close()
Пример #6
0
 def checkToken(cls, token):
     connection = get_connection()
     try:
         with connection.cursor() as cursor:
             sql = 'SELECT token from tokens WHERE token = %s'
             cursor.execute(sql, [token])
             result = cursor.fetchone()
             if result['token'] == token:
                 return True
         return False
     except:
         return False
     finally:
         connection.close()
Пример #7
0
    def get_token(cls, email, hashed_pwd):

        connection = get_connection()
        try:
            with connection.cursor() as cursor:
                sql = "SELECT token, date FROM tokens WHERE email = %s"
                cursor.execute(sql, [email])
                result = cursor.fetchone()
                if cursor.rowcount == 1:
                    current__time_in_seconds = cls.get_current_time_in_seconds()
                    if current__time_in_seconds - int(result['date']) <= 60 * 60 * 24:
                        return result['token']
                return cls.create_token(email, hashed_pwd)
        finally:
            connection.close()
Пример #8
0
 def create_user(cls, email, pwd, token):
     connection = get_connection()
     try:
         with connection.cursor() as cursor:
             sql = 'SELECT email FROM users WHERE email = %s'
             cursor.execute(sql, [email])
             result = cursor.fetchone()
             if cursor.rowcount == 0:
                 sql = 'INSERT INTO users(email, password, api_token) VALUES (%s, %s, %s)'
                 cursor.execute(sql, [email, pwd, token])
                 connection.commit()
             else:
                 sql = 'UPDATE users SET password = %s, api_token = %s WHERE email = %s'
                 cursor.execute(sql, [pwd, token, email])
                 connection.commit()
     finally:
         connection.close()
Пример #9
0
 def create_user(cls, email, pwd, token):
     connection = get_connection()
     try:
         with connection.cursor() as cursor:
             sql = 'SELECT email FROM users WHERE email = %s'
             cursor.execute(sql, [email])
             result = cursor.fetchone()
             if cursor.rowcount == 0:
                 sql = 'INSERT INTO users(email, password, api_token) VALUES (%s, %s, %s)'
                 cursor.execute(sql, [email, pwd, token])
                 connection.commit()
             else:
                 sql = 'UPDATE users SET password = %s, api_token = %s WHERE email = %s'
                 cursor.execute(sql, [pwd, token, email])
                 connection.commit()
     finally:
         connection.close()
Пример #10
0
    def get_token(cls, email, hashed_pwd):

        connection = get_connection()
        try:
            with connection.cursor() as cursor:
                sql = "SELECT token, date FROM tokens WHERE email = %s"
                cursor.execute(sql, [email])
                result = cursor.fetchone()
                if cursor.rowcount == 1:
                    current__time_in_seconds = cls.get_current_time_in_seconds(
                    )
                    if current__time_in_seconds - int(
                            result['date']) <= 60 * 60 * 24:
                        return result['token']
                return cls.create_token(email, hashed_pwd)
        finally:
            connection.close()
Пример #11
0
    def create_token(cls, email, hashed_pwd):

        connection = get_connection()
        try:
            with connection.cursor() as cursor:

                sql = 'SELECT token FROM users FULL JOIN tokens WHERE tokens.email = %s AND password = %s'
                cursor.execute(sql, [email, hashed_pwd])
                seconds = cls.get_current_time_in_seconds()
                token = hash_sha(email + hashed_pwd + str(seconds) + SALT)
                if cursor.rowcount == 1:
                    sql = 'UPDATE tokens SET token = %s, date = %s WHERE email = %s'
                    cursor.execute(sql, [token, seconds, email])
                    connection.commit()
                    return token
                else:
                    sql = 'INSERT INTO tokens(email, token, date) VALUES (%s, %s, %s)'
                    cursor.execute(sql, [email, token, seconds])
                    connection.commit()
                    return token
        finally:
            connection.close()
        return None
Пример #12
0
    def create_token(cls, email, hashed_pwd):

        connection = get_connection()
        try:
            with connection.cursor() as cursor:

                sql = 'SELECT token FROM users FULL JOIN tokens WHERE tokens.email = %s AND password = %s'
                cursor.execute(sql, [email, hashed_pwd])
                seconds = cls.get_current_time_in_seconds()
                token = hash_sha(email + hashed_pwd + str(seconds) + SALT)
                if cursor.rowcount == 1:
                    sql = 'UPDATE tokens SET token = %s, date = %s WHERE email = %s'
                    cursor.execute(sql, [token, seconds, email])
                    connection.commit()
                    return token
                else:
                    sql = 'INSERT INTO tokens(email, token, date) VALUES (%s, %s, %s)'
                    cursor.execute(sql, [email, token, seconds])
                    connection.commit()
                    return token
        finally:
            connection.close()
        return None
Пример #13
0
 def get_connection(self):
     if not self.connection.open:
         self.connection = db_connector.get_connection()
     return self.connection
Пример #14
0
 def __init__(self):
     self.connection = db_connector.get_connection()
Пример #15
0
 def get_connection(self):
     if not self.connection.open:
         self.connection = db_connector.get_connection()
     return self.connection
Пример #16
0
 def __init__(self):
     self.connection = db_connector.get_connection()