Example #1
0
 def create(self, user: User) -> User:
     try:
         one_user = self.collection.insert_one(self.to_bson(user))
     except DuplicateKeyError:
         raise UserExists
     user.id = str(one_user.inserted_id)
     return user
Example #2
0
def login():
    """ Attempt to login for exising user """
    if request.method == "POST": 
        if request.form["btn"] == "login":
            try:
                # check 1 if such user exists
                usr = db.session.query(User)\
                        .filter(User.username == request.form["login"])\
                        .first()
                # check 2 if the password is correct
                if usr.verify_pwd(request.form["password"]):
                    token = usr.current_auth_token
                    # check for token 
                    if token is None:
                        token, date = generate_auth_token()
                        usr.current_auth_token = token
                        usr.last_action = date
                        db.session.commit()
                    session['user'] = usr.current_auth_token
                    return redirect(url_for("api.quantify"))
                else:
                    return render_template("login.html")
            except Exception as ex:
                logger.error(f"could not log in the user {request.form['login']} due to {ex}")
                return render_template("login.html")
        else:
            new_user = User(str(request.form["login"]), str(request.form["password"]))
            try:
                # let SQL handle duplicate dtection on username
                db.session.add(new_user)
                db.session.commit()
                return render_template("login.html")
            except Exception as ex:
                print(f"could not add a new user {new_user.__repr__} due to {ex}")
                return render_template("login.html")

    return render_template("login.html")
Example #3
0
 def __init__(self):
     self.__db = User.get_instance().get_servers_db()
Example #4
0
 def __init__(self):
     self.__db = User.get_instance().get_servers_db()
Example #5
0
	def __init__(self):
		self.__db = User.getInstance().getServersDB()
Example #6
0
 def __init__(self):
     # read user's endpoint list
     self._db = User.get_instance().get_servers_db()
Example #7
0
 def from_bson(cls, document) -> User:
     document['id'] = str(document.pop('_id'))
     return User(**document)
Example #8
0
 def __init__(self):
     # read user's endpoint list
     self._db = User.get_instance().get_servers_db()