Ejemplo n.º 1
0
def update(username):
    editor = current_user
    user = User.query.filter_by(username=username).first_or_404()
    if editor.is_teacher() or user == editor:
        form = EditProfileForm()
        if form.validate_on_submit():
            if form.username.data:
                user.username = form.username.data
            if form.fullname.data:
                user.fullname = form.fullname.data
            if form.email.data:
                user.email = form.email.data
            if form.password.data:
                user.password = form.password.data
            if form.phone.data:
                user.phone_number = form.phone.data
            db.session.commit()
            flash("Congratulations, profile is up to date!")
            return redirect(url_for("index"))
        return render_template("edit_profile.html",
                               title="Edit profile",
                               editor=editor,
                               form=form)
    else:
        flash("You don't have permission!")
        return redirect(url_for("index"))
Ejemplo n.º 2
0
def edit_profile():
    form = EditProfileForm(formdata=request.form, obj=current_user)
    if form.validate_on_submit():
        form.populate_obj(current_user)
        db.session.commit()
        flash('Profile successfully updated', 'success')
        return redirect(url_for('user', username=current_user.username))
    return render_template('edit_profile.html',
                           title='Edit Profile',
                           form=form)
Ejemplo n.º 3
0
def edit_profile(request):  
    if request.method == 'POST':
        form = EditProfileForm(request.POST, instance=request.user)
        
        if form.is_valid():
            form.save()
            return redirect('/blog/profile')
    else:
        form = EditProfileForm(instance=request.user)
        args = {'form': form}
        return render(request, 'blog/edit_profile.html', args)
Ejemplo n.º 4
0
def edit_profile():
  form = EditProfileForm(username=current_user.username,\
                         email=current_user.email,\
                         api_key=current_user.api_key)
  if form.validate_on_submit():
    current_user.email = form.email.data
    if len(form.password.data)>5 and form.password.data == form.password2.data:
      current_user.set_password(form.password.data)

    db.session.commit()
    flash('Your profile has been updated.')
    return redirect(url_for('main.index'))
  return render_template('user/edit_profile.html', form=form)
Ejemplo n.º 5
0
def edit_profile():
    form = EditProfileForm(username=current_user.username,\
                           email=current_user.email,\
                           api_key=current_user.api_key)
    if form.validate_on_submit():
        current_user.email = form.email.data
        if len(form.password.data
               ) > 5 and form.password.data == form.password2.data:
            current_user.set_password(form.password.data)

        db.session.commit()
        flash('Your profile has been updated.')
        return redirect(url_for('main.index'))
    return render_template('user/edit_profile.html', form=form)
Ejemplo n.º 6
0
def edit_profile(request):
    if request.method == 'POST':
        form = EditProfileForm(request.POST, instance=request.user)

        if form.is_valid():
            form.save()
            return redirect('/blog/profile')
    else:
        form = EditProfileForm(instance=request.user)
        args = {'form': form}
        return render(request, 'blog/edit_profile.html', args)