Пример #1
0
Файл: views.py Проект: WES6/boke
def edit_profile_admin(id):
    user = User.query.get_or_404(id)
    form = EditProfileAdminForm(user=user)
    if form.validate_on_submit():
        if user.email != form.email.data:  # 若邮箱更改,重新计算用户头像URL地址
            user.avatar_hash = hashlib.md5(
                form.email.data.encode('utf-8')).hexdigest()
        user.email = form.email.data
        # user.username = form.username.data
        # user.confirmed = form.confirmed.data
        user.role = Role.query.get(form.role.data)
        user.name = form.name.data
        user.location = form.location.data
        user.about_me = form.about_me.data
        db.session.add(user)
        db.session.commit()
        flash('The profile has been updated.')
        return redirect(url_for('.user', name=user.name))
    form.email.data = user.email
    # form.username.data = user.username
    # form.confirmed.data = user.confirmed
    form.role.data = user.role_id
    form.name.data = user.name
    form.location.data = user.location
    form.about_me.data = user.about_me
    return render_template('edit_profile.html', form=form, user=user)
Пример #2
0
def edit_profile_admin(username):
    if not current_user.is_admin:
        abort(403)
    user = User.query.filter_by(username=username).first()
    if not user:
        abort(404)
    form = EditProfileAdminForm(user=user)
    if form.validate_on_submit():
        try:
            user.email = form.email.data
            user.username = form.username.data
            user.name = form.name.data
            user.phonenumber = form.phonenumber.data if form.phonenumber.data else None
            user.phonenumber_locale = form.phonenumber_locale if form.phonenumber.data else None
            user.is_admin = form.is_admin.data
            user.is_maintenance = form.is_maintenance.data
            db.session.add(user)
            db.session.commit()
            flash("The profile has been updated.")
            return redirect(url_for('main.users_list'))
        except:
            db.session.rollback()
            flash("An error occurred while updating user information")
            return redirect(url_for('main.edit_profile_admin', username=user.username))
    form.email.data = user.email
    form.username.data = user.username
    form.name.data = user.name
    form.is_admin.data = user.is_admin
    form.is_maintenance.data = user.is_maintenance
    form.phonenumber.data = user.phonenumber

    return render_template('main/edit_profile.html', form=form, user=user)
Пример #3
0
def edit_profile_admin(id):
    """
    管理员修改个人信息
    :param id: 用户ID
    :return: html
    """
    data = {
        "title": "编辑个人信息",
        "h": "编辑个人信息",
    }
    user = User.query.get_or_404(id)
    form = EditProfileAdminForm(user=user)
    if form.validate_on_submit():
        user.email = form.email.data
        user.username = form.username.data
        user.confirmed = form.confirmed.data
        user.role = Role.query.get(form.role.data)
        user.name = form.name.data
        user.location = form.location.data
        user.about_me = form.about_me.data
        db.session.add(user)
        flash('个人信息已修改')
        return redirect(url_for('.user', username=user.username))
    form.email.data = user.email
    form.username.data = user.username
    form.confirmed.data = user.confirmed
    form.role.data = user.role
    form.name.data = user.name
    form.location.data = user.location
    form.about_me.data = user.about_me
    return render_template('auth/common.html', form=form, user=user, data=data)
def edit_profile_admin(id):
    user = User.query.get_or_404(id)
    form = EditProfileAdminForm(user=user)
    if form.validate_on_submit():
        user.username = form.username.data
        user.role = Role.query.get(form.role.data)
        user.name = form.name.data
        user.about_me = form.about_me.data
        user.email = form.email.data
        user.nascimento = form.nascimento.data
        user.cidade = form.cidade.data
        db.session.add(user)
        db.session.commit()
        flash('Usuário editado pelo administrador com sucesso!')
        return redirect(url_for('.user', username=user.username))
    form.username.data = user.username
    form.role.data = user.role_id
    form.name.data = user.name
    form.about_me.data = user.about_me
    form.email.data = user.email
    form.nascimento.data = user.nascimento
    form.cidade.data = user.cidade
    return render_template('edit-profile.html',
                           form=form,
                           username=user.username)
