예제 #1
0
파일: user.py 프로젝트: garrettseward/emcit
def create_user():
    data = request.get_json()
    if User.get_by_username(data.get('username')):
        return api_error(dict(username=['Username already exists']))
    user = User.from_json(data)
    user.save()
    return jsonify(UserAdministrationResource(user))
예제 #2
0
def login():
    json = request.get_json()

    if 'username' in json:
        user = User.get_by_username(json.get('username').lower())

        if user is not None and user.check_password(json.get('password')):
            login_user(user)
            return jsonify(CurrentUserResource(user))

    return api_error(dict(form=['Invalid username/password.']))
예제 #3
0
def delete_user(id):
    user = User.get(id)

    if not user:
        return api_error('User not found', 404)
    if user.id == current_user.id:
        return api_error('Cannot delete self', 404)

    user.delete()

    return '', 202
예제 #4
0
파일: user.py 프로젝트: garrettseward/emcit
def delete_user(user_id):
    user = User.get(user_id)

    if not user:
        return form_error('User not found')
    if user.id == current_user.id:
        return form_error('Cannot delete self')

    user.delete()

    return '', 202
예제 #5
0
파일: user.py 프로젝트: garrettseward/emcit
def update_user(user_id):
    user = User.get_by_id(user_id)

    if not user:
        return form_error('User not found')

    data = request.get_json()

    if data.get('username') != user.username and User.get_by_username(
            data.get('username')):
        return api_error(dict(username=['Username already in use']))

    if 'password' in data and len(data.get('password')) > 0:
        user.set_password(data.get('password'))

    user.name = data.get('name')
    user.username = data.get('username')
    user.phone_number = data.get('phone_number')
    user.role = data.get('role')
    user.save()

    return jsonify(UserAdministrationResource(user))
예제 #6
0
def update_user(user_id):
    user = User.get_by_id(user_id)

    if not user:
        return api_error('User not found', 404)

    json = request.get_json()

    if 'password' in request.json:
        user.set_password(json.get('password'))

    user.name = json.get('name')
    user.email = json.get('email')
    user.phone_number = json.get('phone_number')
    user.role = json.get('role')
    user.save()

    return jsonify(UserAdministrationResource(user))
예제 #7
0
def load_user(user_id):
    return User.get(user_id)
예제 #8
0
def create_user():
    user = User.from_json(request.get_json())
    user.save()
    return jsonify(UserAdministrationResource(user))
예제 #9
0
def get_user(user_id):
    return jsonify(UserAdministrationResource(User.get(user_id)))
예제 #10
0
def get_users():
    return jsonify(map(UserAdministrationResource, User.all()))