示例#1
0
def account():
    form = UpdateAccountForm()
    if form.validate_on_submit():
        if form.picture.data:
            picture_file = save_picture(form.picture.data)
            current_user.image = picture_file

        current_user.username = form.username.data
        current_user.email = form.email.data
        current_user.fullname = form.fullname.data

        db.session.commit()

        flash('Your account has been updated.', 'success')
        return redirect(url_for('users.account'))

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

    page = request.args.get('page', 1, type=int)
    user = User.query.filter_by(username=current_user.username).first_or_404()
    return render_template('account.html',
                           title='Account',
                           user=user,
                           form=form)
示例#2
0
def account():
    form = UpdateAccountForm()
    if form.validate_on_submit():
        if form.picture.data:
            picture_file = save_picture(form.picture.data)
            current_user.image_file = picture_file
        current_user.username = form.username.data
        current_user.email = form.email.data
        current_user.firstName = form.firstName.data
        current_user.lastName = form.lastName.data
        current_user.about = form.about.data
        user = User(username=current_user.username,
                    firstName=current_user.firstName,
                    email=current_user.email,
                    lastName=current_user.lastName,
                    about=current_user.about,
                    image_file=image_file)
        db.session.commit()
        flash('Your account has been updated!', 'success')
        return redirect(url_for('users.account'))
    elif request.method == 'GET':
        form.username.data = current_user.username
        form.email.data = current_user.email
        form.firstName.data = current_user.firstName
        form.lastName.data = current_user.lastName
        form.about.data = current_user.about
    image_file = url_for('static',
                         filename='profile/' + current_user.image_file)
    return render_template('pages/account.html',
                           title='Account details',
                           description='ipNX Dashboard',
                           image_file=image_file,
                           form=form)
示例#3
0
def account():

    form = UpdateAccountForm()

    if form.validate_on_submit():
        if form.picture.data:
            picture_file = save_picture(form.picture.data)

            current_user.image_file = picture_file

        current_user.username = form.username.data

        current_user.email = form.email.data

        db.session.commit()

        flash('Account has been updated!', 'success')

        return redirect(url_for('users.account'))
    elif request.method == 'GET':

        form.username.data = current_user.username
        
        form.email.data = current_user.email

    image_file = url_for('static', filename='profile_pics/' + current_user.image_file)

    return render_template('account.html', title = 'Account', image_file = image_file, form = form)
示例#4
0
def account():
    form = UpdateAccountForm()
    if form.validate_on_submit():
        if form.picture.data:
            picture_file = save_picture(form.picture.data)
            current_user.image = picture_file

        current_user.username = form.username.data
        current_user.email = form.email.data
        db.session.commit()
        flash('Your account has been updated.', 'success')
        return redirect(url_for('users.account'))

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

    page = request.args.get('page', 1, type=int)
    user = User.query.filter_by(username=current_user.username).first_or_404()
    posts = Post.query.filter_by(author=user).order_by(
        Post.posted_date.desc()).all()
    print('--------', posts)
    image_file = url_for('static',
                         filename='profile_pics/' + current_user.image)
    return render_template('account.html',
                           title='Account',
                           posts=posts,
                           user=user,
                           image_file=image_file,
                           form=form)
示例#5
0
def account():
    form = UpdateAccountForm()
    if form.validate_on_submit():
        if form.picture.data:
            old_pic = current_user.image_file
            pic_file = save_picture(form.picture.data)
            current_user.image_file = pic_file
            if old_pic != 'default.jpg':
                os.remove(
                    os.path.join(app.root_path, 'static/profile_pics',
                                 old_pic))
        current_user.username = form.username.data
        current_user.email = form.email.data
        db.session.commit()
        flash('Your account has been updated', 'success')
        return redirect(url_for('users.account'))
    elif request.method == 'GET':
        form.username.data = current_user.username
        form.email.data = current_user.email
    image_file = url_for('static',
                         filename='profile_pics/' + current_user.image_file)
    return render_template('account.html',
                           title='Account',
                           image_file=image_file,
                           form=form)
