Пример #1
0
def profile():

    form = ProfileForm()
    Id = len(UserProfile.query.all())
    if request.method == "POST" and form.validate_on_submit():
        first_name = form.first_name.data
        last_name = form.last_name.data
        gender = form.gender.data
        email = form.email.data
        location = form.location.data
        biography = form.biography.data
        image = form.image.data
        joined_on = form.joined_on.data
        img_name = first_name + last_name + str(Id + 1)

        NewUser = UserProfile(first_name=first_name,
                              last_name=last_name,
                              gender=gender,
                              email=email,
                              location=location,
                              biography=biography,
                              image=image,
                              joined_on=joined_on)

        db.session.add(NewUser)
        db.session.commit()

        image.save("app/static/profilepictures/" + img_name + ".png")

        flash("New User Profile Created", "success")
        return redirect(url_for("profiles"))

    return render_template('profile.html', form=form)
Пример #2
0
def addProfile():
    profileform = ProfileForm()
    if request.method == "POST" and profileform.validate():
        if profileform.validate_on_submit():
            first_name = profileform.first_name.data
            last_name = profileform.last_name.data
            gender = profileform.gender.data
            email = profileform.email.data
            location = profileform.location.data
            bio = profileform.bio.data
            photo = profileform.photo.data
            
            photo_filename = secure_filename(photo.filename)
            photo.save(os.path.join(app.config['UPLOAD_FOLDER'], photo_filename))
            
            profile = UserProfile(first_name,last_name,gender,location, email,bio, photo_filename)
            db.session.add(profile)
            db.session.commit()
            # photo.save(os.path.join(app.config))
            flash('User sucessfully added', 'success')
            return redirect(url_for('profiles'))
    else: 
        return render_template('addProfile.html', form = profileform)

    if request.method =="GET":
        return render_template('addProfile.html')
Пример #3
0
def profile():
    """Render the website's profile page to add a profile."""
    form = ProfileForm()
    if request.method == "POST" and form.validate_on_submit():
        firstname = form.firstname.data
        lastname = form.lastname.data
        gender = form.gender.data
        email = form.email.data
        location = form.location.data
        biography = form.biography.data
        photo = form.photo.data
        date = datetime.today().strftime('%B %d, %Y')

        filename = secure_filename(photo.filename)
        photo.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))

        profile = Profile(first_name=firstname,
                          last_name=lastname,
                          gender=gender,
                          email=email,
                          location=location,
                          biography=biography,
                          photo=filename,
                          date=date)
        db.session.add(profile)
        db.session.commit()
        flash('Profile Successfully added.', 'success')
        profiles = Profile.query.all()
        return render_template('profiles.html', profiles=profiles)

    return render_template('profile.html', form=form)
Пример #4
0
def profile():
    # Instantiate your form class
    if request.method == 'GET':
        form = ProfileForm()
        return render_template('profile.html', form=form)

    # Validate file upload on submit
    form = ProfileForm()
    if request.method == 'POST' and form.validate_on_submit():
        # Get file data and save to your uploads folder
        F_Name = form.F_Name.data
        L_Name = form.L_Name.data
        Gender = form.Gender.data
        Email = form.Email.data
        Location = form.Location.data
        Biography = form.Biography.data
        file = form.file.data
        filename = secure_filename(file.filename)
        file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
        profile = Profile(F_Name, L_Name, Gender, Email, Location, Biography,
                          filename,
                          datetime.datetime.now().strftime("%B %d, %Y"))
        db.session.add(profile)
        db.session.commit()

        flash('Profile Added', 'success')
        return redirect(url_for('profiles', images=get_uploaded_images()))
    return redirect(url_for('home'))
