Exemple #1
0
def new_profile():
    """Create a new user profile"""
    if (not (session or request.method == 'POST') or 'user_id' in session
            or not ('email' in session or 'email' in request.form)):
        return redirect(url_for('status.index'))

    data = MultiDict()
    try:
        data['email'] = session['email']
        session.pop('email')
    except KeyError:
        pass

    if request.method == 'POST':
        data = request.form

    form = ProfileForm(data)

    if request.method == 'POST' and form.validate():
        db = get_session(current_app)
        u = User(name=data['name'], email=data['email'],
                 username=data['username'], slug=data['username'],
                 github_handle=data['github_handle'])
        db.add(u)
        db.commit()

        session['email'] = u.email
        session['user_id'] = u.id

        flash('Your profile was created.', 'success')

        return redirect(url_for('status.index'))

    return render_template('users/new_profile.html', form=form)
Exemple #2
0
def profile():
    """Shows the user's profile page."""
    db = get_session(current_app)

    user_id = session.get('user_id')
    if not user_id:
        return forbidden('You must be logged in to see a profile!')

    user = db.query(User).get(user_id)

    if request.method == 'POST':
        data = request.form
    else:
        data = MultiDict(user.dictify())

    form = ProfileForm(data)

    if request.method == 'POST' and form.validate():
        user.name = data['name']
        user.username = data['username']
        user.slug = data['username']
        user.github_handle = data['github_handle']
        db.add(user)
        db.commit()
        flash('Your profile was updated.', 'success')

    return render_template('users/profile.html', form=form)
Exemple #3
0
def profile():
    """Shows the user's profile page."""
    db = get_session(current_app)

    user_id = session.get('user_id')
    if not user_id:
        return forbidden('You must be logged in to see a profile!')

    user = db.query(User).get(user_id)

    if request.method == 'POST':
        data = request.form
    else:
        data = MultiDict(user.dictify())

    form = ProfileForm(data)

    if request.method == 'POST' and form.validate():
        user.name = data['name']
        user.username = data['username']
        user.slug = data['username']
        user.github_handle = data['github_handle']
        db.add(user)
        db.commit()
        flash('Your profile was updated.', 'success')

    return render_template('users/profile.html', form=form)
Exemple #4
0
def new_profile():
    """Create a new user profile"""
    if (not (session or request.method == 'POST') or 'user_id' in session
            or not ('email' in session or 'email' in request.form)):
        return redirect(url_for('status.index'))

    data = MultiDict()
    try:
        data['email'] = session['email']
        session.pop('email')
    except KeyError:
        pass

    if request.method == 'POST':
        data = request.form

    form = ProfileForm(data)

    if request.method == 'POST' and form.validate():
        db = get_session(current_app)
        u = User(name=data['name'],
                 email=data['email'],
                 username=data['username'],
                 slug=data['username'],
                 github_handle=data['github_handle'])
        db.add(u)
        db.commit()

        session['email'] = u.email
        session['user_id'] = u.id

        flash('Your profile was created.', 'success')

        return redirect(url_for('status.index'))

    return render_template('users/new_profile.html', form=form)