def seed_user(email, role):
    '''
    Creates a new user in the database.
    '''
    from feedback.user.models import User
    seed_email = email if email else app.config.get('SEED_EMAIL')
    user_exists = User.query.filter(User.email == seed_email).first()
    if user_exists:
        current_app.logger.info(
            'User {email} already exists'.format(email=seed_email))
    else:
        try:
            new_user = User.create(
                email=seed_email,
                created_at=datetime.datetime.utcnow(),
                role_id=int(role)
            )
            db.session.add(new_user)
            db.session.commit()
            current_app.logger.info(
                'User {email} successfully created!'.format(
                    email=seed_email))
        except Exception, e:
            current_app.logger.error(
                'Something went wrong: {exception}'.format(exception=e.message))
Exemplo n.º 2
0
def seed_user(email, role):
    '''
    Creates a new user in the database.
    '''
    from feedback.user.models import User
    seed_email = email if email else app.config.get('SEED_EMAIL')
    user_exists = User.query.filter(User.email == seed_email).first()
    if user_exists:
        current_app.logger.info(
            'User {email} already exists'.format(email=seed_email))
    else:
        try:
            new_user = User.create(
                email=seed_email,
                created_at=datetime.datetime.utcnow(),
                role_id=int(role)
            )
            db.session.add(new_user)
            db.session.commit()
            current_app.logger.info(
                'User {email} successfully created!'.format(
                    email=seed_email))
        except Exception, e:
            current_app.logger.error(
                'Something went wrong: {exception}'.format(exception=e.message))
def user_create():
    form = UserForm()
    if form.validate_on_submit():
        current_app.logger.info("USER CREATED with email {}".format(form.email.data))
        User.create(email=form.email.data, full_name=form.full_name.data, role_id=form.role_id.data)

        flash("Created a new profile.", "alert-success")
        return redirect(url_for("user.user_manage"))
    else:
        return render_template(
            "user/add-edit.html",
            form=form,
            date=today.strftime("%B %d, %Y"),
            form_action=url_for("user.user_create"),
            title="Add User",
            action="Add User",
        )
Exemplo n.º 4
0
def user_create():
    form = UserForm()
    if form.validate_on_submit():
        current_app.logger.info('USER CREATED with email {}'.format(
            form.email.data))
        User.create(email=form.email.data,
                    full_name=form.full_name.data,
                    role_id=form.role_id.data)

        flash('Created a new profile.', 'alert-success')
        return redirect(url_for('user.user_manage'))
    else:
        return render_template('user/add-edit.html',
                               form=form,
                               date=today.strftime('%B %d, %Y'),
                               form_action=url_for('user.user_create'),
                               title='Add User',
                               action='Add User')
Exemplo n.º 5
0
def user_create():
    form = UserForm()
    if form.validate_on_submit():
        current_app.logger.info(
            'USER CREATED with email {}'.format(form.email.data)
        )
        User.create(
            email=form.email.data,
            full_name=form.full_name.data,
            role_id=form.role_id.data)

        flash('Created a new profile.', 'alert-success')
        return redirect(url_for('user.user_manage'))
    else:
        return render_template(
            'user/add-edit.html',
            form=form,
            date=today.strftime('%B %d, %Y'),
            form_action=url_for('user.user_create'),
            title='Add User',
            action='Add User')
Exemplo n.º 6
0
def auth():
    '''
    Endpoint from AJAX request for authentication from persona
    '''

    data = urllib.urlencode({
        'assertion': request.form.get('assertion'),
        'audience': current_app.config.get('BROWSERID_URL')
    })
    req = urllib2.Request('https://verifier.login.persona.org/verify', data)

    response = json.loads(urllib2.urlopen(req).read())
    current_app.logger.debug(
        'LOGIN: status from persona: {}'.format(response))
    if response.get('status') != 'okay':
        current_app.logger.debug(
            'REJECTEDUSER: User login rejected from persona. Messages: {}'.format(response))
        abort(403)

    next_url = request.args.get('next', None)
    email = response.get('email')
    user = User.query.filter(User.email == email).first()

    domain = email.split('@')[1] if len(email.split('@')) > 1 else None

    if user:
        login_user(user)
        flash('Logged in successfully!', 'alert-success')

        current_app.logger.debug(
            'LOGIN: User {} logged in successfully'.format(user.email))
        return next_url if next_url else '/'

    elif domain in current_app.config.get('CITY_DOMAINS'):
        user = User.create(email=email)
        login_user(user)

        current_app.logger.debug(
            'NEWUSER: New User {} successfully created'.format(user.email))
        return '/'

    else:
        current_app.logger.debug(
            'NOTINDB: User {} not in DB -- aborting!'.format(email))
        abort(403)
def auth():
    '''
    Endpoint from AJAX request for authentication from persona
    '''

    data = urllib.urlencode({
        'assertion': request.form.get('assertion'),
        'audience': current_app.config.get('BROWSERID_URL')
    })
    req = urllib2.Request('https://verifier.login.persona.org/verify', data)

    response = json.loads(urllib2.urlopen(req).read())
    current_app.logger.debug('LOGIN: status from persona: {}'.format(response))
    if response.get('status') != 'okay':
        current_app.logger.debug(
            'REJECTEDUSER: User login rejected from persona. Messages: {}'.
            format(response))
        abort(403)

    next_url = request.args.get('next', None)
    email = response.get('email')
    user = User.query.filter(User.email == email).first()

    domain = email.split('@')[1] if len(email.split('@')) > 1 else None

    if user:
        login_user(user)
        flash('Logged in successfully!', 'alert-success')

        current_app.logger.debug(
            'LOGIN: User {} logged in successfully'.format(user.email))
        return next_url if next_url else '/'

    elif domain in current_app.config.get('CITY_DOMAINS'):
        user = User.create(email=email)
        login_user(user)

        current_app.logger.debug(
            'NEWUSER: New User {} successfully created'.format(user.email))
        return '/'

    else:
        current_app.logger.debug(
            'NOTINDB: User {} not in DB -- aborting!'.format(email))
        abort(403)
Exemplo n.º 8
0
def create_a_user(email='*****@*****.**'):
    return User(email=email, first_name='foo', last_name='foo')