示例#1
0
def create_user():
    data = utils.parse_json_body(request)

    if 'username' not in data:
        raise exception.ParameterMissing(name="username")

    if not data['username'] or not data['username'].strip():
        raise exception.ParameterMissing(name="username")

    if users.exists(username=data['username']):
        raise exception.Conflict(
            reason="User with username '%s' already exists" % data['username'])

    if 'firstname' not in data:
        raise exception.ParameterMissing(name="firstname")

    if 'lastname' not in data:
        raise exception.ParameterMissing(name="lastname")

    user = User(username=data['username'],
                firstname=data['firstname'],
                lastname=data['lastname'])

    if 'password' in data:
        user.password = data['password']

    id = users.save(user)
    return get_user(id)
示例#2
0
def authenticate():
    if 'username' not in request.args:
        raise exception.ParameterMissing(name="username")
    if 'password' not in request.args:
        raise exception.ParameterMissing(name="password")

    token, expires = auth.get_token(request.args['username'],
                                    request.args['password'])
    response = make_response('', 201)
    response.set_cookie('X-Auth-Username', request.args['username'], expires=expires)
    response.set_cookie('X-Auth-Token', token, expires=expires)
    return response
示例#3
0
def update_user(id):
    data = utils.parse_json_body(request)

    if 'id' in data and int(data['id']) != int(id):
        raise exception.Conflict(reason="Id mismatch")

    if 'firstname' not in data:
        raise exception.ParameterMissing(name="firstname")

    if 'lastname' not in data:
        raise exception.ParameterMissing(name="lastname")

    user = User(firstname=data['firstname'], lastname=data['lastname'])
    user.id = id

    if 'password' in data:
        user.password = data['password']

    users.update(user)
    return get_user(id)
示例#4
0
def authenticate():
    try:
        data = json.loads(request.data)
    except ValueError:
        raise exception.BodySyntaxError()

    if 'username' not in data:
        raise exception.ParameterMissing(name="username")
    if 'password' not in data:
        raise exception.ParameterMissing(name="password")

    token, expires = auth.get_token(data['username'], data['password'])

    date = datetime.datetime.fromtimestamp(expires).strftime(
        '%Y-%m-%dT%H:%M:%SZ')

    resp_data = {'token': token, 'expires': date}
    response = make_response(json.dumps(resp_data), 201)
    response.set_cookie('X-Auth-Username', data['username'], expires=expires)
    response.set_cookie('X-Auth-Token', token, expires=expires)
    return response
示例#5
0
def set_blade_short_onoff():
    if 'bladeId' not in request.args:
        raise exception.ParameterMissing(name="bladeId")
    return gpio.set_blade_short_onoff(request.args['bladeId'])
示例#6
0
def set_power_on():
    if 'bladeId' not in request.args:
        raise exception.ParameterMissing(name="bladeId")
    return gpio.set_power_on(request.args['bladeId'])
示例#7
0
def get_blade_oil_pump_state():
    if 'bladeId' not in request.args:
        raise exception.ParameterMissing(name="bladeId")
    return gpio.get_blade_oil_pump_state(request.args['bladeId'])
示例#8
0
def start_blade_serial_session():
    if 'bladeId' not in request.args:
        raise exception.ParameterMissing(name="bladeId")
    return gpio.start_blade_serial_session(request.args['bladeId'])