Пример #5
0
def profile():
    form = ProfileForm()
    # if current_user.is_authenticated:
    #     # if user is already logged in, just redirect them to our secure page
    #     # or some other page like a dashboard
    #     return redirect(url_for('secure_page'))

    # Here we use a class of some kind to represent and validate our
    # client-side form data. For example, WTForms is a library that will
    # handle this for us, and we use a custom LoginForm to validate.
    if request.method == 'POST' and form.validate_on_submit():
        firstName = form.fname.data
        lastName = form.lname.data
        email = form.email.data
        location = form.location.data
        sex = form.sex.data
        bio = form.bio.data
        if form.photo.data:
            #filename = secure_filename(form.fle.data.filename)
            #form.fle.data.save('uploads/' + filename)
            im = request.files['photo']
            im_fn = form.fname.data + '_' + secure_filename(im.filename)
            file_path = os.path.join(app.config['UPLOAD_FOLDER'], im_fn)
            im.save(file_path)
        user = UserProfile.query.filter_by(email=email).first()
        #if user is not None and check_password_hash(user.password, password):
        if user is None:
            profile = UserProfile(firstName, lastName, location, email, sex,
                                  bio, datetime.now(), im_fn)
            db.session.add(profile)
            db.session.commit()
        return redirect(url_for('showProfiles'))
    flash_errors(form)
    return render_template('form.html', form=form)
Пример #6
0
def profile():
    form = ProfileForm()
    if request.method == "POST" and form.validate_on_submit():

        # fname = form.fname.data
        # lname = form.lname.data
        # email = form.email.data
        # location = form.location.data
        # gender = form.gender.data
        # biography = form.biography.data

        file = form.image.data
        filename = secure_filename(file.filename)
        file.save(os.path.join(path, filename))

        user = UserProfile(
            request.form['fname'],
            request.form['lname'],
            request.form['email'],
            request.form['location'],
            request.form['gender'],
            request.form['bio'],
            filename,
            # datetime.datetime.now()
            datetime.datetime.now().strftime("%B %d, %Y"))

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

        flash('Profile Saved', 'success')
        return redirect(url_for("profiles"))
    return render_template("profile.html", form=form)
Пример #7
0
def register():
    """ Renders user registration page"""
    form = ProfileForm()

    if request.method == 'POST' and form.validate_on_submit():
        username = form.username.data
        password = form.password.data
        firstname = form.firstname.data
        lastname = form.lastname.data
        location = form.location.data
        email = form.email.data
        biography = form.biography.data

        photo = form.profile_photo.data
        filename = secure_filename(photo.filename)
        #photo.save(os.path.join(app.config['UPLOAD_FOLDER'],filename))
        photo.save(
            os.path.join("./app", app.config['PROFILE_IMG_UPLOAD_FOLDER'],
                         filename))

        date_created = datetime.datetime.now().strftime("%B %d, %Y")

        new_user = UserProfile(username=username,
                               password=password,
                               firstname=firstname,
                               lastname=lastname,
                               biography=biography,
                               profile_photo=filename,
                               location=location,
                               joined_on=date_created,
                               email=email)
        db.session.add(new_user)
        db.session.commit()

        return jsonify(message="User successfully registered")
Пример #8
0
def profile(user_id):
    if current_user.id != user_id:
        return redirect(request.args.get('next') or url_for('index'))
    user = User.query.filter_by(id=user_id).first()
    form = ProfileForm()
    if form.validate_on_submit():
        User.edit(user, {
            'delete': form.delete.data,
            'login': form.login.data,
            'email': form.email.data,
            'first_name': form.first_name.data,
            'last_name': form.last_name.data,
            'type': form.type.data,
        })
        if form.delete.data:
            flash('Profile is deleted', 'primary')
        else:
            flash('Profile is edited', 'primary')
        return redirect(url_for('login'))
    if request.method == 'GET':
        form.login.data = user.login
        form.email.data = user.email
        form.first_name.data = user.first_name
        form.last_name.data = user.last_name
        form.type.data = user.type
    return render_template(
        'profile.html', title='Profile', form=form,
        current_user=current_user
    )
