Esempio n. 1
0
	def run_createuser_test(self, superuser, editor):
		self.admin_login()

		# Create user
		u = User('test', 'Test User', 'test1234', superuser, editor)
		resp = json.loads(self.post_req('user/create', {'username': '******', 'fullname': 'Test User', 'password': '******', 'superuser': superuser, 'editor': editor}).read())
		self.assertFalse('status' in resp)
		u.id = resp['id']

		# Check user profile
		resp = json.loads(self.get_req('user/profile/%d'%u.id).read())
		self.assertFalse('status' in resp)
		self.assertEqual(resp['superuser'], superuser)
		self.assertEqual(resp['editor'], editor)

		# Delete user
		resp = json.loads(self.get_req('user/delete/%d'%u.id).read())
		self.assertFalse('status' in resp)
Esempio n. 2
0
def create_user(request):
    try:
        u = session.query(User).filter(User.username == request.form["username"]).one()
        logging.debug("Not creating user %s, username already in use." % request.form["username"])
        return DuplicateError
    except NoResultFound:
        pass
    u = User(
        request.form["username"],
        request.form["fullname"],
        hash_password(request.form["password"]),
        request.form["editor"] == "true",
        request.form["superuser"] == "true",
    )
    # handle query errors and return a valid response
    session.add(u)
    session.commit()
    u = session.query(User).filter(User.username == request.form["username"]).one()
    return render_json(u.to_api_dict())
Esempio n. 3
0
def user_profile(request, user_id):
    if user_id == -1:
        user = User("admin", "Administrator User", "", False, True, True)
        user.id = -1
        return render_json(user.to_api_dict())
    return render_json(session.query(User).filter(User.id == user_id).one().to_api_dict())