Example #1
0
def user(username):
    user = User.query.filter_by(username=username).first_or_404()

    form = EditProfileForm(current_user.username)
    if form.validate_on_submit():
        current_user.username = form.username.data
        current_user.first_name = form.first_name.data
        current_user.last_name = form.last_name.data
        current_user.email = form.email.data
        db.session.commit()
        flash('Your changes have been saved.')
        return redirect(url_for('auth.user', username=current_user.username))
    elif request.method == 'GET':
        form.username.data = current_user.username
        form.first_name.data = current_user.first_name
        form.last_name.data = current_user.last_name
        form.email.data = current_user.email
        print(user.projects.all())

    return render_template('auth/user.html',
                            title='User preferences',
                            user=user,
                            form=form,
                            projects=user.projects.all(),
                            pform=UpdatePasswordForm())
Example #2
0
    def test_post_with_invalid_email(app_and_db, client,
                                     test_with_authenticated_user):
        new_email = "*****@*****.**"

        db = app_and_db[1]
        db.session.add(
            User(username="******", email=new_email, password="******"))
        db.session.commit()

        form = EditProfileForm(
            original_username=current_user.username,
            original_email=current_user.email,
            username="******",
            email=new_email,
        )
        client.post(url_for("auth.edit_profile"),
                    data=form.data,
                    follow_redirects=True)

        user = User.query.filter_by(username="******").first()
        token = get_confirmation_token(id=user.id, email=form.email.data)
        response = client.post(url_for("auth.activate_email", token=token),
                               follow_redirects=True)
        assert response.status_code == 200
        user = User.query.get(user.id)
        assert user.email != new_email
        assert b"You can not set this email address." in response.data
Example #3
0
def edit_profile():
    form = EditProfileForm(current_user.mob, current_user.nickname)
    if form.validate_on_submit():
        current_user.nickname = form.nickname.data
        current_user.mob = form.mob.data
        db.session.commit()
        flash('Your changes have been saved.')
        return redirect(url_for('main.edit_profile'))
    elif request.method == 'GET':
        form.nickname.data = current_user.nickname
        form.mob.data = current_user.mob
    return render_template('auth/editprofile.html', form=form)
Example #4
0
def edit_profile():
    form = EditProfileForm(current_user.username)
    if form.validate_on_submit():
        current_user.username = form.username.data
        db.session.commit()
        flash('Your changes have been saved.')
        return redirect(url_for('auth.edit_profile'))
    elif request.method == 'GET':
        form.username.data = current_user.username
        form.first_name.data = current_user.first_name
        form.last_name.data = current_user.last_name
    return render_template('edit_profile.html', title='Edit Profile', form=form)
Example #5
0
def edit_profile():
    token = current_user.get_reset_password_token()
    user = User.verify_reset_password_token(token)
    form = EditProfileForm(current_user.username)
    if form.validate_on_submit():
        current_user.username = form.username.data
        user.set_password(form.password.data)
        db.session.commit()
        flash('Your changes have been saved.')
        return redirect(url_for('auth.edit_profile'))
    elif request.method == 'GET':
        form.username.data = current_user.username
    return render_template('auth/edit_profile.html', title='Edit profile',
                           form=form)
Example #6
0
def edit_profile():
    form = EditProfileForm()
    if form.validate_on_submit():
        current_user.name = form.name.data
        current_user.location = form.location.data
        current_user.about_me = form.about_me.data
        db.session.add(current_user._get_current_object())
        db.session.commit()
        flash('Your profile has been updated.')
        return redirect(url_for('.user', username=current_user.username))
    form.name.data = current_user.name
    form.location.data = current_user.location
    form.about_me.data = current_user.about_me
    return render_template('edit_profile.html', form=form)
Example #7
0
def edit_profile():
    user = current_user

    form = EditProfileForm(current_user.username)
    if form.validate_on_submit():
        user.username = form.username.data
        user.about_me = form.about_me.data
        db.session.commit()
        return redirect(url_for("main.user", username=user.username))
    elif request.method == 'GET':
        form.username.data = user.username
        form.about_me.data = user.about_me

    return render_template("edit_profile.html", form=form)
Example #8
0
def profile(username):
    user = User.query.filter_by(username=username).first_or_404()
    form = EditProfileForm()
    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('auth.profile', username=current_user.username))
    elif request.method == 'GET':
        form.username.data = current_user.username
        form.about_me.data = current_user.about_me
    return render_template('auth/profile.html', user=user, title='Edit Profile',
                           form=form)
Example #9
0
def edit_user_profile():

    form = EditProfileForm()
    title = 'Edit profile'
    if form.validate_on_submit():
        if form.email_validate() or form.username_validate(
        ) or form.old_password_validate() != True:
            pass
        else:
            current_user.set_password(form.new_password.data)
            current_user.username = form.username.data
            current_user.email = form.email.data
            db.session.commit()
            flash('Данные успешно сохранены!')
            return redirect(url_for('auth.edit_user_profile'))
    return render_template('user_profile.html', form=form, title=title)
