Exemple #1
0
def edit_profile():
    form = ProfileForm()
    journeys = eval(current_user.journeys)
    if form.validate_on_submit():
        i = 0
        for form_field in form:
            if form_field.name == "submit" or form_field.name == "csrf_token":
                continue
            else:
                journey = {
                    'label': form_field.babel.data,
                    'direction': "to",
                    'travel_address': form_field.travel_address.data,
                    'travel_modes': form_field.travel_modes.data
                }
                journeys[i] = journey
                i += 1

            current_user.journeys = str(journeys)
        db.session.commit()
        flash('Settings Changed!')

        return redirect(url_for('main.edit_profile'))
    elif request.method == 'GET':
        try:
            journeys = eval(current_user.journeys)

        except:
            current_app.logger.info(f"Failed to evaluate {journeys}.")
            journeys = [{
                'label': 'Work',
                'direction': 'to',
                'travel_address': '',
                'travel_modes': []
            }, {
                'label': 'Gym',
                'direction': 'to',
                'travel_address': '',
                'travel_modes': []
            }, {
                'label': 'Pub',
                'direction': 'to',
                'travel_address': '',
                'travel_modes': []
            }]

        for journey, form_field in zip(journeys, form):
            if form_field.name == "submit" or form_field.name == "csrf_token":
                continue

            form_field.babel.data = journey['label']
            form_field.travel_address.data = journey['travel_address']
            form_field.travel_modes.data = journey['travel_modes']

    return render_template('edit_profile.html',
                           title='Edit Profile',
                           form=form)
Exemple #2
0
def profile():
    form = ProfileForm(current_user.username)
    if form.validate_on_submit():
        current_user.username = form.username.data
        current_user.about_me = form.about_me.data
        db.session.commit()
        flash(_('Your changes have been saved.'))
        return redirect(url_for('main.profile'))
    elif request.method == 'GET':
        form.username.data = current_user.username
        form.about_me.data = current_user.about_me
    return render_template(
        'main/profile.html', title=_('Edit Profile'), form=form)
Exemple #3
0
def profile():
    if request.method == 'GET':
        manage_prev_page()
    form = ProfileForm()
    if request.method == 'POST':
        if form.validate_on_submit():
            current_user.username = form.username.data
            current_user.email = form.email.data
            db.session.commit()
            flash('Your account has been changed!')
            return redirect(session['prev_page'])
        else:
            flash('Please check your data!')
    return render_template('main/profile.html', form=form)
Exemple #4
0
def profile(username, tab):

    form = ProfileForm()
    securityform = PasswordChangeForm(prefix='a')
    deleteform = DeleteAccountForm(prefix='b')
    user = db.session.query(User).filter(User.username == username).first()

    if user is None:
        return redirect(url_for('main.home'))

    if securityform.validate_on_submit():

        user.set_password(securityform.password.data)
        db.session.commit()

        flash('Password updated successfully', 'danger')
        return redirect(
            url_for('main.profile', username=user.username, tab=tab))

    if form.validate_on_submit():
        user.email = form.email.data
        user.userdetails.full_name = bleach.clean(form.full_name.data)
        user.username = form.username.data
        user.userdetails.receive_email = form.receive_email.data

        db.session.commit()
        flash('Profile updated successfully.', 'info')
        return redirect(
            url_for('main.profile', username=user.username, tab=tab))

    if deleteform.validate_on_submit():
        db.session.delete(user)
        db.session.commit()

        return redirect(url_for('auth.logout'))

    if user:
        form.email.data = user.email
        form.full_name.data = user.userdetails.full_name
        form.username.data = user.username
        form.receive_email.data = user.userdetails.receive_email

    return render_template('profile.html',
                           form=form,
                           user=user,
                           securityform=securityform,
                           deleteform=deleteform,
                           active_page=tab)
Exemple #5
0
def profile(token):
    user = User.query.filter_by(secure_token=token).first()
    if user is None: abort(404)

    form = ProfileForm()
    if form.validate_on_submit():
        user.first_name = form.first_name.data
        user.gender = form.gender.data
        user.age = form.date_of_birth.data
        db.session.commit()
        flash('Profile has been updated! ')
        return redirect(url_for('main.index'))

    form.first_name.data = user.first_name
    form.gender.data = user.gender
    form.date_of_birth.data = user.age
    return render_template('main/complete_profile.html', form=form, title=_('Complete Profile'))
def index():
    form = ProfileForm()
    if request.method == 'POST':
        if form.validate_on_submit():
            filename = images.save(request.files['img'])
            url = images.url(filename)
            from app.models import Profile
            new_profile = Profile(name=form.name.data,
                                  image_filename=filename,
                                  image_url=url)
            db.session.add(new_profile)
            db.session.commit()
            flash('New profile, {}, added!'.format(new_profile.name),
                  'success')
            return redirect(url_for('main.display_profile'))
        else:
            flash_errors(form)
            flash('ERROR! Profile was not added.', 'error')
    return render_template('add_profile.html', form=form)
Exemple #7
0
def profile_edit():
    form = ProfileForm(current_user.username, current_user.email)

    if form.validate_on_submit():
        current_user.username = form.username.data
        current_user.email = form.email.data

        if form.password.data:
            current_user.set_password(form.password.data)

        db.session.commit()

        flash('Updated your info. All set you bet.')

        return redirect(url_for('main.profile'))
    elif request.method == 'GET':
        form.username.data = current_user.username
        form.email.data = current_user.email

    return render_template('auth/profile_edit.html',
                           title='Edit profile',
                           form=form)
Exemple #8
0
def profile(username):
    if not current_user.get_admin():
        return redirect(url_for('index'))
    form = ProfileForm()
    users = mongo.db.users
    user = users.find_one({'name': username})
    if 'pass' not in user.keys():
        user['passed'] = False
        mongo.db.users.save(user)
    post = user['pass']
    if not user or user['post_num'] < 1:
        abort(404)
    return render_template('Profile.html',
                           forms=user['posts'],
                           form=form,
                           post=post,
                           username=username,
                           admin=False)
Exemple #9
0
def edit_profile():
    user = current_user
    profile_form = ProfileForm()
    if request.method == "POST":
        name = request.form.get('name')
        password = request.form.get('password')
        password2 = request.form.get('password2')
        gender = request.form.get('gender')
        age = request.form.get('age')
        school = request.form.get('school')
        selfinfo = request.form.get('selfinfo')
        # print(name, password, gender, age, school, selfinfo)

        if password != password2:
            flash('两次输入密码不一致')
        else:
            test_user_name = User.query.filter_by(username=name).first()
            if test_user_name:
                flash('用户名已被使用')
            else:
                if name:
                    user.username = name
                if password:
                    user.password = password
                if gender:
                    user.gender = gender
                if age:
                    user.age = age
                if school:
                    user.school = school
                if selfinfo:
                    user.selfinfo = selfinfo
                try:
                    db.session.commit()
                    # flash("修改成功")
                    return redirect(url_for('main.index'))
                except Exception as e:
                    print(e)
                    flash("发布失败")
                    db.session.rollback()
    return render_template('user/edit_profile.html', form=profile_form)