def delete_user_verification(email_verification: EmailVerification):
    db.checkConnection()
    if not db.isConnected():
        return None
    db.execute('DELETE FROM User_Verification WHERE token = ?',
               (email_verification.token, ))
    db.connection.commit()
Beispiel #2
0
def get_user_by_email(email):
    db.checkConnection()
    if not db.isConnected():
        return None
    db.execute('SELECT * FROM User_Users WHERE email = ?', (email, ))
    result = db.cursor.fetchone()
    return __extract_user_from_database_request(result)
Beispiel #3
0
def activate_user(uuid):
    db.checkConnection()
    if not db.isConnected():
        return None
    db.execute('UPDATE User_Users SET status = ? WHERE uuid = ?',
               (Status.VERIFIED, uuid))
    db.connection.commit()
Beispiel #4
0
def create_teacher(teacher: Teacher):
    db.checkConnection()
    if not db.isConnected():
        return None
    db.execute(
        'INSERT INTO User_Teachers (user_uuid, schoolDomain, token) VALUES (?, ?, ?)',
        (teacher.user_uuid, teacher.school_domain, teacher.token))
    db.connection.commit()
def create_user_verification(user: User, token: str):
    db.checkConnection()
    if not db.isConnected():
        return None
    db.execute(
        'INSERT INTO User_Verification (user_uuid, verification_code) VALUES (?, ?)',
        (user.uuid, token))
    db.connection.commit()
Beispiel #6
0
def search_teacher_token(token: str) -> bool:
    db.checkConnection()
    if not db.isConnected():
        return None
    db.execute('SELECT * FROM User_Teachers WHERE token = ?', (token, ))
    result = db.cursor.fetchone()
    if result is None:
        return False
    return True
Beispiel #7
0
def create_user(user: User):
    db.checkConnection()
    if not db.isConnected():
        return None
    db.execute(
        'INSERT INTO User_Users (uuid, email, password, firstName, lastName, status, role) VALUES (?, ?, ?, ?, ?, ?, ?)',
        (user.uuid, user.email, user.password, user.first_name, user.last_name,
         user.status.value, user.role.value))
    db.connection.commit()
Beispiel #8
0
def asign_teacher_token_to_user(user: User, token: str) -> bool:
    db.checkConnection()
    if not db.isConnected():
        return None
    if not search_teacher_token(token):
        return False
    db.execute('UPDATE FROM User_Teachers SET user_uuid = ? WHERE token = ?',
               (user.uuid, token))
    db.connection.commit()
    return True
def get_user_verification(token: str) -> EmailVerification:
    db.checkConnection()
    if not db.isConnected():
        return None
    db.execute('SELECT * FROM User_Verification WHERE token = ?', (token, ))
    result = db.cursor.fetchone()
    if result is not None:
        result = EmailVerification(result.user_uuid, result.verification_code,
                                   result.createdAt)
    return result
Beispiel #10
0
def delete_teacher(teacher: Teacher):
    db.checkConnection()
    if not db.isConnected():
        return None
    db.execute('DELETE FROM User_Teachers WHERE token = ?', (teacher.token, ))
    db.connection.commit()
Beispiel #11
0
def delete_user(uuid):
    db.checkConnection()
    if not db.isConnected():
        return None
    db.execute('DELETE FROM User_Users WHERE uuid = ?', (uuid, ))
    db.connection.commit()
Beispiel #12
0
def user_exists(uuid):
    db.checkConnection()
    if not db.isConnected():
        return None
    db.execute('SELECT uuid FROM User_Users WHERE uuid = ?', (uuid, ))
    return db.cursor.fetchone() is not None
Beispiel #13
0
def update_user(user: User):
    db.checkConnection()
    if not db.isConnected():
        return None
    if user.email is not None:
        db.execute('UPDATE User_Users SET email = ? WHERE uuid = ?',
                   (user.email, user.uuid))
    if user.password is not None:
        db.execute('UPDATE User_Users SET password = ? WHERE uuid = ?',
                   (user.password, user.uuid))
    if user.first_name is not None:
        db.execute('UPDATE User_Users SET firstName = ? WHERE uuid = ?',
                   (user.first_name, user.uuid))
    if user.last_name is not None:
        db.execute('UPDATE User_Users SET lastName = ? WHERE uuid = ?',
                   (user.last_name, user.uuid))
    if user.status is not None:
        db.execute('UPDATE User_Users SET accountStatus = ? WHERE uuid = ?',
                   (user.status.value, user.uuid))
    if user.role is not None:
        db.execute('UPDATE User_Users SET role = ? WHERE uuid = ?',
                   (user.role.value, user.uuid))
    db.connection.commit()