示例#6
0
def account():
    form = UpdateAccountForm()
    if form.validate_on_submit():

        if form.picture.data:
            picture_file = save_picture(form.picture.data)
            current_user.image_file = picture_file

        current_user.username = form.username.data  # This is a SQLAlchemy perk it allows us to take the current_user data which we get thanks to flask_login, and then overwrites it with the form data the user submits!
        current_user.email = form.email.data  # So over here we're overwriting the current_user email with the email the user submits in the form!
        db.session.commit()  # Commit changes in database.db
        flash(
            'Your account has been updated!', 'success'
        )  # Display success message! For anyone wondering 'success' is just a bootstrap class, it gives a green-ish hue.
        return redirect(
            url_for('users.account')
        )  # Redirect to account, without this line of code, the broswer on the redirect below would send multiple post requests causing some problems
    elif request.method == 'GET':
        form.username.data = current_user.username  # This populates the username field upon a 'GET' request
        form.email.data = current_user.email  # This populates the email field upon a 'GET' request
    image_file = url_for('static',
                         filename='profile_images/' + current_user.image_file)
    return render_template('account.html',
                           title='Account',
                           image_file=image_file,
                           form=form)
示例#7
0
文件: routes.py 项目: Josip7171/bro1
def account():
    form = UpdateAccountForm()
    if form.validate_on_submit():
        if form.picture.data:
            picture_file = save_picture(form.picture.data)
            current_user.image_file = picture_file
        current_user.username = form.username.data
        current_user.email = form.email.data
        current_user.address = form.address.data
        current_user.country = form.country.data
        current_user.phone_number = form.phone_number.data
        current_user.about_me = form.about_me.data
        db.session.commit()
        flash('Your account has been updated.', 'success')
        return redirect(url_for('users.account'))
    elif request.method == 'GET':
        form.username.data = current_user.username
        form.email.data = current_user.email
        form.address.data = current_user.address
        form.country.data = current_user.country
        form.phone_number.data = current_user.phone_number
        form.about_me.data = current_user.about_me
    image_file = url_for('static',
                         filename='profile_pics/' + current_user.image_file)
    return render_template('account3.html', form=form, image_file=image_file)
示例#8
0
def users_profile():
    form = UpdateAccountForm()

    if 'submit' in request.form:
        if form.validate_on_submit():
            if form.picture.data:
                current_user.picture = save_picture(form.picture.data)

            current_user.username = form.username.data
            current_user.email = form.email.data

            db.session.commit()
            flash('Your account has been updated!', 'success')
            return redirect(url_for('users_blueprint.users_profile'))

    if 'cancel' in request.form:
        return redirect(url_for('users_blueprint.users_profile'))

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

    return render_template('users_profile.html',
                           title='Your Profile',
                           form=form)
示例#9
0
def update_account():
    form = UpdateAccountForm()
    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 updated!', 'success')
        return redirect(url_for('users.account'))
    elif request.method == 'GET':
        form.username.data = current_user.username
        form.email.data = current_user.email
    return render_template('account1.html', title='Account', form=form)
示例#10
0
def account():
    form=UpdateAccountForm()
    if form.validate_on_submit():
        if form.picture.data:               #check if any picture has been uploaded while updating details.
            picture_file=save_picture(form.picture.data)
            current_user.image_file = picture_file
        current_user.username=form.username.data
        current_user.email=form.email.data
        db.session.commit()
        flash('Your account has been updated!','Success')
        return redirect(url_for('users.account'))
    elif request.method == 'GET':                       #To display the email and username of user in the accounts page Textboxes
        form.username.data =current_user.username
        form.email.data =current_user.email
    image_file=url_for('static', filename='profile_pics/'+ current_user.image_file)
    return render_template('account.html',title='Account', image_file=image_file, form=form)
示例#11
0
def dashboard():
    if current_user.has_role('primeserver'):
        form = UpdateAccountPrimeServerForm()
    else:
        form = UpdateAccountForm()
    if form.validate_on_submit():
        if form.picture.data:
            picture_file = save_picture(form.picture.data)
            current_user.image_file = picture_file
        current_user.username = form.username.data
        current_user.email = form.email.data.lower()
        current_user.bio = form.bio.data
        current_user.favsong = form.favsong.data
        if current_user.has_role('primeserver'):
            current_user.ign = form.ign.data
            current_user.noteskin = form.noteskin.data
            current_user.scrollspeed = round(0.5 * round(float(form.scrollspeed.data) / 0.5), 1)
            current_user.modifiers = current_user.modifiers | mods_to_int([], form.judgement.data)
            current_user.psupdate = "True" if not form.psupdate.data else "False"
        db.session.commit()
        flash('Account details updated!', 'success')
        return redirect(url_for('users.dashboard'))
    elif request.method == "GET":
        form.username.data = current_user.username
        form.email.data = current_user.email
        form.bio.data = current_user.bio
        form.favsong.data = current_user.favsong
        if current_user.has_role('primeserver'):
            form.ign.data = current_user.ign
            form.noteskin.data = current_user.noteskin
            form.scrollspeed.data = current_user.scrollspeed
            form.judgement.data = int_to_judge(current_user.modifiers)
            form.psupdate.data = current_user.psupdate == "False"
    image_file = url_for('static', filename='profile_pics/' + current_user.image_file)
    return render_template("dashboard.html", title="Dashboard", image_file=image_file, form=form, current_user=current_user)
