Ejemplo n.º 1
0
def login_post():
    data = request_dict.create()

    email = data.email.lower().strip()
    password = data.password.strip()

    if not email or not password:
        return {
            'email': email,
            'password': password,
            'error': 'Some required fields are missing',
            'user_id': cookie_auth.get_user_id_via_auth_cookie(flask.request),
        }
    # TODO: Validate the user
    user = user_service.login_user(email, password)
    if not user:
        return {
            'email': email,
            'password': password,
            'error': 'The account does not exist or the password is wrong',
            'user_id': cookie_auth.get_user_id_via_auth_cookie(flask.request),
        }
    # TODO: log in browser as a session
    resp = flask.redirect('/account')
    cookie_auth.set_auth(resp, user.id)
    return resp
Ejemplo n.º 2
0
def login_post():

    data = request_dict.create(default_val='')

    email = data.email.lower().strip()
    password = data.password.strip()

    if not email or not password:
        return {
            'email': email,
            'password': password,
            'error': "Some required fields are missing"
        }

    # TODO: Validate the user
    user = user_service.login_user(email, password)
    if not user:
        return {
            'email': email,
            'password': password,
            'error': "The account does not exist or the password is incorrect"
        }

    resp = flask.redirect(url_for('account.index'))
    cookie_auth.set_auth(resp, user.id)
    return resp
def login_post():
    # TODO: create view model for login
    data = request_dict.create()
    r = flask.request
    email = data.email.lower().strip()
    password = data.password.strip()

    if not email or not password:
        return {
            'email': email,
            'password': password,
            'error': "Some require fields are missing",
        }

    user = user_service.login_user(email, password)

    if not user:
        return {
            'email': email,
            'password': password,
            'error': "The account does not exist or the password is wrong",
        }

    resp = flask.redirect('/account')
    cookie_auth.set_auth(resp, user.id)
    return resp
Ejemplo n.º 4
0
def login_post():
    data = request_dict.create(default_val='')

    email = data.email.lower().strip()
    password = data.password.strip()

    if not email or not password:
        return {
            'email': email,
            'password': password,
            'error': "Some required fields are missing.",
            'user_id': cookie_auth.get_user_id_via_auth_cookie(flask.request),
        }

    user = user_service.login_user(email, password)
    if not user:
        return {
            'email': email,
            'password': password,
            'error': "The account does not exist or the password is wrong.",
            'user_id': cookie_auth.get_user_id_via_auth_cookie(flask.request),
        }

    resp = flask.redirect('/account')
    cookie_auth.set_auth(resp, user.id)

    return resp
Ejemplo n.º 5
0
def test_01_add_product():
    user_token = login_user("*****@*****.**",
                            "Qwerty11")["session"]["accessToken"]
    headers = {"Authorization": f"Bearer {user_token}"}
    r = requests.post(url=absolute_url("/products"),
                      json=product_model,
                      headers=headers)

    assert r.status_code == 201
Ejemplo n.º 6
0
def admin_signup_post():
    form = request.form
    init_key = open('initialization_key.txt').read()
    if init_key == form['init_key']:
        flash("Initialization Confirmed.")
        csrf_valid = user_svc.csrf_validate(csrf_token)
        msg = user_svc.add_new_user(name,email,password)
        if msg == "" and csrf_valid:
            msg = user_svc.login_user(form['name'], form['password'])
            return redirect(url_for('read.index'))
        else:
            flash(msg)
    else:
        flash("Initializaton Key Error.")
        return {"csrf_token":user_svc.csrf_new_token()}
Ejemplo n.º 7
0
def test_03_delete_product():
    user_token = login_user("*****@*****.**",
                            "Qwerty11")["session"]["accessToken"]
    headers = {"Authorization": f"Bearer {user_token}"}
    add_product = requests.post(url=absolute_url("/products"),
                                json=product_model,
                                headers=headers)
    response = add_product.json()
    product_id = response["data"][0]["id"]
    r = requests.delete(url=absolute_url(f"/products/{product_id}"),
                        headers=headers)

    assert r.status_code == 204
    product_details = requests.get(url=absolute_url(f"/products/{product_id}"),
                                   headers=headers)
    assert product_details.status_code == 404
Ejemplo n.º 8
0
def login_post():
    vm = LoginViewModel()
    vm.validate()

    if vm.error:
        return vm.to_dict()

    user = user_service.login_user(vm.email, vm.password)
    if not user:
        vm.error = "The account does not exist or the password is wrong."
        return vm.to_dict()

    resp = flask.redirect('/account')
    cookie_auth.set_auth(resp, user.id)

    return resp
Ejemplo n.º 9
0
async def login_post(request: Request):
    vm = LoginViewModel(request)
    await vm.load()

    if vm.error:
        return vm.to_dict()

    # Create the account
    user = user_service.login_user(vm.email, vm.password)
    if not user:
        vm.error = "The account does not exist or the password is wrong."
        return vm.to_dict()
    # Login user

    response = fastapi.responses.RedirectResponse(
        url='/account', status_code=status.HTTP_302_FOUND)
    cookie_auth.set_auth(response, user.id)
    return response
Ejemplo n.º 10
0
def login_user():
    body = request.get_json()

    possible_params = ['username', 'password']
    try:
        check_parameters(params=body, required=possible_params, possible=possible_params)
    except exceptions.ParamsError as e:
        return {"message": e.message}, 400

    username = body['username']
    password = body['password']
    try:
        access_token = user_service.login_user(username, password)
    except exceptions.InvalidUsernameOrPassword:
        return {"message": "Invalid username or password"}, 400
    return {
            'token': access_token
           }, 200
Ejemplo n.º 11
0
def login_user():
    body = request.get_json()

    possible_params = ['username', 'password']
    try:
        check_parameters(params=body,
                         required=possible_params,
                         possible=possible_params)
    except exceptions.ParamsError as e:
        return {"message": e.message}, 400

    try:
        token = user_service.login_user(body['username'], body['password'])
    except exceptions.InvalidUsernameOrPassword:
        return {"message": "Invalid username or password"}, 400
    except exceptions.UserAuthServerError:
        return "", 500
    return {'token': token}, 200
Ejemplo n.º 12
0
def login_post():
    vm = LoginViewModel()
    vm.validate()

    if vm.error:
        return render_template("account/login.html", error=vm.error)

    user = user_service.login_user(vm.username, vm.password)
    if not user:
        return render_template("account/login.html",
                               username=vm.username,
                               error="The account does not exist or the "
                               "password is wrong.")

    # Validate the user
    login_user(user)

    return redirect("/account")
Ejemplo n.º 13
0
def test_02_edit_product():
    user_token = login_user("*****@*****.**",
                            "Qwerty11")["session"]["accessToken"]
    headers = {"Authorization": f"Bearer {user_token}"}
    add_product = requests.post(url=absolute_url("/products"),
                                json=product_model,
                                headers=headers)
    response = add_product.json()
    product_id = response["data"][0]["id"]
    r = requests.put(url=absolute_url(f"/products/{product_id}"),
                     json=product_model_edited,
                     headers=headers)
    response = r.json()

    assert r.status_code == 200
    assert response['data']['size'] == 15
    assert response['data']['stockAvail'] == 15
    assert response['data']['thc'] == 15
    assert response['data']['cbd'] == 21