Пример #9
0
def profile():
    """Render the website's profile page."""
    profilePage = ProfileForm()

    if request.method == 'POST':
        if profilePage.validate_on_submit():

            firstName = profilePage.firstName.data
            lastName = profilePage.lastName.data
            gender = profilePage.gender.data
            email = profilePage.email.data
            location = profilePage.location.data
            biography = profilePage.biography.data
            photo = profilePage.photo.data

            filename = secure_filename(photo.filename)
            photo.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))

            profile = Profile(first_name=firstName,
                              last_name=lastName,
                              gender=gender,
                              email=email,
                              location=location,
                              biography=biography,
                              profile_picture="uploads/" + filename)
            db.session.add(profile)
            db.session.commit()

            flash('New Profile Created!', 'success')
            return redirect(url_for('profiles'))
        else:
            flash_errors(profilePage)

    return render_template('profile.html', form=profilePage)
Пример #10
0
def edit_profile(username):
    """Endpoint to edit a user profile."""
    form = ProfileForm()
    if form.validate_on_submit():
        if current_user.type_of_user in [
                1, 2
        ] or username == current_user.username:
            user = User.query.filter_by(username=username).first_or_404()
            user.username = form.username.data
            user.email = form.email.data
            user.edit_date = datetime.datetime.utcnow().date()
            if current_user.type_of_user in [2]:
                user.type_of_user = int(form.type_of_user.data)
            user.edit_uid = current_user.id
            db.session.commit()
            flash("Your changes have been saved.")
            return redirect(url_for("edit_profile", username=user.username))
        else:
            flash("You are not authorised to view this!")
            return redirect(url_for("index"))
    elif request.method == "GET":
        if current_user.type_of_user in [
                1, 2
        ] or username == current_user.username:
            user = User.query.filter_by(username=username).first_or_404()
            form.username.data = user.username
            form.email.data = user.email
            form.type_of_user.data = str(user.type_of_user)
            return render_template("edit_profile.html",
                                   title="Edit Profile",
                                   form=form)
        else:
            flash("You are not authorised to view this!")
            return redirect(url_for("index"))
Пример #11
0
def profile():
    form = ProfileForm()
    if request.method == "POST":
        if form.validate_on_submit() == True:
            
            #Gets the user input from the form
            fname = form.firstname.data
            lname = form.lastname.data
            gender = form.gender.data
            email = form.email.data
            location = form.location.data
            bio = form.bio.data
            date = format_date_joined()
            filename = assignPath(form.photo.data)
            
            #create user object and add to database
            user = UserProfile(fname,lname,gender,email,location,bio, date, filename)
            db.session.add(user)
            db.session.commit()

            # remember to flash a message to the user
            flash('User information submitted successfully.', 'success')
        else:
            flash('User information not submitted', 'danger')
        return redirect(url_for("profiles"))  # they should be redirected to a secure-page route instead
    return render_template("profile.html", form=form)
Пример #12
0
def view_profile():
    form = ProfileForm()

    form.sex.data = int(form.sex.data)
    form.diabetes.data = int(form.diabetes.data)
    form.smoker.data = float(form.smoker.data)
    if form.validate_on_submit():
        user = UserSession.query.get(current_user.username)
        if form.age.data != '':
            user.age = form.age.data
        if form.sex.data != '-1':
            user.sex = form.sex.data
        if form.height.data != '':
            user.height = form.height.data
        if form.weight.data != '':
            user.weight = form.weight.data
        if form.smoker.data != 0.0:
            user.smoker = form.smoker.data
        if form.blood_pressure_systolic != '' and form.blood_pressure_diastolic.data != '':
            user.blood_pressure_systolic = form.blood_pressure_systolic.data
            user.blood_pressure_diastolic = form.blood_pressure_diastolic.data
        if form.diabetes.data != -1:
            user.diabetes = form.diabetes.data

        db.session.commit()
        return render_template("profile.html", form=form)

    return render_template("profile.html", form=form)
