Beispiel #1
0
    def run(self):
        deployments = Deployment.objects
        option = prompt_choices('Deployment', [
            (str(i), v) for i, v in enumerate(deployments, 1)])
        deployment = deployments[int(option) - 1]
        email = prompt('Email')
        password = prompt_pass('Password')
        password_confirm = prompt_pass('Confirm Password')

        can_create, form_errors = can_create_user(email, password,
                                                  password_confirm, deployment)

        if can_create:
            try:
                user = register_user(email=email, password=password)
            except socket.error as e:
                # if there's an error sending the notification email,
                # recover
                print 'Error sending confirmation email: {}'.format(e)
                user = users.get(email=email, deployment=None)
            user.update(set__deployment=deployment)
            print '\nUser created successfully'
            print 'User(id=%s email=%s)' % (user.id, user.email)
            return
        print '\nError creating user:'******'\n'.join(errors)
Beispiel #2
0
def persona_login():
    if 'assertion' not in request.form:
        abort(400)

    url = urlparse(request.url)
    try:
        hostname = url.hostname if get_deployment(url.hostname) else \
            Deployment.objects().first().hostnames[0]
    except:
        hostname = "localhost"

    if url.port:
        port = url.port
    else:
        port = 443 if url.scheme == "https" else 80

    data = {'assertion': request.form['assertion'],
            'audience': '{scheme}://{hostname}:{port}'.format(
                scheme=url.scheme, hostname=hostname, port=port)}
    resp = requests.post('https://verifier.login.persona.org/verify',
                         data=data, verify=True)

    if resp.ok:
        verification_data = resp.json()
        if verification_data['status'] == 'okay':
            # log the user in
            user = users.get(email=verification_data['email'])
            if user:
                login_user(user)
                return redirect(url_for('dashboard.index'))

    return current_app.login_manager.unauthorized()
Beispiel #3
0
def persona_login():
    if 'assertion' not in request.form:
        abort(400)

    url = urlparse(request.url)
    try:
        hostname = url.hostname if get_deployment(url.hostname) else \
            Deployment.objects().first().hostnames[0]
    except:
        hostname = "localhost"

    if url.port:
        port = url.port
    else:
        port = 443 if url.scheme == "https" else 80

    data = {
        'assertion':
        request.form['assertion'],
        'audience':
        '{scheme}://{hostname}:{port}'.format(scheme=url.scheme,
                                              hostname=hostname,
                                              port=port)
    }
    resp = requests.post('https://verifier.login.persona.org/verify',
                         data=data,
                         verify=True)

    if resp.ok:
        verification_data = resp.json()
        if verification_data['status'] == 'okay':
            # log the user in
            user = users.get(email=verification_data['email'])
            if user:
                login_user(user)
                return redirect(url_for('dashboard.index'))

    return current_app.login_manager.unauthorized()