Пример #5
0
def edit_profile_admin(id):
    user = User.query.get_or_404(id)
    form = EditProfileAdminForm(user=user)

    if form.validate_on_submit():
        user.email = form.email.data
        user.username = form.username.data
        user.confirmed = form.confirmed.data
        user.role = form.role.data
        user.name = form.name.data
        user.location = form.location.data
        user.about_me = form.about_me.data

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

        flash('The profile has been updated.')
        return redirect(url_for('.user', username=user.username))

    form.email.data = user.email
    form.username.data = user.username
    form.confirmed.data = user.confirmed
    form.role.data = user.role
    form.name.data = user.name
    form.location.data = user.location
    form.about_me.data = user.about_me
    return render_template('edit_profile.html', form=form, user=user)
Пример #6
0
def edit_profile_admin(id):
    # 通过主键得到
    user = User.query.get_or_404(id)
    form = EditProfileAdminForm(user)

    if form.validate_on_submit():
        user.email = form.email.data
        user.username = form.username.data
        user.confirmed = form.confrimed.data
        if Role.query.filter_by(name=form.role.data).first:
            user.role = Role.query.filter_by(name=form.role.data).first()
        user.name = form.name.data
        user.about_me = form.about_me.data
        user.location = form.location.data
        db.session.add(user)
        flash("个人信息更新成功")
        return redirect(url_for(".user", username=user.username))
    form.email.data = user.email
    form.username.data = user.username
    form.name.data = user.name
    form.about_me.data = user.about_me
    form.location.data = user.location
    form.role.data = user.role
    form.confrimed.data = user.confirmed

    return render_template("edit_profile.html", form=form, user=user)
Пример #7
0
def edit_profile_admin(username):
    if not current_user.is_admin:
        abort(403)
    user = User.query.filter_by(username=username).first()
    if not user:
        abort(404)
    form = EditProfileAdminForm(user=user)
    if form.validate_on_submit():
        try:
            user.email = form.email.data
            user.username = form.username.data
            user.name = form.name.data
            user.phonenumber = form.phonenumber.data if form.phonenumber.data else None
            user.phonenumber_locale = form.phonenumber_locale if form.phonenumber.data else None
            user.is_admin = form.is_admin.data
            user.is_maintenance = form.is_maintenance.data
            db.session.add(user)
            db.session.commit()
            flash("The profile has been updated.")
            return redirect(url_for('main.users_list'))
        except:
            db.session.rollback()
            flash("An error occurred while updating user information")
            return redirect(
                url_for('main.edit_profile_admin', username=user.username))
    form.email.data = user.email
    form.username.data = user.username
    form.name.data = user.name
    form.is_admin.data = user.is_admin
    form.is_maintenance.data = user.is_maintenance
    form.phonenumber.data = user.phonenumber

    return render_template('main/edit_profile.html', form=form, user=user)
Пример #8
0
def edit_profile_admin():
    user = User.query.get_or_404(id)
    form = EditProfileAdminForm(user=user)
    if form.validate_on_submit():
        user.email = form.email.data
        user.username = form.username.data
        user.confirmed = form.confirmed.data
        user.role = Role.query.get(form.role.data)
        user.name = form.name.data
        user.location = form.location.data
        user.about_me = form.about_me.data
        try:
            db.session.add(user)
            db.session.commit()
        except Exception as e:
            current_app.logger.error(e)
            return jsonify(errno=RET.DBERR, errmsg='数据库错误')
        flash('资料更新完成')
        return redirect('.user', username=user.username)
    form.email.data = user.email
    form.username.data = user.username
    form.confirmed.data = user.confirmed
    form.role.data = user.role_id
    form.name.data = user.name
    form.location.data = user.location
    form.about_me.data = user.about_me
    return render_template('edit_profile.html', form=form, user=user)
Пример #9
0
def edit_profile_admin(id):
    user = User.query.get_or_404(id)
    form = EditProfileAdminForm(user=user)
    edit_success = False
    if form.validate_on_submit():
        user.confirmed = form.confirmed.data
        user.email = form.email.data
        user.role = Role.query.get(form.role.data)
        user.username = form.username.data
        user.location = form.location.data
        user.about_me = form.about_me.data
        db.session.add(user)
        db.session.commit()
        flash("User's profile has benn updated.", "success")
        edit_success = True
    form.username.data = user.username
    form.location.data = user.location
    form.about_me.data = user.about_me
    form.role.data = user.role_id
    form.email.data = user.email
    form.confirmed.data = user.confirmed
    return render_template('user/edit_profile.html',
                           form=form,
                           edit_success=edit_success,
                           user=user)