Пример #13
0
def profile_form_submit(user_id):
    form = ProfileForm()
    form['csrf_token'].data = request.cookies['csrf_token']
    if form.validate_on_submit():
        profile = Profile.query.filter(Profile.user_id == user_id).first()
        if profile:
            profile.about_me = form.data['about_me']
            profile.location = form.data['location']
            profile.nin_gt = form.data['nin_gt']
            profile.ps_gt = form.data['ps_gt']
            profile.xbox_gt = form.data['xbox_gt']
            profile.steam_gt = form.data['steam_gt']
            profile.discord_gt = form.data['discord_gt']
        else:
            profile = Profile(
                user_id=user_id,
                about_me=form.data['about_me'],
                location=form.data['location'],
                nin_gt=form.data['nin_gt'],
                ps_gt=form.data['ps_gt'],
                xbox_gt=form.data['xbox_gt'],
                steam_gt=form.data['steam_gt'],
                discord_gt=form.data['discord_gt'],
            )
        db.session.add(profile)
        db.session.commit()
        return profile.to_dict()
Пример #14
0
def profile():
    """Render the website's profile page."""
    profileform = ProfileForm()
    if request.method == 'POST' and profileform.validate_on_submit():
        firstname = profileform.firstname.data
        lastname = profileform.lastname.data
        gender = profileform.gender.data
        email = profileform.email.data
        location = profileform.location.data
        biography = profileform.biography.data
        photo = profileform.photo.data
        flash('Profile has been created', 'success')
        filename = secure_filename(photo.filename)
        photo.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))

        userprofile = UserProfile(first_name=firstname,
                                  last_name=lastname,
                                  gender=gender,
                                  email=email,
                                  location=location,
                                  biography=biography,
                                  profilepic="uploads/" + filename)
        db.session.add(userprofile)
        db.session.commit()
        return redirect(url_for('profiles'))
    return render_template('profile.html', form=profileform)
def profile(username):
    username = username.lower()
    preparedQuery = 'SELECT * FROM Users WHERE username=?;'
    user = safe_query(preparedQuery, (username,), one=True)
    edit = False
    form = ProfileForm()

    if username == current_user.username:
        if form.validate_on_submit():
            preparedQuery = 'UPDATE Users ' \
                            'SET education=?, employment=?, music=?, movie=?, nationality=?, birthday=? ' \
                            'WHERE id=?;'
            data = (form.education.data, form.employment.data, form.music.data, form.movie.data, form.nationality.data,
                    form.birthday.data, current_user.id)
            safe_query(preparedQuery, data)
            return redirect(url_for('profile', username=username))
        elif form.is_submitted():
            edit = True
        if user['education'] != 'Unknown':
            form.education.data = user['education']
        if user['nationality'] != 'Unknown':
            form.nationality.data = user['nationality']
        if user['music'] != 'Unknown':
            form.music.data = user['music']
        if user['movie'] != 'Unknown':
            form.movie.data = user['movie']
        if user['employment'] != 'Unknown':
            form.employment.data = user['employment']
        if user['birthday'] != 'Unknown':
            form.birthday.data = datetime.strptime(user['birthday'], '%Y-%m-%d')

    return render_template('profile.html', title='Profile', user=user, form=form, edit=edit)
Пример #16
0
def profile():
    form = ProfileForm()
    if request.method == "POST" and form.validate_on_submit():
        firstname = form.firstname.data
        lastname = form.lastname.data
        email = form.email.data
        location = form.location.data
        gender = form.gender.data
        biography = form.biography.data
        photo = form.photo.data
        filename = secure_filename(photo.filename)
        photo.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
        user = UserProfile(first_name=firstname,
                           last_name=lastname,
                           email=email,
                           location=location,
                           gender=gender,
                           biography=biography,
                           filename=filename,
                           created_on=format_date_joined())
        db.session.add(user)
        db.session.commit()
        flash('Profile was successfully added', 'success')
        return redirect(url_for('profiles'))
    else:

        return render_template('profile.html', form=form)
