Пример #1
0
def user():
 
    form=UpdateAccountForm()
    if form.validate_on_submit():

        if form.picture.data:
            imageDict=upload(form.picture.data)
            user_collection.update_one({'username':current_user.username},{'$set':{'image_file':imageDict['url']}})
        
        username=form.username.data
        email=form.email.data
        new_interests=request.form.getlist('interests')

        if user_collection.count_documents({'username':username}):
            flash("username is taken")
            user_collection.update_one({'username':current_user.username},{'$set':{'email':email,'interests':new_interests}})
            return render_template('user.html', form=form)

        if user_collection.count_documents({'email':email}):
            flash("email is taken, please login again")
            user_collection.update_one({'username':current_user.username},{'$set':{'username':username,'interests':new_interests}})
            return redirect(url_for('login'))



        user_collection.update_one({'username':current_user.username},{'$set':{'username':username,'email':email,'interests':new_interests}})
        flash('Your account has been updated, please login again')
        return redirect(url_for('login'))

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

    image_file=url_for('static',filename='profilepics/'+current_user.image_file)
    return render_template('user.html', form=form,curr_interests=current_user.interests,curr_pic=current_user.image_file,interests=interests)
Пример #2
0
def user():
    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 created')
    elif request.method == 'GET':
        form.username.data = current_user.username
        form.email.data = current_user.email
    image_file = url_for('static',
                         filename='profilepics/' + current_user.image_file)
    return render_template('user.html', form=form)