示例#1
0
文件: routes.py 项目: fdnflm/Blog
def profile():
    edit_form = EditProfile(current_user.name)
    password_form = EditPassword()
    uplaod_photo = UploadPhoto()

    if uplaod_photo.validate_on_submit():
        avatar = uplaod_photo.photo.data
        filename = secure_filename(generate_id(6) + ".jpg")
        avatar.save(os.path.join(app.config["UPLOAD_FOLDER"], filename))
        current_user.avatar_id = filename
        db.session.commit()
        return redirect("/profile")

    if edit_form.validate_on_submit():
        current_user.name = edit_form.username.data
        current_user.bio = edit_form.bio.data
        db.session.commit()
        return redirect("/profile")
    elif request.method == 'GET':
        edit_form.username.data = current_user.name
        edit_form.bio.data = current_user.bio

    if password_form.validate_on_submit():
        if check_password_hash(current_user.password,
                               password_form.password_old.data):
            current_user.password = generate_password_hash(
                password_form.password.data)
            db.session.commit()
            return redirect("/profile")

    return render_template("profile.html",
                           form=edit_form,
                           upload_ph=uplaod_photo,
                           password_form=password_form,
                           title="Profile")
示例#2
0
def update_profile():
    """Update profile for current user."""
    if not g.user:
        flash("Access unauthorized.", "danger")
        return redirect("/")

    form = EditProfile(obj=g.user)

    if form.validate_on_submit():

        g.user.location = form.location.data or None
        g.user.bio = form.bio.data or None
        g.user.header_image_url = form.header_image_url.data or None
        g.user.image_url = form.image_url.data or g.user.image_url
        g.user.username = form.username.data
        g.user.email = form.email.data
        password = form.password.data

        user = User.authenticate(g.user.username, password)
        if user:

            db.session.add(g.user)
            db.session.commit()

            return redirect(f"/users/{g.user.id}")

        else:
            flash("Password Incorrect")

    return render_template("users/edit.html", form=form, user_id=g.user.id)
示例#3
0
def edit_user(user_id):
    user = User.query.filter_by(user_id=user_id).first()
    form = EditProfile(obj=user)
    if form.validate_on_submit():
        form.populate_obj(user)
        db.session.commit()

        return redirect(url_for('user', user_id=user_id))

    return render_template('edit_user.html', user=user, form=form)
示例#4
0
def editprofile(id):
	user= User.query.filter_by(id=id).one()
	form = EditProfile()
	if form.validate_on_submit():
		user.name= form.name.data
		user.email = form.email.data
		db.session.add(user)
		db.session.commit()
		flash('Profile Successfully edited.')
		return redirect(url_for('myprofile',id=id))
	return render_template('editprofile.html',user=user, form=form)
示例#5
0
def edit_profile():
	newform=EditProfile()
	if newform.validate_on_submit():
		current_user.name=newform.name.data
		current_user.location=newform.location.data	
		current_user.about_me=newform.about_me.data
		db.session.add(current_user)
		flash('Profile Updated')
		return redirect(url_for('user',username=current_user.username))
	newform.name.data=current_user.name
	newform.location.data=current_user.location
	newform.about_me.data=current_user.about_me
	return render_template('edit_profile.html',form=newform)
示例#6
0
文件: views.py 项目: extant1/ships
def edit_profile():
    form = EditProfile()
    user = User.query.filter_by(email=current_user.email).first()
    if form.validate_on_submit():
        current_user.handle = form.handle.data
        current_user.rsi_profile = form.rsi_profile.data
        current_user.tas_profile = form.tas_profile.data
        current_user.hide_email = form.hide_email.data
        db.session.add(user)
        flash('Your profile has been updated.', 'info')
        return redirect(url_for('user.profile', handle=current_user.handle))
    form.handle.data = current_user.handle
    form.rsi_profile.data = current_user.rsi_profile
    form.tas_profile.data = current_user.tas_profile
    form.hide_email.data = current_user.hide_email
    return render_template('user/edit_profile.html', form=form)
示例#7
0
文件: views.py 项目: P1sar/QuAsker
def edit():

    edit_form = EditProfile()
    edit_avatar = EditAvatar()

    if edit_avatar.avatar.data:
        file_path = os.path.join(app.config['UPLOAD_FOLDER'], 
                                current_user.nickname + ".png")
        edit_avatar.avatar.data.save(file_path)

    if edit_form.validate_on_submit():
        about_me = edit_form.about_me.data
        current_user.about_me = about_me
        db.session.add(current_user)
        db.session.commit()
        return redirect(url_for('edit'))


    return render_template('edit_profile.html', edit_form = edit_form, 
                            edit_avatar = edit_avatar)