当前位置: 首页>>代码示例>>Python>>正文


Python User.user_from_dict方法代码示例

本文整理汇总了Python中models.user.User.user_from_dict方法的典型用法代码示例。如果您正苦于以下问题:Python User.user_from_dict方法的具体用法?Python User.user_from_dict怎么用?Python User.user_from_dict使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.user.User的用法示例。


在下文中一共展示了User.user_from_dict方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: post

# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import user_from_dict [as 别名]
    def post(self):
        login = request.headers["X-Login"]
        password = request.headers["X-Password"]

        if (login or password) is None:
            return '', 404

        user_dict = mongo.db.users.find_one({"password": self.hash_password(password), "login": login})

        if user_dict is None:
            return '', 403

        session_dict = mongo.db.sessions.find_one({"user.login": login, "status": 0})

        """ we do not create a new session if already exists"""
        if session_dict is not None:
            return Session.session_from_dict(session_dict).format_http(), 201

        user_dict["_id"] = str(user_dict["_id"])
        user = User.user_from_dict(user_dict)

        session = Session.session_from_user(user)
        mongo.db.sessions.insert(session.format())

        return session.format_http(), 201
开发者ID:hellich,项目名称:questionnaire,代码行数:27,代码来源:Authentication.py

示例2: post

# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import user_from_dict [as 别名]
    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
开发者ID:hellich,项目名称:questionnaire,代码行数:19,代码来源:UserServices.py

示例3: delete

# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import user_from_dict [as 别名]
    def delete(self, login):
        authorize(request.headers["Authorization"])

        if login == SUPER_USER:
            abort(403)

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

        user_delete = User.user_from_dict(existing)
        user_delete.deleteDate = datetime.now()

        delete_id = mongo.db.users_deleted.insert(user_delete.format_for_delete())

        mongo.db.users.remove({"login": login})

        print "deleted : ", delete_id

        return {"message": "deleted"}, 200
开发者ID:hellich,项目名称:questionnaire,代码行数:20,代码来源:UserServices.py

示例4: put

# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import user_from_dict [as 别名]
    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
开发者ID:hellich,项目名称:questionnaire,代码行数:23,代码来源:UserServices.py

示例5: get_all_users

# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import user_from_dict [as 别名]
    def get_all_users(self):
        users = []
        for user in mongo.db.users.find():
            users.append(User.user_from_dict(user).format())

        return users, 200
开发者ID:hellich,项目名称:questionnaire,代码行数:8,代码来源:UserServices.py

示例6: get_a_user

# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import user_from_dict [as 别名]
 def get_a_user(self, login):
     user = mongo.db.users.find_one_or_404({"login": login})
     return User.user_from_dict(user).format(), 200
开发者ID:hellich,项目名称:questionnaire,代码行数:5,代码来源:UserServices.py


注:本文中的models.user.User.user_from_dict方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。