예제 #1
0
def login():

    if request.method == 'GET':
        user_dict = request.authorization
    elif request.method == 'POST':
        user_dict = request.get_json()

    if user_dict is None or user_dict is '':
        return util.make_auth_challenge(msg='No credentials provided')

    try:
        username = user_dict['username']
    except:
        return util.make_json_error(msg='Missing username', status_code=401)
    try:
        password = user_dict['password']
    except:
        return util.make_json_error(msg='Missing password', status_code=401)

    if not User.authenticate(username, password):
        return util.make_json_error(msg='Wrong username and/or password',
                                    status_code=401)

    try:
        user = User.get_by_name(user_dict['username'])
        login_user(user)
        return util.make_json_success(msg='Success')
    except UserNotFoundError as e:
        return util.make_json_error(msg='User not found', status_code=401)
예제 #2
0
def lulebo_unauth_cord(user_uuid):
    user = User.get_by_uuid(str(user_uuid))
    json = util.lulebo_object_status(user.lulebo_session_id)

    is_connected = json['IsConnected']
    data = dict(cordConnected=True if is_connected == '1' else False,
                loginStatus=json['loginStatus'])
    return util.make_json_success(data=data)
예제 #3
0
def user_info_update():
    json_data = request.get_json()

    ## TODO: If json_data is not dict, error
    print(json_data)

    try:
        current_user.email = json_data['email']
    except:
        pass
    try:
        current_user.lulebo_username = json_data['lulebo_username']
    except:
        pass
    try:
        current_user.lulebo_password = json_data['lulebo_password']
    except:
        pass

    try:
        password = json_data['password']
    except:
        password = None
    try:
        passvalid = json_data['passvalid']
    except:
        passvalid = None

    if password is not None:
        if password == passvalid:
            current_user.password = password
        else:
            return util.make_json_error(msg='Passwords don\'t match')

    print('=== CURRENT USER ===')
    print(current_user.username)
    print(current_user.password)
    print(current_user.email)
    print(current_user.lulebo_username)
    print(current_user.lulebo_password)

    try:
        db.session.add(current_user)
        db.session.commit()
        msg, status = 'Success', 'ok'
    except Exception as e:
        db.session.rollback()
        msg, status = 'unknown error', 'error'
        print(e)
    db.session.close()
    return jsonify({'msg': msg, 'status': status})

    return util.make_json_success(msg='', data=data)
예제 #4
0
def user_info_get():
    '''
    Login by
        ```
        wget -qO- http://localhost:8081/login               \
        --save-cookies c.txt                                \
        --post-data '{"username":"******", "password":"******"}' \
        --header="Content-Type: application/json"           \
        --keep-session-cookie
        ```
        or
        ```
        wget -S -qO- http://kim:pass@localhost:8081/login \
        --save-cookies c.txt                              \
        --keep-session-cookie
        ```
        Test this resource with
        ```
        wget -qO- --load-cookies c.txt http://localhost:8081/u
        ```
        or
        ```
        wget -S -qO- http://kim:pass@localhost:8081/login \
        http://localhost:8081/u
        ```

        Testing with curl
        ```
        curl '{kim:pass@localhost:8081/login,localhost:8081/u}' -c ''
        ```

    '''

    data = {
        'username': current_user.username,
        'email': current_user.email,
        'lulebo_username': current_user.lulebo_username,
        'lulebo_password': current_user.lulebo_password,
        'uuid': current_user.uuid
    }

    return util.make_json_success(msg='', data=data)
예제 #5
0
def lulebo_unauth_direct_start(user_uuid):
    user = User.get_by_uuid(str(user_uuid))
    data = util.lulebo_direct_start(user.lulebo_session_id)
    return util.make_json_success(data=data)
예제 #6
0
def lulebo_unauth_site_info(user_uuid):
    user = User.get_by_uuid(str(user_uuid))
    data = util.lulebo_site_info(user.lulebo_session_id)
    return util.make_json_success(data=data)
예제 #7
0
def lulebo_auth_direct_start():
    data = util.lulebo_direct_start(current_user.lulebo_session_id)
    return util.make_json_success(data=data)
예제 #8
0
def lulebo_auth_object_status():
    data = util.lulebo_object_status(current_user.lulebo_session_id)
    return util.make_json_success(data=data)
예제 #9
0
def lulebo_auth_site_info():
    data = util.lulebo_site_info(current_user.lulebo_session_id)
    return util.make_json_success(data=data)
예제 #10
0
def user_uuid(user_uuid):
    print('/u/', user_uuid)
    user = User.get_by_uuid(str(user_uuid))
    return util.make_json_success(msg='', data={'username': user.username})
예제 #11
0
def say_secret_hi():
    return util.make_json_success(msg='Hello! (Logged in)')
예제 #12
0
def say_hi():
    return util.make_json_success(msg='Hello!')
예제 #13
0
def logout():
    logout_user()
    return util.make_json_success(msg='Logged out')