Пример #17
0
def profile():
    form = ProfileForm()
    label1 = ''
    label2 = ''
    flag = False
    if request.method == 'POST':
        if 'submitProfile' in request.form:
            if form.validate_on_submit():
                current_user.firstName = request.form['firstname']
                current_user.lastName = request.form['lastname']
                current_user.studyField = request.form['field_selection']
                print(request.form['field_selection'])
                current_user.university = request.form['university_selection']
                print(request.form['university_selection'])
                current_user.bio = request.form['bio']
                current_user.complete = True
                db.session.add(current_user)
                db.session.commit()
                label1 = 'your information submitted successfully ... '
        if 'changePassword' in request.form:
            if request.form['password'] != '':
                current_user.set_password(request.form['password'])
                db.session.add(current_user)
                db.session.commit()
                label2 = 'your password changed successfully ... '
            else:
                flag = True
                label2 = 'please enter correct password !! '

    return render_template('landing_page/profile.html',
                           label1=label1,
                           label2=label2,
                           flag=flag,
                           title='Friends',
                           form=form)
Пример #18
0
def profile():
    form = ProfileForm()
    if request.method == "POST":
        if form.validate_on_submit():

            #Gets the user input from the form
            fname = form.first_name.data
            lname = form.last_name.data
            username = form.Username.data
            password = form.Password.data
            account_type = form.account_type.data
            date = format_date_joined()
            pic = assignPathU(form.pic.data)
            rsvplst = ""

            #create user object and add to database
            user = UserProfile(fname, lname, username, password, account_type,
                               pic, date, rsvplst)
            db.session.add(user)
            db.session.commit()

            # remember to flash a message to the user
            flash('User information submitted successfully.', 'success')
        else:
            flash('User information not submitted', 'danger')
        return redirect(
            url_for("login")
        )  # they should be redirected to a secure-page route instead
    return render_template("profile.html", form=form)
Пример #19
0
def add_profile():
    """Either (GET) provide profile form or (POST) create the profile"""
    form = ProfileForm()
    if form.validate_on_submit():
        # Get values from form
        fname = request.form['first_name']
        lname = request.form['last_name']
        gender = request.form['gender']
        email = request.form['email']
        location = request.form['location']
        bio = request.form['bio']

        try:
            """Idea for now: need to save the picture, and save the filename. Store items to database"""
            p_filename = save_photo(
                request.files['profile_picture'])  # profile photo filename
            profile = UserProfile(fname, lname, gender, email, location, bio,
                                  p_filename)
            db.session.add(profile)
            db.session.commit()
            flash('User successfully created', 'success')
            return redirect(url_for('view_profiles'))
        except:
            flash("User could not be created", 'danger')
    return render_template('add_profile.html', form=form)
Пример #20
0
def profile():
    form = ProfileForm()
    if request.method == 'POST':
        if form.validate_on_submit():
            firstname = form.firstname.data
            lastname = form.lastname.data
            location = form.location.data
            email = form.email.data
            biography = form.biography.data
            gender = form.gender.data

            #form.photo.label.text = 'Browse...'
            photo = form.photo.data
            filename = secure_filename(photo.filename)
            photo.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))

            date_created = datetime.datetime.now().strftime("%B %d, %Y")

            new_user = UserProfile(firstname=firstname,
                                   lastname=lastname,
                                   biography=biography,
                                   photo=filename,
                                   gender=gender,
                                   location=location,
                                   created_on=date_created,
                                   email=email)

            db.session.add(new_user)
            db.session.commit()

            flash('Profile added', 'success')
            return redirect(url_for("profiles"))
    return render_template('profile.html', form=form)
