def register_post():
    data = request_dict.create(default_val='')

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

    if not name or not email or not password:
        return {
            'name': name,
            '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.create_user(name, email, password)
    if not user:
        return {
            'name': name,
            'email': email,
            'password': password,
            'error': "A user with that email already exists.",
            '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
def register_post():
    r = flask.request

    name = r.form.get("name")
    email = r.form.get("email", "").lower().strip()
    password = r.form.get("password", "").strip()

    if not name or not email or not password:
        return {
            "error": "Some required fields are missing",
            "name": name,
            "email": email,
            "password": password
        }
    user = user_service.create_user(name, email, password)
    if not user:
        return {
            "error": "A user with that email already exist",
            "name": name,
            "email": email,
            "password": password
        }

    resp = flask.redirect("/account")
    cookie_auth.set_auth(resp, user.id)
    return resp
Beispiel #3
0
def register_post():
    r = flask.request

    name = r.form.get('name')
    email = r.form.get('email', '').lower().strip()
    password = r.form.get('password', '').strip()

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

    # TODO: Create the user
    user = user_service.create_user(name, email, password)
    if not user:
        return {
            'name': name,
            'email': email,
            'password': password,
            'error': "A user with that email already exists."
        }

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

    return resp
Beispiel #4
0
def insert_a_user():
    success = create_user(
        name="Andrew",
        email="*****@*****.**",
        password="******",
        profile_image_url=None,
    )
    if success:
        print("User added successfully")
    else:
        print("User not added")
def register_post():
    vm = RegisterViewModel()
    vm.validate()

    if vm.error:
        return vm.to_dict()

    user = user_service.create_user(vm.name, vm.email, vm.password)
    if not user:
        vm.error = 'The account could not be created'
        return vm.to_dict()

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

    return resp
def register_post():
    vm=RegisterViewModel()
    vm.validate()

    if vm.error:
        return vm.to_dict()

    user = user_service.create_user(vm.name, vm.email, vm.password)
    if not user:
        vm.error="A user with that email already exists."
        return vm.to_dict()

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

    return resp
Beispiel #7
0
def register_post():
    view_model = RegisterViewModel()
    view_model.validate()

    if view_model.error:
        return view_model.to_dict()

    user = user_service.create_user(view_model.name, view_model.email,
                                    view_model.password)

    if not user:
        return view_model.to_dict()

    resp = flask.redirect('/account')
    cookie_auth.set_auth(resp, user.id)
    return resp
def register_post():
    log.notice(f"Anonymous user is registering for a new account")

    vm = RegisterViewModel()
    vm.validate()

    if vm.error:
        log.notice(f"User could not create account, error: {vm.error}.")
        return vm.to_dict()

    user = user_service.create_user(vm.name, vm.email, vm.password)
    if not user:
        vm.error = 'The account could not be created'
        log.notice(f"User could not create account, error: {vm.error}.")
        return vm.to_dict()

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

    log.notice(f"User SUCCESSFULLY created account: {user.name} - {user.email}.")
    return resp
def auth():
    args = flask.request.args

    if flask.request.args.get('state') != session.get("state"):
        return flask.redirect('/')  # No-OP. Goes back to Index page
    if "error" in flask.request.args:  # Authentication/Authorization failure

        return f"There was an error logging in: Error: {args.get('error')}, details: {args.get('error_description')}."
    if flask.request.args.get('code'):
        cache = session_cache.load_cache()
        result = msal_builder.build_msal_app(
            cache=cache).acquire_token_by_authorization_code(
                flask.request.args['code'],
                scopes=app_config.
                SCOPE,  # Misspelled scope would cause an HTTP 400 error here
                redirect_uri='http://localhost:5006/account/auth')
        if "error" in result:
            return f"There was an error logging in: Error: {args.get('error')}, details: {args.get('error_description')}."

        session_cache.save_cache(cache)
        # 'oid': '257af28c-d791-4287-bf95-b67578dae57e',
        claims = result['id_token_claims']

        email = claims.get('emails', ['NONE'])[0].strip().lower()
        first_name = claims.get('given_name')
        last_name = claims.get('family_name')

        user = user_service.find_user_by_email(email)
        if not user:
            user = user_service.create_user(f'{first_name} {last_name}', email,
                                            str(uuid.uuid4()))

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

    return flask.redirect('/')
 def create_user(self):
     self.user = user_service.create_user(self.name, self.email_address,
                                          self.password)
     if not self.user:
         self.error = "Error: New user rejected - invalid password or a user with that email already exists"