Пример #1
0
    def post(self):
        authorize(request.headers["Authorization"])

        user = User.user_from_dict(post_parser.parse_args())
        user.password = hashlib.sha256(user.password).hexdigest()
        user.creationDate = datetime.now()

        existing = mongo.db.users.find_one({"login": user.login})

        if not (existing is None):
            abort(409)

        user_id = mongo.db.users.insert(user.format_for_create())
        user._id = user_id
        print "inserted : ", user_id

        return user, 201
Пример #2
0
    def post(self):
        authorize(request.headers["Authorization"])

        user = User.user_from_dict(post_parser.parse_args())
        user.password = hashlib.sha256(user.password).hexdigest()
        user.creationDate = datetime.now()

        existing = mongo.db.users.find_one({"login":user.login})

        if not (existing is None):
            abort(409)

        user_id = mongo.db.users.insert(user.format_for_create())
        user._id = user_id
        print "inserted : ", user_id

        return user, 201
Пример #3
0
    def put(self, login):
        authorize(request.headers["Authorization"])

        if login == SUPER_USER:
            abort(403)

        existing = mongo.db.users.find_one({"login": login})
        if existing is None:
            abort(404)

        user_edit = User.user_from_dict(post_parser.parse_args())
        user_edit.password = hashlib.sha256(user_edit.password).hexdigest()
        user_edit.creationDate = existing.get('creationDate')

        print user_edit.format()

        mongo.db.users.update({"login": login}, {"$set": user_edit.format_for_update()})

        print "modified : ", user_edit

        return user_edit, 201
Пример #4
0
    def put(self, login):
        authorize(request.headers["Authorization"])

        if login == SUPER_USER:
            abort(403)

        existing = mongo.db.users.find_one({"login": login})
        if existing is None:
            abort(404)

        user_edit = User.user_from_dict(post_parser.parse_args())
        user_edit.password = hashlib.sha256(user_edit.password).hexdigest()
        user_edit.creationDate = existing.get('creationDate')

        print user_edit.format()

        mongo.db.users.update({"login": login},
                              {"$set": user_edit.format_for_update()})

        print "modified : ", user_edit

        return user_edit, 201