Пример #21
0
def profile():
    profile = UserProfile.query.filter_by(user_id=current_user.id).first()
    form = ProfileForm(obj=profile)
    if form.validate_on_submit():
        if profile:
            form.populate_obj(profile)
            db.session.commit()

            flash('Profile Information has been saved!')
            return redirect(url_for('account'))
        new_profile = UserProfile(user_id=current_user.id,
                                  first_name=form.first_name.data,
                                  last_name=form.last_name.data,
                                  birth_date=form.birth_date.data,
                                  address_1=form.address_1.data,
                                  address_2=form.address_2.data,
                                  city=form.city.data,
                                  state=form.state.data,
                                  zip=form.zip.data)

        db.session.add(new_profile)
        db.session.commit()

        flash('Profile Information has been saved!')
        return redirect(url_for('account'))
    return render_template('profile.html', form=form)
Пример #22
0
def profile():
    """Render the website's profile page"""
    form = ProfileForm()
    us_Id = len(UserProfile.query.all())

    if request.method == "POST" and form.validate_on_submit():

        first_name = form.first_name.data
        last_name = form.last_name.data
        gender = form.gender.data
        location = form.location.data
        email = form.email.data
        bio = form.biography.data
        date = format_date(get_date())
        image = form.image.data
        imageName = first_name + last_name + str(us_Id + 1)

        newUser = UserProfile(first_name=first_name,
                              last_name=last_name,
                              gender=gender,
                              location=location,
                              email=email,
                              biography=bio,
                              created_on=date,
                              profilePic=imageName)
        db.session.add(newUser)
        db.session.commit()

        image.save("app/static/profilepictures/" + imageName + ".png")

        flash("New User Profile Created", "success")
        return redirect(url_for("profiles"))

    return render_template("profile.html", form=form)
Пример #23
0
def profile():
    form = ProfileForm()
    if request.method == "POST" and form.validate_on_submit():
        photo = form.Pic.data
        name = form.firstName.data + " " + form.lastName.data
        gender = form.gender.data
        email = form.email.data
        location = form.location.data
        bio = form.biography.data

        filename = secure_filename(photo.filename)
        photo.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
        #print(os.path.join(
        #  app.config['UPLOAD_FOLDER'], filename
        #))
        created_on = getDate()
        user = Users(created_on, name, location, filename, gender, email, bio)

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

        flash("user was successfully added", 'success')
        return redirect(url_for("home"))
    print(form.errors)
    return render_template("profile.html", form=form)
Пример #24
0
def profile():
    form1 = ProfileForm()
    form2 = PasswordForm()
    user = User.query.filter_by(UserAccountId=current_user.get_id()).first()

    if form1.submit.data and form1.validate_on_submit():
        if user.Profile == None:
            user_profile = UserProfile(FirstName=form1.first_name.data, LastName=form1.last_name.data, DOB=form1.dob.data, \
                Phone=form1.phone.data, Address=form1.address.data, Country=form1.country.data, owner=user)
            db.session.add(user_profile)
            db.session.commit()
        else:
            user.Profile.FirstName = form1.first_name.data
            user.Profile.LastName = form1.last_name.data
            user.Profile.DOB = form1.dob.data
            user.Profile.Phone = form1.phone.data
            user.Profile.Address = form1.address.data
            user.Profile.Country = form1.country.data
            db.session.commit()
        flash('Changes succesfully saved!')
        return redirect(url_for('profile'))

    if form2.update.data and form2.validate_on_submit():
        if user is None or not user.check_password(form2.password.data):
            flash('Invalid current password')
            return redirect(url_for('profile'))
        user.set_password(form2.new_password.data)
        db.session.commit()
        flash('Password succesfully updated!')
        return redirect(url_for('profile'))

    return render_template('account-profile.html',
                           title='Profile',
                           form1=form1,
                           form2=form2)
