示例#1
0
 def get_user(self, username: str):
     try:
         user = self.collection_users.find_one({"username": username})
         if user is not None:
             u = User()
             u.load_json(user)
             return u
         else:
             return False
     except:
         return False
示例#2
0
def register():
    u = User()
    u.load_json(request.json)
    u.password = HASH.hash(u.password)
    cookie = users_db.save(u)
    if cookie:
        Authorization.save_session(u)
        return jsonify({
            'Authorization': encode(u.json_cookie_payload()),
            "Message": "Registered"
        }), 200
    abort(401)
示例#3
0
def modify_user():
    logging.warning("llega")
    session_cookie = COOKIE_MANAGER.get_authorization_token_decoded(request)
    if session_cookie:
        session = sessions_db.get(session_cookie)
        if session:
            user = users_db.get(session_cookie.get("username"))
            if user:
                user2 = User()
                request.get_json()["password"] = user.password
                user2.load_json(request.get_json())
                modify = users_db.modify(user.username, user.password, user2)
                if modify:
                    removed = Authorization.remove_session(request)
                    if removed:
                        Authorization.save_session(user2)
                    return jsonify({
                        'Authorization':
                        encode(user2.json_cookie_payload()),
                        "Message":
                        "Modified"
                    }), 200

    abort(401)