Add is_admin property to person table
This commit is contained in:
@@ -12,11 +12,12 @@ class Person:
|
|||||||
"""
|
"""
|
||||||
Simple Person class compatible with Flask-Login.
|
Simple Person class compatible with Flask-Login.
|
||||||
"""
|
"""
|
||||||
def __init__(self, person_id, name, email, password_hash):
|
def __init__(self, person_id, name, email, password_hash, is_admin=False):
|
||||||
self.id = person_id
|
self.id = person_id
|
||||||
self.name = name
|
self.name = name
|
||||||
self.email = email
|
self.email = email
|
||||||
self.password_hash = password_hash
|
self.password_hash = password_hash
|
||||||
|
self.is_admin = is_admin
|
||||||
|
|
||||||
def get_id(self):
|
def get_id(self):
|
||||||
"""Required by Flask-Login to get a unique user identifier."""
|
"""Required by Flask-Login to get a unique user identifier."""
|
||||||
@@ -44,14 +45,14 @@ def get_person_by_id(person_id):
|
|||||||
Fetch a person record by person_id and return a Person object.
|
Fetch a person record by person_id and return a Person object.
|
||||||
"""
|
"""
|
||||||
sql = """
|
sql = """
|
||||||
SELECT person_id, name, email, password_hash
|
SELECT person_id, name, email, password_hash, is_admin
|
||||||
FROM person
|
FROM person
|
||||||
WHERE person_id = %s
|
WHERE person_id = %s
|
||||||
LIMIT 1
|
LIMIT 1
|
||||||
"""
|
"""
|
||||||
row = db.execute(sql, [person_id], one=True)
|
row = db.execute(sql, [person_id], one=True)
|
||||||
if row:
|
if row:
|
||||||
return Person(row['person_id'], row['name'], row['email'], row['password_hash'])
|
return Person(row['person_id'], row['name'], row['email'], row['password_hash'], row['is_admin'])
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
@@ -60,14 +61,14 @@ def get_person_by_email(email):
|
|||||||
Fetch a person record by email and return a Person object.
|
Fetch a person record by email and return a Person object.
|
||||||
"""
|
"""
|
||||||
sql = """
|
sql = """
|
||||||
SELECT person_id, name, email, password_hash
|
SELECT person_id, name, email, password_hash, is_admin
|
||||||
FROM person
|
FROM person
|
||||||
WHERE email = %s
|
WHERE email = %s
|
||||||
LIMIT 1
|
LIMIT 1
|
||||||
"""
|
"""
|
||||||
row = db.execute(sql, [email], one=True)
|
row = db.execute(sql, [email], one=True)
|
||||||
if row:
|
if row:
|
||||||
return Person(row['person_id'], row['name'], row['email'], row['password_hash'])
|
return Person(row['person_id'], row['name'], row['email'], row['password_hash'], row['is_admin'])
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user