本文整理汇总了Python中models.user.UserModel.add_user方法的典型用法代码示例。如果您正苦于以下问题:Python UserModel.add_user方法的具体用法?Python UserModel.add_user怎么用?Python UserModel.add_user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.user.UserModel
的用法示例。
在下文中一共展示了UserModel.add_user方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from models.user import UserModel [as 别名]
# 或者: from models.user.UserModel import add_user [as 别名]
def post(self):
args = self.get_json_arguments()
merchant_id, username, password, re_password, department, mobile, authority, is_valid = \
get_and_valid_arguments(
args, 'merchant_id', 'username', 'password', 're_password', 'department', 'mobile',
'authority', 'is_valid')
hotel_id = None
if 'hotel_id' in args:
hotel_id = args['hotel_id']
try:
hotel_id = int(hotel_id)
authority = 0
authority += PERMISSIONS.update_order
authority += PERMISSIONS.view_cooperated_hotel
authority += PERMISSIONS.view_order
authority += PERMISSIONS.inventory
authority += PERMISSIONS.pricing
authority += PERMISSIONS.update_password
except Exception:
self.finish_json('1', u'不合法的酒店')
return
if merchant_id != self.current_user.merchant_id:
self.finish_json(1, u'您只能管理自己的酒店')
return
if not username:
self.finish_json(1, u'请填写用户名')
return
if (not password) or (not re_password):
self.finish_json(1, u'请输入密码')
return
if password != re_password:
self.finish_json(1, u'两次密码不一致')
return
if not department:
self.finish_json(1, u'请输入部门')
return
if not mobile:
self.finish_json(1, u'请输入手机号')
return
if authority & PERMISSIONS.admin or authority & PERMISSIONS.root:
self.finish_json(1, u'不允许添加管理员用户')
return
user = UserModel.get_user_by_merchantid_username(
self.db, merchant_id, username)
if user:
self.finish_json(1, u'用户名已被使用')
else:
UserModel.add_user(self.db, merchant_id, username,
password, department, mobile, authority, is_valid, hotel_id)
self.finish_json(0, u'添加成功')
示例2: post
# 需要导入模块: from models.user import UserModel [as 别名]
# 或者: from models.user.UserModel import add_user [as 别名]
def post(self):
user = ObjectDict(json_decode(self.request.body))
print user
if not self.valid_new_user(user.username, user.password, user.nickname, user.department, user.permission):
self.finish_json(errcode=400, errmsg="invalid arguments")
else:
_user = UserModel.get_user_by_username(self.db, user.username)
if _user is not None:
print 'username has been used'
self.finish_json(errcode=400, errmsg="exist username")
else:
try:
_user = UserModel.add_user(
self.db, user.username, user.password, user.nickname, user.department, user.permission)
self.finish_json(result=_user.tojson())
except Exception, e:
print e
self.finish_json(errcode=507, errmsg=str(e))