Пример #10
0
def edit_profile_admin(id):
    user = User.query.get_or_404(id)
    form = EditProfileAdminForm(user=user)
    if form.validate_on_submit():
        user.username = form.username.data
        user.confirmed = form.confirmed.data
        user.role = Role.query.get(form.role.data)
        user.about_me = form.about_me.data
        flash('修改成功')
        return redirect(url_for('.user', username=user.username))
    form.username.data = user.username
    form.confirmed.data = user.confirmed
    form.role.data = user.role
    form.about_me.data = user.about_me
    return render_template('edit_profile.html', form=form, user=user)
Пример #11
0
def edit_profile_admin(id):
    user = User.query.get_or_404(id)
    form = EditProfileAdminForm(user=user)
    if form.validate_on_submit():
        user.username = form.username.data
        user.role = Role.query.get(form.role.data)
        user.name = form.name.data
        user.about_me = form.about_me.data
        db.session.add(user)
        db.session.commit()
        flash('Usuário editado com sucesso!')
        return redirect(url_for('.edit_voluntarios_admin'))
    form.username.data = user.username
    form.role.data = user.role_id
    form.name.data = user.name
    form.about_me.data = user.about_me
    return render_template(
        'edit_profile.html', form=form, username=user.username
    )
Пример #12
0
def edit_profile_admin(identity):
    user = User.query.get_or_404(identity)
    form = EditProfileAdminForm(user)
    if form.validate_on_submit():
        user.email = form.email.data
        user.username = form.username.data
        user.confirmed = form.confirmed.data
        user.role = Role.query.get(form.role.data)
        user.location = form.location.data
        user.about_me = form.about_me.data
        db.session.add(user)
        flash('The profile has been updated.')
        return redirect(url_for('.profile', username=user.username))
    form.email.data = user.email
    form.username.data = user.username
    form.confirmed.data = user.confirmed
    form.role.data = user.role_id
    form.location.data = user.location
    form.about_me.data = user.about_me
    return render_template('edit_profile.html', form=form, user=user)
Пример #13
0
def edit_profile_admin(id):
    user = User.query.get_or_404(id)
    form = EditProfileAdminForm(user=user)
    if form.validate_on_submit():
        user.email = form.email.data
        user.username = form.username.data
        user.confirmed = form.confirmed.data
        user.role = Role.query.get(form.role.data)
        user.name = form.name.data
        user.class_info = form.class_info.data
        user.about_me = form.about_me.data
        db.session.add(user)
        flash('你的信息已经更新')
        return redirect(url_for('.user', username=user.username))
    form.email.data = user.email
    form.username.data = user.username
    form.confirmed.data = user.confirmed
    form.role.data = user.role_id
    form.name.data = user.name
    form.class_info.data = user.class_info
    form.about_me.data = user.about_me
    return render_template('edit_profile.html', form=form, user=user)
Пример #14
0
def edit_profile_admin(id):
    user = User.query.get_or_404(id)
    form = EditProfileAdminForm(user=user)
    if form.validate_on_submit():
        user.email = form.username.data
        user.username = form.username.data
        user.first_name = form.first_name.data
        user.role.data = Role.query.get(form.role.data)
        user.last_name = form.last_name.data
        user.confirmed = form.confirmed.data
        db.session.add(user)
        db.session.commit()
        flash('The profile has been edited.')
        return redirect(url_for('main.users'))
    form.username.data = user.username
    form.email.data = user.email
    form.first_name.data = user.first_name
    form.last_name.data = user.last_name
    form.confirmed.data = user.confirmed
    return render_template('main/edit_profile_admin.html',
                           user=user,
                           form=form)
Пример #15
0
def edit_profile_admin(id):
    user = User.query.get_or_404(id)
    form = EditProfileAdminForm(user=user,
                                original_username=user.username,
                                original_email=user.email)
    if form.validate_on_submit():
        user.username = form.username.data
        user.email = form.email.data
        user.about_me = form.about_me.data
        user.role = form.role.data
        db.session.add(user)
        db.session.commit()
        flash('Your changes have been saved.', 'success')
        return redirect(url_for('main.user', username=user.username))
    elif request.method == 'GET':
        form.username.data = user.username
        form.email.data = user.email
        form.about_me.data = user.about_me
        form.role.data = Role.query.get(user.role_id)
    return render_template('users/edit_profile.html',
                           title='Edit Profile',
                           form=form,
                           user=user)
Пример #16
0
from flask import render_template, abort, flash, redirect, url_for, request, current_app