intrgrating suggestions after betta 1
This commit is contained in:
@@ -22,7 +22,10 @@ class Users:
|
||||
'created_at': row[12],
|
||||
'otp_code': row[13],
|
||||
'otp_expiration': row[14],
|
||||
'user_role': row[15]
|
||||
'user_role': row[15],
|
||||
'company_id': row[16],
|
||||
'active': row[17],
|
||||
'temporary_password': row[18]
|
||||
}
|
||||
return user
|
||||
|
||||
@@ -70,6 +73,28 @@ class Users:
|
||||
if hasattr(conn, "commit"):
|
||||
conn.commit()
|
||||
return inserted_id
|
||||
|
||||
def insert_company_user(self, name, email, password_hash, company_id):
|
||||
created_at = datetime.now().isoformat()
|
||||
company_id = company_id
|
||||
user_role = 'company_user'
|
||||
with get_connection() as conn:
|
||||
cursor = conn.cursor()
|
||||
returning = "RETURNING id" if is_postgres() else ""
|
||||
query = f"""
|
||||
INSERT INTO users (
|
||||
name, email, password_hash, created_at, user_role, company_id
|
||||
) VALUES ({self.ph}, {self.ph}, {self.ph}, {self.ph}, {self.ph}, {self.ph}) {returning}
|
||||
"""
|
||||
cursor.execute(query, (name, email, password_hash, created_at, user_role, company_id))
|
||||
inserted_id = None
|
||||
if is_postgres():
|
||||
inserted_id = cursor.fetchone()[0]
|
||||
else:
|
||||
inserted_id = cursor.lastrowid
|
||||
if hasattr(conn, "commit"):
|
||||
conn.commit()
|
||||
return inserted_id
|
||||
|
||||
def update_user_otp(self, user_id, otp_code, expiration):
|
||||
with get_connection() as conn:
|
||||
@@ -190,5 +215,33 @@ class Users:
|
||||
""",
|
||||
(smtp_host, smtp_port, smtp_user, user_id)
|
||||
)
|
||||
if hasattr(conn, "commit"):
|
||||
conn.commit()
|
||||
|
||||
def deactivate_user(self, user_id):
|
||||
with get_connection() as conn:
|
||||
cursor = conn.cursor()
|
||||
cursor.execute(
|
||||
f"""
|
||||
UPDATE users
|
||||
SET active = {self.ph}
|
||||
WHERE id = {self.ph}
|
||||
""",
|
||||
(0, user_id)
|
||||
)
|
||||
if hasattr(conn, "commit"):
|
||||
conn.commit()
|
||||
|
||||
def update_temp_pass(self, user_id):
|
||||
with get_connection() as conn:
|
||||
cursor = conn.cursor()
|
||||
cursor.execute(
|
||||
f"""
|
||||
UPDATE users
|
||||
SET temporary_passwrd = {self.ph}
|
||||
WHERE id = {self.ph}
|
||||
""",
|
||||
(0, user_id)
|
||||
)
|
||||
if hasattr(conn, "commit"):
|
||||
conn.commit()
|
||||
Reference in New Issue
Block a user