diff options
Diffstat (limited to 'src/lb_app/app_db/user.py')
-rw-r--r-- | src/lb_app/app_db/user.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/lb_app/app_db/user.py b/src/lb_app/app_db/user.py new file mode 100644 index 0000000..1af957c --- /dev/null +++ b/src/lb_app/app_db/user.py @@ -0,0 +1,27 @@ +from flask import current_app + +from .db import MongoDB + +class User(object): + def __init__(self, app=None): + self.app = app + + def all(self): + db = MongoDB(self.app) + mongo = db.connection() + return list(mongo.db.users.find({})) + + def register(self, username): + db = MongoDB(self.app) + mongo = db.connection() + error = None + + if not username: + error = 'Username is required.' + elif len(list(mongo.db.users.find({"username": username}))) > 0: + error = 'User {} is already registered.'.format(username) + + if error is None: + mongo.db.users.insert({"username": username}) + return None + return error |