本文整理汇总了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
示例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
示例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
示例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
示例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
示例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