示例#12
0
def profile(user):
    form = UpdateAccountForm()
    if form.validate_on_submit():
        if form.picture.data:
            pic_file = save_img(form.picture.data)
            current_user.image_file = pic_file
        current_user.username = form.username.data
        current_user.email = form.email.data
        db.session.commit()
        print('your account has been updated')
        return redirect(url_for('users.profile', user=current_user.username))
    elif request.method == 'GET':
        form.username.data = current_user.username
        form.email.data = current_user.email
    image_file = url_for('static',
                         filename='profile_pics/' + current_user.image_file)
    return render_template("profile.html", image_src=image_file, form=form)
示例#13
0
def account():
    form = UpdateAccountForm()
    if form.validate_on_submit():
        if form.picture.data:
            pic_file = save_picture(form.picture.data)
            current_user.img = pic_file

        current_user.username = form.username.data
        current_user.email = form.email.data
        db.session.commit()
        flash(f"Account info updated", "success")
        return redirect(url_for("users.account"))
    elif request.method == "GET":
        form.username.data = current_user.username
        form.email.data = current_user.email
    img = url_for("static", filename="profile_pics/" + current_user.img)
    return render_template("account.html", title="Account", img=img, form=form)
示例#14
0
def myblog():
    form = UpdateAccountForm()
    if form.validate_on_submit():
        if form.picture.data:
            picture_file = save_picture(form.picture.data)
            current_user.profile_image_file = picture_file
        if form.cover.data:
            cover_file = save_cover(form.cover.data)
            current_user.blog[0].cover_image_file = cover_file

        current_user.user_name = form.user_name.data
        current_user.email = form.email.data

        current_user.blog[0].blog_name = form.blog_name.data
        current_user.blog[0].phrase = form.phrase.data
        current_user.blog[0].about = form.about.data

        db.session.commit()
        flash('Blog updated.', 'success')
        return redirect(url_for('users.myblog'))
    elif request.method == 'GET':
        form.user_name.data = current_user.user_name
        form.email.data = current_user.email

        form.blog_name.data = current_user.blog[0].blog_name
        form.phrase.data = current_user.blog[0].phrase
        form.about.data = current_user.blog[0].about
    else:
        flash('update failed, check the fields', 'danger')
    image_file = url_for('static',
                         filename='profile_pics/' +
                         current_user.profile_image_file)
    image_cover = url_for('static',
                          filename='cover_pics/' +
                          current_user.blog[0].cover_image_file)

    page = request.args.get('page', 1, type=int)
    posts = Post.query.filter_by(author=current_user).order_by(
        Post.created_date.desc()).paginate(page=page, per_page=5)
    return render_template('profile.html',
                           image_file=image_file,
                           image_cover=image_cover,
                           form=form,
                           posts=posts)
示例#15
0
def account():
    form = UpdateAccountForm()
    if form.validate_on_submit():
        user_profile = UserProfile(
            author=current_user, #changed authors to author, recreate database after changing relationships and keys in models.py
            full_name=form.full_name.data,
            address_one=form.address_one.data,
            address_two=form.address_two.data,
            city=form.city.data,
            state=form.state.data,
            zipcode=form.zipcode.data
        )
        db.session.add(user_profile)
        db.session.commit()
        flash('Your profile has been saved', 'success')
        return redirect(url_for('main.home'))
    # elif request.method == 'GET':
    #     form.username.data = current_user.username
    #     form.email.data = current_user.email
    return render_template('account.html', title='Account', form=form)
示例#16
0
def account():
    form = UpdateAccountForm()
    form.upline.choices = [(upline.id, upline.username)
                           for upline in User.query.all()]
    form.referrer.choices = [(referrer.id, referrer.username)
                             for referrer in User.query.all()]
    if form.validate_on_submit():
        if form.picture.data:
            picture_file = save_picture(form.picture.data)
            current_user.image_file = picture_file
        current_user.username = form.username.data
        current_user.email = form.email.data
        current_user.fullname = form.fullname.data
        current_user.title = form.title.data
        current_user.ic_number = form.ic_number.data
        current_user.phone_number = form.phone_number.data
        current_user.birthday = form.birthday.data
        current_user.location = form.location.data
        current_user.upline_id = form.upline.data
        current_user.referrer_id = form.referrer.data
        db.session.commit()
        flash('Your account has been updated!', 'success')
        return redirect(url_for('users.account'))
    elif request.method == 'GET':
        form.username.data = current_user.username
        form.email.data = current_user.email
        form.fullname.data = current_user.fullname
        form.title.data = current_user.title
        form.ic_number.data = current_user.ic_number
        form.phone_number.data = current_user.phone_number
        form.birthday.data = current_user.birthday
        form.location.data = current_user.location
        form.upline.data = current_user.upline_id
        form.referrer.data = current_user.referrer_id
    image_file = url_for('static',
                         filename='profile_pics/' + current_user.image_file)
    return render_template('account.html',
                           title='Account',
                           image_file=image_file,
                           form=form)