Example #10
0
def edit_profile():
    form = EditProfileForm(current_user.username, current_user.email)

    if form.validate_on_submit():
        current_user.username = form.username.data
        current_user.email = form.email.data
        db.session.commit()
        flash("Your profile information has been updated.")
        return redirect(url_for("main.user", username=current_user.username))

    elif request.method == "GET":
        form.username.data = current_user.username
        form.email.data = current_user.email

    return render_template("auth/edit_profile.html",
                           title="Edit Profile",
                           form=form)
Example #11
0
def edit_profile(username):
    user=User.query.filter_by(username=username).first_or_404()
    if username != current_user.username:
        return redirect(url_for('homepage'))
    form = EditProfileForm(prefer_language=('py' if current_user.prefer_language == 'py' else 'cpp'))
    if form.validate_on_submit():
        current_user.username = form.username.data
        current_user.email = form.email.data
        current_user.prefer_language = form.prefer_language.data
        db.session.commit()
        flash('Your change has been saved')
        return redirect(url_for('homepage'))
    elif request.method == 'GET':
        form.username.data = current_user.username
        form.email.data = current_user.email
    return render_template('auth/edit_profile.html', user=user, title='Edit Profile',
                           form=form)
Example #12
0
def edit_profile() -> str:
    form = EditProfileForm(
        original_username=current_user.username, original_email=current_user.email
    )
    if form.validate_on_submit():
        user = User.query.filter_by(username=current_user.username).first()
        if user:
            user.username = form.username.data
            if form.email.data != current_user.email:
                email.send_change_email_confirmation(form.email.data, user)
                flash("Check your email to confirm the email address change.")
            db.session.commit()
            flash("You change your profile data.")
            return redirect(url_for("main.user", username=current_user.username))
    elif request.method == "GET":
        form.username.data = current_user.username
        form.email.data = current_user.email
    return render_template("auth/form.html", title="Edit Profile", form=form)
Example #13
0
def edit_profile():
    form = EditProfileForm(current_user.username)
    print("not here")
    print(form.username.data)
    print(form.about_me.data)
    if form.validate_on_submit():
        current_user.username = form.username.data
        print("in here")
        current_user.about_me = form.about_me.data
        db.session.commit()
        flash('Username and profile changed', 'success')
        return redirect(url_for('auth.user', username=current_user.username))
    # elif request.method == 'GET':
    #     form.username.data = current_user.username
    #     form.about_me.data = current_user.about_me
    #     print("in here instead")
    return render_template('edit_profile.html',
                           title='Edit Profile',
                           form=form)
Example #14
0
 def test_post(client, mocker, test_with_authenticated_user):
     mocker.patch("app.auth.email.send_change_email_confirmation")
     form = EditProfileForm(
         original_username=current_user.username,
         original_email=current_user.email,
         username="******",
         email="*****@*****.**",
     )
     response = client.post(url_for("auth.edit_profile"),
                            data=form.data,
                            follow_redirects=True)
     assert response.status_code == 200
     user = User.query.filter_by(username=form.username.data).first()
     assert user.username == "new_username"
     assert user.email == current_user.email
     email.send_change_email_confirmation.assert_called_once_with(
         form.email.data, user)
     assert b"Check your email to confirm the email address change." in response.data
     assert b"You change your profile data." in response.data
Example #15
0
    def test_post_with_valid_email(client, mocker,
                                   test_with_authenticated_user):
        mocker.patch("app.auth.email.send_change_email_confirmation")
        form = EditProfileForm(
            original_username=current_user.username,
            original_email=current_user.email,
            username="******",
            email="*****@*****.**",
        )
        client.post(url_for("auth.edit_profile"),
                    data=form.data,
                    follow_redirects=True)

        token = get_confirmation_token(id=1, email=form.email.data)
        response = client.post(url_for("auth.activate_email", token=token),
                               follow_redirects=True)
        assert response.status_code == 200
        user = User.query.get(1)
        assert user.email == form.email.data
        assert b"You confirm your new email address." in response.data
Example #16
0
def edit_profile():
    form = EditProfileForm()

    if form.validate_on_submit():
        name = form.name.data
        email = form.email.data
        job_title = form.job_title.data

        #edit a user
        try:
            current_user.edit(name, email, job_title)

            # Update successful
            flash(
                'User {}, updated with email={}, name={}, job_title={}'.format(
                    current_user.id, current_user.email, current_user.name,
                    current_user.get_meta()['job_title']), 'teal')

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

        except Exception as e:
            # Update unsuccessful
            error_json = e.args[1]
            error = json.loads(error_json)['error']['message']
            flash("Error: {}".format(error), 'red')

    form.name.data = current_user.name
    form.email.data = current_user.email

    meta = current_user.get_meta()
    if meta:
        form.job_title.data = meta['job_title']

    return render_template('auth/edit_profile.html',
                           title='Edit Profile',
                           form=form)