示例#1
0
文件: user.py 项目: DouFM/wang_fm
 def post(self):
     args = UserLoginArgs().args
     user = get_user(name=args['name'])[0]
     if check_user_password(user, args['password']) and check_user_enable(user):
         session['user'] = user.key
         return marshal(user, user_fields)
     return None
示例#2
0
文件: user.py 项目: tiger8888/wang_fm
 def post(self):
     args = UserLoginArgs().args
     user = get_user(name=args['name'])[0]
     if check_user_password(user,
                            args['password']) and check_user_enable(user):
         session['user'] = user.key
         return marshal(user, user_fields)
     return None
示例#3
0
 def test_patch(self):
     self.login_as_admin()   # this will add a user name admin!
     user = add_user('name1', 'pw1', 'normal')
     user_key = user.key
     rv = self.app.patch('/api/user/%s/' % (user_key),
                         data={'password': '******',
                               'level': 'admin'})
     rv = json.loads(rv.data)
     assert rv['level'] == 'admin'
     user = get_user(key=user_key)[0]
     assert check_user_password(user, 'new_password')
示例#4
0
 def test_add_user(self):
     name = 'user_name'
     password = '******'
     level = 'normal'
     user = add_user(name, password, level)
     assert add_user(name, password, level) is None
     assert len(get_user(key=user.key)) == 1
     user = get_user()[0]
     assert user.name == 'user_name'
     assert user.password == _encrypt('user_name', 'user_password')
     assert check_user_password(user, 'user_password')
     assert user.level == 'normal'
示例#5
0
 def test_update_user(self):
     name = 'user_name'
     password = '******'
     level = 'normal'
     add_user(name, password, level)
     user = get_user()[0]
     update_user(user, password='******', level='disable')
     user = get_user()[0]
     assert user.name == 'user_name'
     assert user.password == _encrypt(user.name, 'new_password')
     assert check_user_password(user, 'new_password')
     assert user.level == 'disable'
     try:
         update_user(user, name='some_name')
     except AttributeError:
         pass
     try:
         update_user(user, level='some_level')
     except AssertionError:
         pass