示例#17
0
def account():
    form = UpdateAccountForm()
    if form.validate_on_submit():
        if form.picture.data:
            picture_file = save_picture(form.picture.data)
            current_user.image_file = picture_file
        current_user.username = form.username.data
        current_user.email = form.email.data
        db.session.commit()
        flash('Your account has been updated!', 'success')
        return redirect(url_for('users.account'))
        #By redirecting, we don't get the browser message saying
        #(are you sure you want to refresh? It will cause bla bla bla)
    elif request.method == 'GET':
        form.username.data = current_user.username
        form.email.data = current_user.email
    image_file = url_for('static',
                         filename='images/' + current_user.image_file)
    return render_template('account.html',
                           title='Account',
                           image_file=image_file,
                           form=form)
示例#18
0
def account():
    form = UpdateAccountForm()
    if form.validate_on_submit():
        # If there is a profile pic passed save it
        if form.picture.data:
            picture_file = save_picture(form.picture.data)
            current_user.image_file = picture_file
        current_user.username = form.username.data
        current_user.email = form.email.data
        db.session.commit()
        flash('Your account has been updated!', 'success')
        return redirect(url_for('users.account'))
    elif request.method == 'GET':
        # Load with initial values if GET request
        form.username.data = current_user.username
        form.email.data = current_user.email
         # Get latest post of user
        latestPosts = Post.query.filter_by(author=current_user).order_by(Post.date_posted.desc()).limit(6).all()

    image_file = url_for('static', filename='profile_pics/' + current_user.image_file)
    return render_template('account.html', title='Account',
                           image_file=image_file, form=form, user=current_user,latestPosts=latestPosts)
示例#19
0
def account():
    form = UpdateAccountForm()
    if form.validate_on_submit():
        current_user.username = form.username.data
        current_user.email = form.email.data
        current_user.company = form.company.data

        try:
            db.session.commit()
        except Exception as e:
            logger.debug("Error: {} Account Info Update ".format(current_user))
            logger.debug("ERROR {}.".format(e))
        else:
            flash('Your account has been updated!', 'success')
            logger.debug("Updated account: {}.".format(current_user))
            return redirect(url_for('users_blueprint.account'))

    elif request.method == 'GET':
        form.username.data = current_user.username
        form.email.data = current_user.email
        form.company.data = current_user.company
    return render_template('account.html', form=form)
示例#20
0
def account():
    form = UpdateAccountForm()
    if form.validate_on_submit():
        if form.picture.data:
            picture_file = save_picture(form.picture.data)
            current_user.image_file = picture_file
        current_user.username = form.username.data
        current_user.email = form.email.data
        db.session.commit()
        flash("Your account has been updated!!", "success")
        # Because of POST GET request resending and stuff
        return redirect(url_for("users.account"))

    elif request.method == "GET":
        form.username.data = current_user.username
        form.email.data = current_user.email
    image_file = url_for('static',
                         filename='profile_pics/{}'.format(
                             current_user.image_file))
    return render_template('account.html',
                           title='Account',
                           image_file=image_file,
                           form=form)
示例#21
0
def account():
    form = UpdateAccountForm()
    if form.validate_on_submit():
        if form.picture.data:
            picture_file = save_picture(form.picture.data)
            current_user.image_file = picture_file
        current_user.username = form.username.data
        current_user.email = form.email.data
        db.session.commit()
        flash('Your account has been updated!', 'success')
        return redirect(
            url_for('users.account')
        )  # this line forces the browser to send another get request preventing the 'do you want to submit your data again?' issue
    elif request.method == 'GET':
        # if it's a GET request the pre-populate the fields with the current variables
        form.username.data = current_user.username
        form.email.data = current_user.email
    image_file = url_for('static',
                         filename='profile_pics/' + current_user.image_file)
    return render_template('account.html',
                           title="Account",
                           image_file=image_file,
                           form=form)