Пример #25
0
def profile_form_submit(user_id):
    form = ProfileForm()
    form['csrf_token'].data = request.cookies['csrf_token']
    if form.validate_on_submit():
        profile = Profile.query.filter_by(user_id=user_id).first()
        if profile:
            profile.about = form.data['about'],
            profile.first_name = form.data['first_name'],
            profile.last_name = form.data['last_name'],
            profile.phone_number = form.data['phone_number'],
            profile.location = form.data['location'],
            profile.work = form.data['work'],
            profile.language = form.data['language'],
        else:
            profile = Profile(about=form.data['about'],
                              first_name=form.data['first_name'],
                              last_name=form.data['last_name'],
                              phone_number=form.data['phone_number'],
                              location=form.data['location'],
                              work=form.data['work'],
                              language=form.data['language'],
                              user_id=user_id)

        db.session.add(profile)
        db.session.commit()
        return profile.to_dict()
Пример #26
0
def account_settings():
    '''账户设置,包括改密码等'''
    user = current_user
    form = ProfileForm(formdata=request.form, obj=user)
    errors = []
    if form.validate_on_submit():
        username = form['username'].data.strip()
        if username == user.username:
            pass
        elif User.query.filter_by(username=username).all():
            errors.append(
                _("Sorry, the username " + username + " has been taken!"))
        else:
            user.username = username

        user.homepage = form['homepage'].data.strip()
        if not user.homepage.startswith('http'):
            user.homepage = 'http://' + user.homepage
        user.description = form['description'].data.strip()
        if request.files.get('avatar'):
            avatar = request.files['avatar']
            ok, info = handle_upload(avatar, 'image')
            if ok:
                user.set_avatar(resize_avatar(info))
            else:
                errors.append(_("Avatar upload failed"))
        user.save()
    return render_template('settings.html',
                           user=user,
                           form=form,
                           errors=errors)
Пример #27
0
def add_profile():
    """GET provides the profile form while POST stores profile"""
    profileform = ProfileForm()
    if request.method == 'POST' and profileform.validate_on_submit():
        # Get values from form
        fname = request.form['first_name']
        lname = request.form['last_name']
        gender = request.form['gender']
        email = request.form['email']
        location = request.form['location']
        bio = request.form['bio']

        file = profileform.photo.data
        filename = secure_filename(file.filename)
        file.save(os.path.join(path, filename))

        try:
            profile = UserProfile(fname, lname, gender, email, location, bio,
                                  filename)
            db.session.add(profile)
            db.session.commit()
            flash('Profile Saved', 'success')
            return redirect(url_for('view_profiles'))
        except:
            flash("Profile failed to save", 'danger')
    return render_template('add_profile.html', form=profileform)
Пример #28
0
def profile():
    form = ProfileForm()

    if form.validate_on_submit():
        current_user.email = form.email.data
        current_user.telefone = form.telefone.data
        current_user.sobremim = form.sobremim.data
        current_user.registro = form.registro.data
        current_user.ifcomunity = form.ifcomunity.data
        current_user.sobrenome = form.sobrenome.data
        current_user.username = form.username.data
        current_user.base = form.base.data
        current_user.pais = form.pais.data

        db.session.add(current_user)
        db.session.commit()

        flash("dados alterados com sucesso", "success")
        return redirect(url_for(".profile"))

    form.email.data = current_user.email
    form.telefone.data = current_user.telefone
    form.sobremim.data = current_user.sobremim
    form.registro.data = current_user.registro
    form.ifcomunity.data = current_user.ifcomunity
    form.sobrenome.data = current_user.sobrenome
    form.username.data = current_user.username
    form.base.data = current_user.base
    form.pais.data = current_user.pais

    return render_template("user/profile/edit.html", form=form)
Пример #29
0
def profile():
    form = ProfileForm()
    if request.method == "POST" and form.validate_on_submit():
        profilePhoto = form.photo.data
        filename = secure_filename(profilePhoto.filename)
        profilePhoto.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
        newUser = UserProfile(
            # first_name = form.first_name.data,
            # last_name = form.last_name.data,
            # email = form.email.data,
            # location = form.location.data,
            # gender = form.gender.data,
            # biography = form.biography.data,
            # profilePhoto = filename,
            request.form['first_name'],
            request.form['last_name'],
            request.form['email'],
            request.form['location'],
            request.form['gender'],
            request.form['biography'],
            filename,
            created_on=datetime.now().strftime("%B %d, %Y"))
        db.session.add(newUser)
        db.session.commit()
        flash('You have successfully added a new profile.', 'success')
        return redirect(url_for('profiles'))
    return render_template('profile.html', form=form)