示例#22
0
def dashboard():
    form = UpdateAccountForm()
    if form.validate_on_submit():
        if form.picture.data:
            picture_file = save_picture(form.picture.data)
            current_user.image_file = picture_file
        current_user.username = form.username.data
        current_user.email = form.email.data
        current_user.bio = form.bio.data
        current_user.favsong = form.favsong.data
        db.session.commit()
        flash('Account details updated!', 'success')
        return redirect(url_for('users.dashboard'))
    elif request.method == "GET":
        form.username.data = current_user.username
        form.email.data = current_user.email
        form.bio.data = current_user.bio
        form.favsong.data = current_user.favsong
    image_file = url_for('static',
                         filename='profile_pics/' + current_user.image_file)
    return render_template("dashboard.html",
                           title="Dashboard",
                           image_file=image_file,
                           form=form)
示例#23
0
def account():
    pass
    form = UpdateAccountForm()

    if request.method == 'POST':
        pass
        current_user.username = form.username.data
        current_user.email = form.email.data
        db.session.commit()
        flash('Username and/or Email updated!', 'success')

        return redirect(url_for('users.account'))

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

    return render_template('account.html', title='Account', form=form)
示例#24
0
def account(username):
    if current_user.is_company or current_user.username != username:
        abort(Constants.FORBIDDEN_PAGE_ERROR_PAGE)

    user = User.query.filter_by(username=username).first_or_404()
    account_form = UpdateAccountForm()
    password_form = UpdatePasswordForm()
    picture_form = UpdatePictureForm()

    if picture_form.submit_picture.data and picture_form.validate_on_submit():
        if picture_form.image_file.data:
            remove_from_s3(user.username,
                           picture_form.image_file.data.filename,
                           "profilePics", Config.AWS_STORAGE_BUCKET_NAME)
            new_picture = upload_to_s3(user.username,
                                       picture_form.image_file.data,
                                       "profilePics",
                                       Config.AWS_STORAGE_BUCKET_NAME,
                                       Constants.PROFILE_PICTURE_SIZE)
            user.image_file = new_picture
            database.session.commit()
            flash("Your profile picture has been changed!", "success")

        return redirect(url_for('users.account', username=user.username))

    if account_form.submit_info.data and account_form.validate_on_submit():
        valid_input = True

        if account_form.firstname.data and account_form.firstname.data != user.firstname:
            user.firstname = account_form.firstname.data

        if account_form.lastname.data and account_form.lastname.data != user.lastname:
            user.lastname = account_form.lastname.data

        if account_form.username.data and account_form.validate_username(
                account_form.username):
            user.username = account_form.username.data.lower()
        else:
            valid_input = False
            flash("Username already being used. Please try again", "danger")

        if account_form.validate_email(account_form.email):
            user.email = account_form.email.data.lower()
        else:
            valid_input = False
            flash("Email already being used. Please try again", "danger")

        if account_form.validate_phone_number(account_form.phone_number):
            user.phone_number = account_form.phone_number.data
        else:
            valid_input = False
            flash("Phone number already being used. Please try again",
                  "danger")

        if account_form.occupation.data and account_form.occupation.data != user.occupation:
            user.occupation = account_form.occupation.data

        if account_form.hometown.data and account_form.hometown.data != user.hometown:
            user.hometown = account_form.hometown.data

        if account_form.bio.data and account_form.bio.data != user.bio:
            user.bio = account_form.bio.data

        if valid_input:
            database.session.commit()
            flash("Your account changes have been saved!", "success")

        return redirect(url_for('users.account', username=user.username))

    if password_form.submit_password.data and password_form.validate_on_submit(
    ):
        valid_input = True

        if password_form.validate_password(password_form.old_password):
            hashed_password = bcrypt.generate_password_hash(
                password_form.new_password.data)
            user.password = hashed_password
        else:
            valid_input = False
            flash("Incorrect old password. Please try again", "danger")

        if valid_input:
            database.session.commit()
            flash("Your password has been changed!", "success")

        return redirect(url_for('users.account', username=user.username))

    if request.method == "GET":
        account_form.firstname.data = user.firstname
        account_form.lastname.data = user.lastname
        account_form.username.data = user.username
        account_form.email.data = user.email
        account_form.phone_number.data = user.phone_number
        account_form.occupation.data = user.occupation
        account_form.hometown.data = user.hometown
        account_form.bio.data = user.bio

    return render_template("account_user.html",
                           user=user,
                           account_form=account_form,
                           password_form=password_form,
                           picture_form=picture_form)