Пример #30
0
def profile():
    form = ProfileForm()
    if request.method == 'POST':
        if form.validate_on_submit():
            firstname = form.firstname.data
            lastname = form.lastname.data
            email = form.email.data
            biography = form.biography.data
            location = form.location.data
            gender = form.gender.data

            created_on = format_date_joined()

            photo = form.photo.data
            filename = secure_filename(photo.filename)
            photo.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))

            User = UserProfile(firstname=firstname,
                               lastname=lastname,
                               email=email,
                               location=location,
                               gender=gender,
                               created_on=created_on,
                               filename=filename,
                               biography=biography)
            db.session.add(User)
            db.session.commit()

            flash("User Created Successfully!")
            return redirect(url_for("viewprofiles"))
        else:
            flash_errors(form)

    return render_template('profile.html', form=form)
Пример #31
0
def create_profile():
        form = ProfileForm()
        if request.method == 'POST' and form.validate_on_submit():
            new_data = User.query.get(str(id))
            new_data.email = form.email.data
            db.session.commit()
            return redirect('/index')
        return render_template('create_profile.html', form=form)
Пример #32
0
def account_settings():
    '''账户设置,包括改密码等'''
    user = current_user
    form = ProfileForm(request.form, user)
    if form.validate_on_submit():
        #user.username = form['username'].data
        #user.gender = form['gender'].data
        user.homepage = form['homepage'].data.strip()
        if not user.homepage.startswith('http'):
            user.homepage = 'http://' + user.homepage
        user.description = form['description'].data.strip()
        if request.files.get('avatar'):
            avatar = request.files['avatar']
            ok,info = handle_upload(avatar,'image')
            if ok:
                user.set_avatar(info)
            else:
                errors.append(_("Avatar upload failed"))
        user.save()
    return render_template('settings.html', user=user, form=form)
Пример #33
0
def edit_profile():
    form = ProfileForm()
    if form.validate_on_submit():
        username = form.username.data
        email = form.email.data
        alarm_email = form.alarm_email.data
        try:
            g.user.username = username
            g.user.email = email
            g.user.alarm_email = alarm_email
            db.session.commit()
            return redirect(url_for('index'))

        except (InvalidRequestError, IntegrityError):
            flash('Duplicate username!')
            db.session.rollback()

    form.username.data = g.user.username
    form.email.data = g.user.email
    form.alarm_email.data = g.user.alarm_email
    return render_template('edit_profile.html', form=form)
Пример #34
0
def profile_edit():
    user = User.find_by_id(bson_obj_id(current_user.id))
    if not user:
        abort(404)
    form = ProfileForm()
    if request.method == 'POST':
        if form.validate_on_submit():
            username = form.username.data
            location = form.location.data
            website = form.website.data
            introduction = form.introduction.data
            data = {
                'username': username,
                'location': location,
                'website': website,
                'introduction': introduction
            }

            avatar = request.files['avatar']
            if avatar and AllowFile.is_img(avatar.filename):
                filename = secure_filename(avatar.filename)
                fs = GridFS(mongo.db, collection="avatar")
                avatar_id = fs.put(avatar, content_type=avatar.content_type, filename=filename)
                if avatar_id:
                    if user['avatar']:
                        fs.delete(bson_obj_id(user['avatar']))
                    data['avatar'] = avatar_id
            else:
                flash('图片格式不支持', 'red')

            User.update_user(user['_id'], data)

            return redirect(url_for('.profile'))
        else:
            flash('资料修改失败', 'red')
    return render_template('profile_edit.html', user=user, form=form, title='编辑资料')