コード例 #1
0
def profile_page():
    """ обработчик страницы профиля """

    form = ProfileForm()
    session = db_session.create_session()
    profile = session.query(User).filter(User.id == current_user.id).first()

    if request.method == "GET":
        form.email.data = profile.email
        form.surname.data = profile.surname
        form.name.data = profile.name
        form.age.data = profile.age
        form.about.data = profile.about
        form.education.data = profile.education
        form.speciality.data = profile.speciality

    if form.validate_on_submit():
        profile.surname = form.surname.data
        profile.name = form.name.data
        profile.age = form.age.data
        profile.about = form.about.data
        profile.education = form.education.data
        profile.speciality = form.speciality.data
        session.commit()

        if bool(form.avatar.data):
            add_avatar(form.avatar.data, current_user)

    return render_template('profile.html',
                           title='Профиль',
                           form=form,
                           css=url_for('static',
                                       filename='css/profile_style.css'))
コード例 #2
0
ファイル: application.py プロジェクト: pavan15f/pportal
def addProfile():
    pf=ProfileForm()
    if pf.validate_on_submit():
        profileInfo=request.form
        app.logger.info(profileInfo)
        return redirect(url_for(endpoint="home"))
    return render_template("addProfile.html",form=pf)
コード例 #3
0
ファイル: views.py プロジェクト: CapitalD/Taplist
def new_person():
    if not current_user.is_admin:
        return abort(401)
    form = ProfileForm()
    form.location.query = Location.query.order_by('name')
    form.brewery.query = Brewery.query.order_by('name')
    if form.validate_on_submit():
        person = Person(firstname=form.firstname.data,
                        lastname=form.lastname.data,
                        email=form.email.data,
                        password = bcrypt.generate_password_hash(form.password.data),
                        is_admin = form.is_admin.data,
                        is_manager = form.is_manager.data,
                        is_brewer = form.is_brewer.data)
        db.session.add(person)
        db.session.commit()
        if person.is_manager:
            location = Location.query.get(form.location.data.id)
            location.managers.append(person)
            db.session.add(location)
        if person.is_brewer:
            brewery = Brewery.query.get(form.brewery.data.id)
            brewery.brewers.append(person)
            db.session.add(brewery)
        db.session.commit()
        flash("Person added successfully", "success")
        return redirect(url_for("index"))
    if form.errors:
        flash("Changes to profile could not be saved.  Please correct errors and try again.", "error")
    return render_template('new_person.html',
                    title='Add a person',
                    form=form,
                    admin_template=True)
コード例 #4
0
ファイル: views.py プロジェクト: czhangneu/careermedley2
def profile(nickname):
    user = g.user
    print user.nickname
    form = ProfileForm()
    if request.method == 'POST':
        if form.validate_on_submit():
            firstname = form.firstname.data
            lastname = form.lastname.data
            city = form.city.data
            state = form.state.data
            country = form.country.data
            zipcode = form.zipcode.data
            major = form.major.data
            degree = form.degree.data

            account = Account(user.id, firstname, lastname, city, state, country, zipcode, major, degree)
            db.session.add(account)
            db.session.commit()
            return render_template('profile.html',
                           title=nickname,
                           form=form,
                           user=user)
    return render_template('profile.html',
                           title=nickname,
                           form=form,
                           user=user)
コード例 #5
0
ファイル: app.py プロジェクト: kylecao/cloud-pcap
def profile():

    form = ProfileForm()

    if form.validate_on_submit():

        user = User.query.filter_by(username=current_user.username).one()

        user.email = form.email.data

        if form.new_password1.data:
            if user.verify_password(form.current_password.data):
                user.password = form.new_password1.data
            else:
                db.session.commit()
                flash('Current password is not correct.', 'danger')
                return redirect(url_for('profile'))

        db.session.commit()

        flash('Profile changes saved.', 'success')
        return redirect(url_for('profile'))

    else:

        user = User.query.filter_by(username=current_user.username).one()
        
        form.email.data = user.email

        return render_template('profile.html', form=form)
コード例 #6
0
def profile():
    form = ProfileForm()
    if request.method == "POST":
        if form.validate_on_submit():

            # get form data
            firstname = form.firstname.data
            lastname = form.lastname.data
            gender = form.gender.data
            email = form.email.data
            location = form.location.data
            biography = form.biography.data
            file = form.upload.data
            filename = secure_filename(file.filename)
            profile_created_on = datetime.datetime.now()

            new_user = UserProfile(firstname=firstname,
                                   lastname=lastname,
                                   gender=gender,
                                   email=email,
                                   location=location,
                                   biography=biography,
                                   image=filename,
                                   date_joined=profile_created_on)

            db.session.add(new_user)
            db.session.commit()
            file.save(os.path.join(filefolder, filename))
            flash('Successfully added user', 'success')
            return redirect(url_for('profiles'))

    return render_template("profile.html", form=form)
コード例 #7
0
ファイル: views.py プロジェクト: flydrt/Instant-Messaging
def edit_profile():
    form = ProfileForm()
    if form.validate_on_submit():
        current_user.nickname = form.nickname.data
        if form.gender.data == '1':
            current_user.gender = False
        elif form.gender.data == '2':
            current_user.gender = True
        else:
            current_user.gender = None
        current_user.birthday = form.birthday.data
        current_user.signature = form.signature.data
        current_user.introduction = form.introduction.data
        current_user.hometown = form.hometown.data
        current_user.contact_email = form.contact_email.data
        current_user.telephone = form.telephone.data
        db.session.add(current_user)
        db.session.commit()
        flash('Your changes have been save')
        return redirect(url_for('profile'))
    form.nickname.data = current_user.nickname
    if current_user.gender is False:
        form.gender.data = '1'
    elif current_user.gender is True:
        form.gender.data = '2'
    else:
        form.gender.data = '0'
    form.birthday.data = current_user.birthday
    form.signature.data = current_user.signature
    form.introduction.data = current_user.introduction
    form.hometown.data = current_user.hometown
    form.contact_email.data = current_user.contact_email
    form.telephone.data = current_user.telephone
    return render_template('edit_profile.html', form=form)
コード例 #8
0
ファイル: app.py プロジェクト: sichensong-99/Web-Projects
def profile():
    my_form = ProfileForm()  #初始化表单
    my_data = Profile(
    )  #初始化数据,没这行,数据无法放在form中,给该表单提交的数据起名为my_data,即first_name那列数据就叫my_data.first_name
    my_data.remove_none_values()  #call the function
    if my_form.validate_on_submit():  #意思是如果表单提交成功
        my_data.first_name = request.form.get('first_name')
        my_data.last_name = request.form.get('last_name')
        #print("first_name", my_data.first_name)
        #print("last_name", my_data.last_name)
        file = request.files.get('file_photo')
        if file:
            orig_filename = secure_filename(file.filename)
            new_filename = str(uuid.uuid1())  #生成uuid
            my_data.file_photo_filename = orig_filename  #To save the orignal file name
            my_data.file_photo_code = new_filename
            #上面这行是为了存储uuid,目的是如果不同用户上传的不用文件,起了同一个名,靠uuid来区分

            # save to upload folder
            file.save(os.path.join(app.config['UPLOAD_FOLDER'], new_filename))

            #save to database
            db.session.add(my_data)
            db.session.commit()
            print("my_data", my_data.id)

            #redirect to display page
            return redirect('/profile/' +
                            str(my_data.id))  #这个意思是每个数据的特定URL,比如profile/5...

    return render_template("profile.html", my_form=my_form, my_data=my_data)
コード例 #9
0
ファイル: app.py プロジェクト: Em98/easy-Tor-detect
def profile():

    form = ProfileForm()

    if form.validate_on_submit():

        user = User.query.filter_by(username=current_user.username).one()

        user.email = form.email.data

        if form.new_password1.data:
            if user.verify_password(form.current_password.data):
                user.password = form.new_password1.data
            else:
                db.session.commit()
                flash('Current password is not correct.', 'danger')
                return redirect(url_for('profile'))

        db.session.commit()

        flash('Profile changes saved.', 'success')
        return redirect(url_for('profile'))

    else:

        user = User.query.filter_by(username=current_user.username).one()

        form.email.data = user.email

        return render_template('profile.html', form=form)
コード例 #10
0
def addProfile():
    pForm = ProfileForm()
    uFolder = app.config['UPLOAD_FOLDER']
    
    if request.method == "POST" and pForm.validate_on_submit():
        f_name = request.form['f_name']
        l_name = request.form['l_name']
        gender = request.form['gender']
        email = request.form['email']
        location = request.form['location']
        bio = request.form['bio']
        
        image_file = request.files['photo']
        filename = secure_filename(image_file.filename)
        image_file.save(os.path.join(uFolder, filename))
        
        now = datetime.datetime.now()
        joined = "" + format_date_joined(now.year, now.month, now.day)
        
        user = UserProfile(f_name, l_name, gender, email, location, bio, filename, joined)
        
        db.session.add(user)
        db.session.commit()
        
        flash('New profile added!', 'sucess')
        return redirect(url_for('listProfiles'))
    return render_template('profile.html', pForm=pForm) 
コード例 #11
0
def profile():
    formfile = ProfileForm()

    if request.method == "POST":
        if formfile.validate_on_submit():

            firstname = formfile.firstname.data
            lastname = formfile.lastname.data
            gender = formfile.gender.data
            email = formfile.email.data
            location = formfile.location.data
            img = formfile.img.data
            bio = formfile.bio.data
            dateCreated = date_created()

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

            #new user data from form adding to the database paramaters
            newUser = UserProfile(firstname, lastname, email, location, gender,
                                  bio, photo, dateCreated)
            ##Get user information to be added to database
            db.session.add(newUser)
            db.session.commit()

            flash("Profile Created", "Success")
            return redirect(url_for('profiles'))
    # flash_errors(formfile)
    return render_template('profile.html', form=formfile)
コード例 #12
0
def profile_add():
    form = ProfileForm()
    if form.validate_on_submit():
        username = request.form['username']
        id = random.randint(10000000, 99999999)
        firstname = request.form['firstname']
        lastname = request.form['lastname']
        age = request.form['age']
        biography = request.form['biography']
        sex = request.form['sex']
        file = request.file['image']
        image = secure_filename(file.filename)
        file.save = (os.path.join("app/static/image", image))
        joined = datetime.now().strftime('%Y %b %d')
        # return render_template("profile.html", form=form)
        profile = UserProfile(id, username, firstname, lastname, age,
                              biography, sex, image, joined)
        db.session.add(profile)
        db.session.commit()
        flash('user' + 'username' + 'successfully added!' + 'success')
        flash('please log in', 'success')
        return redirect()

    flash_errors(form)
    return render_template('profile.html', form=form)
コード例 #13
0
def profile():
    if current_user.is_authenticated():
        user = current_user
    else:
        user = None

    form = ProfileForm(obj=user)

    if not form.password or form.password == '':
        del form.password

    if form.validate_on_submit():
        if user:
            flash('Successfully updated your profile.')
        else:
            user = User()
            user.role = 1
            flash('Congratulations, you just created an account!')

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

        if not current_user.is_authenticated():
            login_user(user)

        return redirect('/')

    return render_template('demographic.html', form=form)
コード例 #14
0
def profile():
    if current_user.is_authenticated():
        user = current_user
    else:
        user = None
    
    form = ProfileForm(obj=user)

    if not form.password or form.password == '':
        del form.password
    
    if form.validate_on_submit():
        if user:
            flash('Successfully updated your profile.')
        else:
            user = User()
            user.role = 1
            flash('Congratulations, you just created an account!')

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

        if not current_user.is_authenticated():
            login_user(user)

        return redirect('/')

    return render_template('demographic.html', form=form)
コード例 #15
0
ファイル: views.py プロジェクト: chungs1/HackerNet
def edit_profile():
    if request.remote_addr != "127.0.0.1":
        return "UNAUTHORIZED ACCESS ATTEMPT REJECTED"
    form = ProfileForm()
    if form.validate_on_submit():
        if cache.get('ip_dict_valid'):
            cache.set('rerun_setup', True)
            cache.set('ip_dict_valid', True)

        file = request.files['picture']
        file.save(os.path.join(basedir,"app/static/profile.jpg"))

        pickling = {}
        #Get form data here!
        pickling["name"] = form.name.data
        pickling["location"] = form.location.data
        pickling["organization"] = form.organization.data
        pickling["about"] = form.about.data
        pickling["project"] = form.project.data
        pickling["project_description"] = form.project_description.data

        pickle.dump(pickling, open('pickledUser.p', 'wb'))
        
        #form.picture.save(filename)
        return redirect(url_for('profile'))
        
    #Get cpickle stuff here
    return render_template('edit_profile.html', form=form)
コード例 #16
0
def profile():
    profileForm = ProfileForm()

    if request.method == 'POST' and profileForm.validate_on_submit():
        firstname = profileForm.firstname.data
        lastname = profileForm.lastname.data
        email = profileForm.email.data
        location = profileForm.location.data
        gender = profileForm.gender.data
        bio = profileForm.biography.data

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

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

        user = UserProfile(firstname, lastname, email, location, gender, bio,
                           imageName, created_on)
        db.session.add(user)
        db.session.commit()

        flash('Profile Successfully Added', 'success')
        return redirect(url_for("profiles"))
    flash_errors(profileForm)
    return render_template('profile.html', form=profileForm)
コード例 #17
0
ファイル: views.py プロジェクト: jodidari/info3180-project1
def 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.bio.data
        print biography
        #image=form.upload.data
        now = str(datetime.date.today())

        image = request.files['photo']
        if allowed_file(image.filename):
            filename = secure_filename(image.filename)
            image.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
        else:
            flash('Incorrect File Format', 'danger')
            return redirect(url_for('profile'))

        user = UserProfile(firstname, lastname, gender, email, location,
                           biography, filename, now)
        db.session.add(user)
        db.session.commit()
        flash('File Saved', 'success')
        return redirect(url_for('profiles'))
    return render_template("profile.html", form=form)
コード例 #18
0
def addProfile():
    form = ProfileForm()

    if request.method == 'POST' and form.validate_on_submit():
        fname = request.form['fname']
        lname = request.form['lname']
        gender = request.form['gender']
        email = request.form['email']
        location = request.form['location']
        bio = request.form['bio']
        images = app.config["UPLOAD_FOLDER"]
        image = request.files['photo']

        image_name = secure_filename(image.filename)
        image.save(os.path.join(images, image_name))

        while True:
            userid = random.randint(1, 9999999)
            result = UserProfile.query.filter_by(userid=userid).first()
            if result is None:
                break

        created_on = time.strftime("%d %b %Y")
        new_profile = UserProfile(fname, lname, gender, email, location, bio,
                                  image_name, userid, created_on)
        db.session.add(new_profile)
        db.session.commit()
        flash('New profile sucessfully added', 'success')
        return redirect(url_for('profiles'))
    return render_template('addProfile.html', form=form)
コード例 #19
0
def about():
    viewprofile1 = viewprofile(request.args.get('username'))
    form = ProfileForm()
    if request.method == 'POST' and form.validate_on_submit():
        db = get_db()
        username = request.args.get('username')
        c = db.execute('select * from userprofile where username=?',
                       (username, ))
        userexists = c.fetchone()
        if userexists:
            print("I'AM HERE", username, form.firstname.data,
                  form.lastname.data, form.city.data, form.state.data,
                  form.country.data, form.zipcode.data, form.degreename.data,
                  form.studyfield.data, form.school.data, type(form.gpa.data))
            c1 = db.execute(
                '''UPDATE userprofile SET firstname=? , lastname=? , city=? , state=? , country=? , zipcode=? , degreename=? , studyfield=? , school=? , gpa=? , exp1=?,resume1=?,skillset=? WHERE username=?''',
                [
                    form.firstname.data, form.lastname.data, form.city.data,
                    form.state.data, form.country.data, form.zipcode.data,
                    form.degreename.data, form.studyfield.data,
                    form.school.data,
                    float(form.gpa.data), form.exp.data, form.resume.data,
                    form.skillset.data, username
                ])
            db.commit()
        else:
            c1 = db.execute(
                'INSERT INTO userprofile(username,firstname,lastname,city,state,country,zipcode,degreename,studyfield,school,gpa,exp1,resume1,skillset) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)',
                [
                    username, form.firstname.data, form.lastname.data,
                    form.city.data, form.state.data, form.country.data,
                    form.zipcode.data, form.degreename.data,
                    form.studyfield.data, form.school.data,
                    float(form.gpa.data), form.exp.data, form.resume.data,
                    form.skillset.data
                ])
            db.commit()
        return redirect(url_for('about',
                                username=request.args.get('username')))
    elif request.method == 'GET' and viewprofile1 != "":

        form.firstname.data = str(viewprofile1['First name'])
        form.lastname.data = str(viewprofile1['Last name'])
        form.city.data = str(viewprofile1['City'])
        form.state.data = str(viewprofile1['State'])
        form.country.data = str(viewprofile1['Country'])
        form.zipcode.data = int(viewprofile1['Zip code'])
        form.degreename.data = str(viewprofile1['Highest Level of Education'])
        form.studyfield.data = str(viewprofile1['Field of Study'])
        form.school.data = str(viewprofile1['School or University'])
        form.gpa.data = float(viewprofile1['Overall Result(GPA)'])
        form.exp.data = int(viewprofile1['Total relevant years of Experience'])
        form.resume.data = str(viewprofile1['Resume Information'])
        form.skillset.data = str(viewprofile1['Skill Set'])
    return render_template('about.html',
                           title='About',
                           viewprofile1=viewprofile1,
                           keys=request.args.get('username'),
                           form=form)
コード例 #20
0
def profile():
    form = ProfileForm()
    if form.validate_on_submit():
        flash(
            f'Hi {form.firstname.data}, your information was updated successfully.',
            'success')

    return render_template('user-profile.html', form=form)
コード例 #21
0
def edit_profile():
    # obj allows all user-info get into the form
    form = ProfileForm(current_user, obj=current_user)
    if form.validate_on_submit():
        form.populate_obj(current_user)
        db.session.add(current_user)
        db.session.commit()
        flash('Personal Information has been updated', 'success')
        return redirect(url_for('.index', name=current_user.name))
    return render_template('user/edit_profile.html', form=form)
コード例 #22
0
def profile():
    user = User.query.filter_by(email=current_user.email).first_or_404()
    form = ProfileForm(obj=user)

    if request.method == 'POST':
        if form.validate_on_submit():
            user.save()
            flash('Profile updated.', 'success')

    return render_template('user/profile.html', user=user, form=form)
コード例 #23
0
def profile():
    #form instance
    form = ProfileForm()
    #model instance
    data = Profile()
    #print("sucess")
 
    if form.validate_on_submit():
        data.first_name = request.form.get('first_name')
        data.last_name = request.form.get('last_name')
        data.email =  request.form.get('email')
        data.password = request.form.get('password')
        data.check_box = request.form.get('check_list')
        data.radio = request.form.get('radio1')
        data.city = request.form.get('city')
        data.state = request.form.get('state')
        data.zipcode = request.form.get('zipcode')
        data.date = request.form.get('choose_date')
        data.address = request.form.get('address')
        data.date_range = request.form.get('my_date_range')
        data.time =  request.form.get('time_picker')
        data.slider_value =  request.form.get('slider_value')
        data.list_to_string(request.form.getlist('multiple_states'))
        data.like_level = request.form.get('multiple_options')
        #print("data.check_box", data.check_box)
        #print("data.date_range", data.date_range) 
        #print("data.time", data.time)
        #print("data.slider_value", data.slider_value)
        #print("data.multiselect", data.multiselect)
        #print("data.like_level", data.like_level)
        #test fetch data from the form successfully

        # process file
        file = request.files.get('file_photo')
        #print("filename", file.filename)
        if file:
            orig_filename = secure_filename(file.filename)
            new_filename = str(uuid.uuid1())
            data.file_photo_filename = orig_filename
            data.file_photo_code = new_filename
            #rint("data.file_photo_filename", data.file_photo_filename)
            #print("data.file_photo_code", data.file_photo_code)
            


            #save the local file system
            file.save(os.path.join(app.config['UPLOAD_FOLDER'], new_filename))

            # save to database
            db.session.add(data)
            db.session.commit()
            #print("data", data.id)
            return redirect('/profile/' + str(data.id)) 
    
    return render_template('profile.html', title = 'Profile', form = form) # customize the title
コード例 #24
0
def add_profile():
    """ Render a page for adding a user profile """

    # Generate form
    form = ProfileForm()
    # Check request type
    if request.method == "POST":
        # Validate form
        if form.validate_on_submit():
            # Get form values
            first_name = request.form['firstname']
            last_name = request.form['lastname']
            username = request.form['username']
            age = request.form['age']
            biography = request.form['biography']
            gender = request.form['gender']
            # Uploads folder
            imageFolder = app.config["UPLOAD_FOLDER"]
            # Get picture file
            imageFile = request.files['image']
            # Check if empty
            if imageFile.filename == '':
                # Store default profile pic in DB
                imageName = "profile-default.gif"
            else:
                # Secure file
                imageName = secure_filename(imageFile.filename)
                # Save to uploads directory
                imageFile.save(os.path.join(imageFolder, imageName))
            # Loop to find a unique id
            while True:
                # Generate a random userid
                userid = random.randint(620000000, 620099999)
                # Search for this userid
                result = UserProfile.query.filter_by(userid=userid).first()
                # Check if not found
                if result is None:
                    # Unique; Exit loop
                    break
            # Generate the date the user was created on
            created_on = timeinfo()
            # Store data in database
            profile = UserProfile(userid, first_name, last_name, username, age,
                                  gender, biography, imageName, created_on)
            db.session.add(profile)
            db.session.commit()
            # Flash success message
            flash('New user profile sucessfully added', 'success')
            # Redirect to list of profiles
            return redirect(url_for('list_profiles'))

    # Display any errors in form
    flash_errors(form)

    return render_template('add_profile.html', form=form)
コード例 #25
0
ファイル: app.py プロジェクト: spandana1234/projectmain
def firstfill():
    form2 = ProfileForm()
    form = ResetpassForm()
    if form2.validate_on_submit():
        if request.method == 'POST':
            result = request.form
            values = list(result.values())
            addresstoverify = values[3]
            s1 = values[1]
            s2 = values[2]
            match2 = re.match("^[A-z][A-z|\.|\s]+$", s1)
            match3 = re.match("^[A-z][A-z|\.|\s]+$", s2)
            match1 = re.match('^[_a-z0-9-]+(\.[_a-z0-9-]+)*@enquero.com$',
                              addresstoverify)
            if match1 == None:
                flash('Incorrect email address', 'danger')
                return redirect(url_for('firstfill'))
            elif match2 == None:
                flash('Incorrect First Name', 'danger')
                return redirect(url_for('firstfill'))
            elif match3 == None:
                flash('Incorrect Last Name', 'danger')
                return redirect(url_for('firstfill'))

            else:
                global a, mng, results1
                cursor = connection1.cursor()
                select = ("SELECT * FROM profile WHERE empid='" + a + "'")
                cursor.execute(select)
                results = cursor.fetchone()

                if results == None:
                    cursor = connection1.cursor()
                    insert = (
                        "INSERT INTO profile (fname,lname,email,experience,practice,ejoindate,currentpro,location,gender,ques,ans,empid) VALUES(?,?,?,?,?,?,?,?,?,?,?,?)"
                    )

                    values = [
                        values[1], values[2], values[3], values[8], values[9],
                        values[5], values[6], values[7], values[4], values[10],
                        values[11], a
                    ]
                    cursor.execute(insert, values)
                    connection1.commit()
                cursor.execute("SELECT * FROM profile WHERE empid='" + a + "'")
                results1 = cursor.fetchone()
                if mng != None:
                    return redirect(url_for('skills'))
                else:
                    return redirect(url_for('skills1'))
    return render_template('profile.html',
                           form2=form2,
                           form=form,
                           mng=mng,
                           open=False)
コード例 #26
0
ファイル: views.py プロジェクト: Weilor/poetbrain
def modify_profile():
    if not current_user.confirmed:
        return render_template('auth/user_confirm.html', confirmed=False)
    form = ProfileForm()
    if form.validate_on_submit():
        current_user.location = form.location.data
        current_user.about_me = form.about_me.data
        db.session.add(current_user)
        return redirect(url_for("main.user_page", username=current_user.username))
    form.about_me.data = current_user.about_me
    form.location.data = current_user.location
    return render_template('modify_profile.html', form=form, user=current_user)
コード例 #27
0
def profile():
    form = ProfileForm(obj=current_user)

    if form.validate_on_submit():
        form.populate_obj(user)
        user.update_at = get_current_time()

        db.session.commit()

        flash('Public profile updated.', 'success')

    return render_template('user/profile.html', form=form)
コード例 #28
0
ファイル: views.py プロジェクト: LoyiLY/fbone
def profile():
    form = ProfileForm(obj=current_user)

    if form.validate_on_submit():
        form.populate_obj(user)
        user.update_at = get_current_time()

        db.session.commit()

        flash('Public profile updated.', 'success')

    return render_template('user/profile.html', form=form)
コード例 #29
0
ファイル: views.py プロジェクト: kafeinnet/kafeinnet-blog
def users(current = -1):
    if current >= 0:
        users = User.query.all()
        user = User.query.filter(User.user_id == current).first()
        profileform = ProfileForm(obj=user)

        if request.method == 'POST' and profileform.validate_on_submit():
            if profileform.delete.data:
                user.deleted = True

            else:
                if profileform.undelete.data:
                    user.deleted = False

                user.fullname = profileform.fullname.data

                if profileform.password.data:
                    user.password = bcrypt.generate_password_hash(profileform.password.data)

            db.session.commit()
            return redirect('/users/edit/' + str(current))

        return render_custom_template('users.html', users=users, profileform=profileform, current=current)
    else:
        users = User.query.all()
        profileform = ProfileForm()

        if request.method == 'POST' and profileform.validate_on_submit():
            user = User(
                -1,
                profileform.username.data,
                bcrypt.generate_password_hash(profileform.password.data),
                profileform.fullname.data
            )
            db.session.add(user)
            db.session.commit()
            return redirect('/users')

        return render_custom_template('users.html', users=users, profileform=profileform, current=current)
コード例 #30
0
ファイル: views.py プロジェクト: julesbello/nyuadtube
def profile():
		form = ProfileForm()
		user = g.user	
		if form.validate_on_submit():
				user.facebook = form.facebook.data if len(form.facebook.data) > 2 else "null"
				user.nickname = form.username.data if len(form.username.data) > 2 else user.nickname
				db.session.commit()
				flash("Profile updated successfully.")
				return redirect(url_for('index'))
		return render_template('profile.html',
		title= 'Profile',
		form = form,
		user = user)
コード例 #31
0
ファイル: flaskr.py プロジェクト: Jianwei-Wang/my-flaskr
def edit_profile():
    form = ProfileForm()
    if form.validate_on_submit():
        current_user.real_name = form.real_name.data
        current_user.location = form.location.data
        current_user.about_me = form.about_me.data
        db.session.add(current_user)
        db.session.commit()
        flash('Your profile has been updated.')
        return redirect(url_for('main.user', username=current_user.name))
    form.real_name.data = current_user.real_name
    form.location.data = current_user.location
    form.about_me.data = current_user.about_me
    return render_template('edit_profile.html', form=form)
コード例 #32
0
ファイル: views.py プロジェクト: itucsdb1973/itucsdb1973
def edit_profile():
    user = get_user(current_user.id)
    form = ProfileForm(request.form, bio=user.bio, email=user.email)
    if form.validate_on_submit():
        user.bio = form.data["bio"]
        user.email = form.data["email"]
        db = current_app.config["db"]
        try:
            db.update_items(user, id=current_user.id)
        except NotUniqueError:
            form.email.errors.append("email address already in use")
        else:
            return redirect(url_for("profile"))
    return render_template("edit_profile_page.html", form=form)
コード例 #33
0
ファイル: flaskr.py プロジェクト: Jianwei-Wang/my-flaskr
def edit_profile():
    form = ProfileForm()
    if form.validate_on_submit():
	current_user.real_name = form.real_name.data
        current_user.location = form.location.data
        current_user.about_me = form.about_me.data
	db.session.add(current_user)
	db.session.commit()
	flash('Your profile has been updated.')
	return redirect(url_for('main.user', username = current_user.name))
    form.real_name.data = current_user.real_name
    form.location.data = current_user.location
    form.about_me.data = current_user.about_me
    return render_template('edit_profile.html', form = form)
コード例 #34
0
def profile():

    if not current_user.is_authenticated:
        return redirect(url_for('signup'))

    form = ProfileForm()
    if form.validate_on_submit():
        user = current_user
        print(user)
        user.name = form.name.data
        user.last_name = form.last_name.data

        db.session.commit()
        flash('Edit user')
    return render_template('profile.html', form=form)
コード例 #35
0
def profile():
    if current_user.is_authenticated == False:
        return redirect(url_for('core.home'))
    form = ProfileForm(obj=current_user)
    if form.validate_on_submit():
        user = User.query.filter_by(id=current_user.id).first()
        user.first_name = form.first_name.data
        user.last_name = form.last_name.data
        user.email_notifications = form.email_notifications.data
        user.text_notifications = form.text_notifications.data
        user.profile_complete = True
        db.session.commit()
        flash('Your details have been updated')
        return render_template('user/profile.html', title='Profile', form=form)
    return render_template('user/profile.html', title='Profile', form=form)
コード例 #36
0
ファイル: app.py プロジェクト: stevensadh95/gym-webapp
def register():
    form = SignupForm()

    profile = ProfileForm()

    if request.method == 'GET':
        return render_template("sign_up.html", form=form, profile=profile)
    if request.method == 'POST':

        if profile.validate_on_submit():

            connection = sqlite3.connect('gymder.db')
            cursor = connection.cursor()

            if cursor.execute("SELECT * FROM user WHERE username='******'".format(
                    profile.username.data)).fetchall():
                flash("Username Already Exists", "danger")
                return redirect(url_for("register"))

            filename = profile.picture.data.filename

            profile.picture.data.save('static/uploads/' + filename)

            path = 'static/uploads/' + filename
            user_profile = Profile(profile.username.data, profile.name.data,
                                   profile.email.data, profile.state.data,
                                   profile.sex.data, profile.birthday.data,
                                   path, profile.bio.data)
            add_user(cursor, user_profile)

            connection.commit()

        if form.validate_on_submit():
            if User.query.filter_by(username=form.username.data).first():
                flash("User Already Exists", "danger")
                return redirect(url_for("register"))
            else:
                new_user = User(form.username.data, form.password.data)
                db.session.add(new_user)
                db.session.commit()
                login_user(new_user)

                flash("Registered successfully", "info")
                return redirect(url_for("index"))

        else:
            flash("Form didn't validate", "danger")
            return redirect(url_for(register))
コード例 #37
0
def profile():
    form = ProfileForm()
    if not session.get("USERNAME") is None:
        if form.validate_on_submit():
            cv_dir = Config.CV_UPLOAD_DIR
            file_obj = form.cv.data
            cv_filename = session.get("USERNAME") + '_CV.pdf'
            file_obj.save(os.path.join(cv_dir, cv_filename))
            flash('CV uploaded and saved')
            return redirect(url_for('index'))
        return render_template('profile.html',
                               title='Add/Modify your profile',
                               form=form)
    else:
        flash("User needs to either login or signup first")
        return redirect(url_for('login'))
コード例 #38
0
ファイル: views.py プロジェクト: czhangneu/careermedley
def user(nickname):
    print(request.args.get("jobkey"))
    user = g.user
    account = Account.query.filter_by(id=user.id).first()
    print "are we here? account: %s" % account
    if account is None:
        form = ProfileForm()
        if request.method == 'POST' and form.validate_on_submit():
            print "yes we got here....user.id: %s, user.email: %s" % (user.id, user.email)
            firstname = form.firstname.data
            lastname = form.lastname.data
            city = form.city.data
            state = form.state.data
            country = form.country.data
            zipcode = form.zipcode.data
            major = form.major.data
            degree = form.degree.data
            account = Account(id=user.id, firstname=firstname, lastname=lastname,
                        city=city, state=state, country=country, zipcode=zipcode,
                        major=major, degree=degree)
            print " account: %s" % account
            db.session.add(account)
            db.session.commit()
            jobForm = JobSearchForm()
            return render_template('user.html',
                                   nickname=nickname,
                                   user=user,
                                   form=jobForm)
        return render_template('profile.html', nickname=nickname,
                               user=user,
                               form=form)
    else:
        jobForm = JobSearchForm()
        if request.method == 'POST':
            if jobForm.validate_on_submit():
                getJobs = ProcessJobSearch()
                jobs = getJobs.job_search(jobForm.job.data, jobForm.location.data)
                for i in range(len(jobs)):
                    print "range (%d: %s)" % (i, jobs[i])
                    print '*' * 100
                return render_template('user.html',
                                       title='CareerMedley',
                                       form=jobForm, user=user, jobs=jobs)
    return render_template('user.html',
                           title=nickname,
                           form=jobForm,
                           user=user)
コード例 #39
0
ファイル: views.py プロジェクト: 0shanAbry1/info3180-project1
def add_profile():
    """Renders the profile form to add a new user"""
    form = ProfileForm() #Instance of the form
    
    if(request.method == 'POST'): #Handles POST requests
        if form.validate_on_submit(): #Form is valid
            # Retrieve form data
            firstname = request.form['firstname']
            lastname = request.form['lastname']
            username = request.form['username']
            age = request.form['age']
            biography = request.form['biography']
            gender = request.form['gender']
            
            imageFolder = app.config["UPLOAD_FOLDER"]
            imageFile = request.files['image']
            
            #Determines the file name of the image
            if(imageFile.filename == ''):
                imageName = "default-profilePicture.jpg"
            else:
                imageName = secure_filename(imageFile.filename)
                imageFile.save(os.path.join(imageFolder, imageName))
            
            while True:
                userid = random.randint(7000000,7999999) #Generates a random id for the user
                userid_data = UserProfile.query.filter_by(userid=userid).first()
                
                if userid_data is None: #Genereated userid is unique
                    break
                
            created_on = timeinfo() #Retrieves today's date
                
            entry = UserProfile(userid, firstname, lastname, username, age, gender, biography, imageName, created_on)
            db.session.add(entry)
            db.session.commit()
                
            flash('New profile for user added successfully :)', 'success')
                
            # return redirect(url_for('view_profile', userid=userid))
            # return redirect('/profile/' + userid)
            return redirect(url_for('list_profiles'))
    
    flash_errors(form)
    
    #Default >> GET Request
    return render_template('add_profile.html', form=form)
コード例 #40
0
def newProfile():
    form = ProfileForm()

    if request.method == 'GET':
        return render_template('signup.html', form=form)
    elif request.method == 'POST':
        if form.validate_on_submit():
            first_name = form.first_name.data
            last_name = form.last_name.data
            user_name = form.user_name.data
            password = form.password.data
            gender = form.gender.data
            email = form.email.data
            role = form.role.data

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

            uid = generateUserId(first_name, last_name)

            #Remember to add an Admin Account
            newUser = UserProfile(uid=uid,
                                  isAdmin=isAdmin,
                                  first_name=first_name,
                                  last_name=last_name,
                                  user_name=user_name,
                                  password=password,
                                  gender=gender,
                                  email=email,
                                  role=role,
                                  image=filename)

            db.session.add(newUser)
            db.session.commit()

            if current_user.is_authenticated and current_user.isAdmin == "yes":
                active = "active"
            else:
                active = "notactive"

            flash("Profile Successfully Created", "success")
            return redirect(
                url_for("profiles")
            )  ##########  #url_for('profile', uid=user.uid) use this just in case.
        return render_template('signup.html', form=form, active=active)
コード例 #41
0
ファイル: views.py プロジェクト: kafeinnet/kafeinnet-blog
def profile():
    user = User.query.filter(User.user_id == current_user.user_id).first()

    profileform = ProfileForm(obj=user)

    if request.method == 'POST' and profileform.validate_on_submit():
        user.fullname = profileform.fullname.data

        if profileform.password.data:
            user.password = bcrypt.generate_password_hash(profileform.password.data)

        db.session.commit()
        #login_user(User(user.user_id, user.username, user.password))

        return redirect('/profile')
    else:
        return render_custom_template('profile.html', profileform=profileform)
コード例 #42
0
ファイル: dash.py プロジェクト: jackij/FPWeb
def profile():
  page = request.environ.get('PAGE', {})
  page['user'] = current_user
  page['db'] = db
  form_content = page['form_content']

  if request.method == 'POST':
    form = ProfileForm()
    if form.validate_on_submit():
      print 'Whooo!!'
    else:
      print 'Booo!!'
    form_content = str(form)

  html = str(base(**page))
  html = html.format(form_content=page['form_content'])
  return html
コード例 #43
0
ファイル: views.py プロジェクト: CapitalD/Taplist
def edit_profile(id):
    if not current_user.is_admin and not current_user.id == id:
        abort(401)
    form = ProfileForm()
    form.location.query = Location.query.order_by('name')
    form.brewery.query = Brewery.query.order_by('name')
    if form.validate_on_submit():
        person = Person.query.get_or_404(id)
        person.firstname = form.firstname.data
        person.lastname = form.lastname.data
        person.email = form.email.data
        if len(form.password.data) > 0:
            person.password = bcrypt.generate_password_hash(form.password.data)
        if current_user.is_admin:
            person.is_admin = form.is_admin.data
            person.is_manager = form.is_manager.data
            person.is_brewer = form.is_brewer.data
        db.session.add(person)
        db.session.commit()
        if person.is_manager:
            location = Location.query.get(form.location.data.id)
            location.managers.append(person)
            db.session.add(location)
            db.session.commit()
        if person.is_brewer:
            brewery = Brewery.query.get(form.brewery.data.id)
            brewery.brewers.append(person)
            db.session.add(brewery)
            db.session.commit()
        flash("Profile edited successfully", "success")
        return redirect(url_for("index"))
    person = Person.query.get_or_404(id)
    form.firstname.data = person.firstname
    form.lastname.data = person.lastname
    form.email.data = person.email
    if person.is_manager:
        form.location.data = person.locations[0]
    if person.is_brewer:
        form.brewery.data = person.breweries[0]
    if form.errors:
        flash("Changes to profile could not be saved.  Please correct errors and try again.", "error")
    return render_template('edit_profile.html',
                            title='Edit profile',
                            person=person,
                            form=form,
                            admin_template=True)
コード例 #44
0
def profile():
    form = ProfileForm(username=current_user.name, email=current_user.email)

    if form.validate_on_submit():
        current_user.name = form.username.data
        current_user.email = form.email.data
        for room in user_get_rooms(current_user):
            if room.is_group:
                room.chats[0].message = ", ".join(
                    member.name for member in room_get_members(room))
            else:
                for assoc in room.members:
                    if not assoc.member == current_user:
                        assoc.room_name = current_user.name
        db.session.commit()
        flash("Save changed successfully.")
    return render_template("chat/profile.html", form=form)
コード例 #45
0
ファイル: app.py プロジェクト: packetpounder/donkey
def profile():

    form = ProfileForm()

    if form.validate_on_submit():

        user = User.query.filter_by(username=current_user.username).one()

        user.email = form.email.data

        if form.new_password1.data:
            if user.verify_password(form.current_password.data):
                user.password = form.new_password1.data
            else:
                db.session.commit()
                flash('Current password is not correct.', 'danger')
                return redirect(url_for('profile'))

        db.session.commit()

        flash('Profile changes saved.', 'success')
        return redirect(url_for('profile'))

    else:

        user = User.query.filter_by(username=current_user.username).one()
        
        photos = Photo.query.filter_by(user_id=user.id).order_by(desc(Photo.vote_value)).all()

        votes = {}

        for photo in photos:
            temp_votes = Vote.query.filter_by(photo_id=photo.id).all()
            votes[photo.id] = {'up': 0, 'down': 0}
            for vote in temp_votes:
                if vote.value > 0:
                    votes[photo.id]['up'] += 1
                else:
                    votes[photo.id]['down'] += 1

            votes[photo.id]['total'] = votes[photo.id]['up'] - votes[photo.id]['down']

        form.email.data = user.email

        return render_template('profile.html', form=form, photos=photos, votes=votes)
コード例 #46
0
ファイル: views.py プロジェクト: czhangneu/careermedley
def profile(nickname):
    user = g.user
    form = ProfileForm()
    if request.method == 'POST':
        if form.validate_on_submit():
            firstname = form.firstname.data
            lastname = form.lastname.data
            city = form.city.data
            state = form.state.data
            country = form.country.data
            zipcode = form.zipcode.data
            major = form.major.data
            degree = form.degree.data

    return render_template('profile.html',
                           title=nickname,
                           form=form,
                           user=user)
コード例 #47
0
ファイル: views.py プロジェクト: SebastianMerz/together
def profile():
  """
  Use this to let people change emails and phone numbers
  """
  if g.user is None:
    return redirect(url_for("index"))

  form = ProfileForm()
  if form.validate_on_submit():
    user = models.User.query.get(g.user['id'])
    user.email = form.email.data
    user.phone_number = form.phone_number.data
    print form.email.data
    print form.phone_number.data
    g.user['email'] = form.email.data
    g.user['phone_number'] = form.phone_number.data
    db.session.add(user)
    db.session.commit()
    flash('Your changes have been saved')
  return render_template("profile.html", app_id=FB_APP_ID, name=FB_APP_NAME, user = g.user, form=form)
コード例 #48
0
ファイル: clover.py プロジェクト: steve-fan/clover
def settings():
    form = ProfileForm()

    if form.validate_on_submit():

        g.user.update({
            'username': form.username.data,
            'email': form.email.data,
            'about': form.about.data,
            'city': form.city.data,
            'website': form.website.data})

        current_app.logger.info('user: %s'%g.user)

        if g.user['email']:
            current_app.redis.set('email:%s:uid'%g.user['email'], g.user['id'])

        current_app.redis.hmset('user:%s'%g.user['id'], g.user)
        return redirect(url_for('.feed'))

    return render_template('settings.html', form=form)
コード例 #49
0
ファイル: views.py プロジェクト: antbla/info3180-project1
def profile():
    form = ProfileForm()

    if request.method == 'POST':
        if form.validate_on_submit():
            username = form.username.data

            if not User.query.filter_by(username=username).first():
                user = User(username=username,
                            first_name=form.first_name.data,
                            last_name=form.last_name.data,
                            age=form.age.data)

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

                uploaded_file = request.files['image']
                if uploaded_file and allowed_file(uploaded_file.filename):
                    filename = 'user_profile_{0}.{1}'.format(
                        user.user_id, uploaded_file.filename.split('.')[-1]
                    )
                    uploaded_file.save(os.path.join(app.config['UPLOAD_FOLDER'],
                                                    filename))
                    user.image = filename
                    db.session.commit()

                    return redirect(url_for('profiles'))

            # User already exist. Can't create
            flash(u"User with username %s already exist" % username)

        for field, errors in form.errors.items():
            for error in errors:
                flash(u"Error in the %s field - %s" % (
                    getattr(form, field).label.text,
                    error
                ))

    return render_template('profile_form.html', form=form)
コード例 #50
0
ファイル: views.py プロジェクト: slam1108/myFacebook
def profile():
	form = ProfileForm()
	#print 'f**k'
	if form.validate_on_submit():
		if request.method == 'POST':
			file = request.files['file']
			#print file
			if file and allowed_file(file.filename):
				filename = secure_filename(file.filename)
				#print 'filename'+filename
				file.save(os.path.join(IMAGE_SRC, filename))
				#path = '/static/'+filename
				#print 'path'+path
				db.session.query(User).filter_by(uid=g.user.uid).update({"pic":filename})
				db.session.commit()
				#print '#######################'+g.user.pic
				return redirect(url_for('profile'))
			else:
				db.session.query(User).filter_by(uid=g.user.uid).update({"pic":''})
				db.session.commit()
				return redirect(url_for('profile'))

	return render_template('profile.html', user=g.user, form=form)
コード例 #51
0
ファイル: views.py プロジェクト: mfa/weight-app
def profile():
    from models import User, Scale
    u1 = User.query.get(current_user._user)
    form = ProfileForm(obj=u1)

    form.default_scale.choices = [(g.name, g.name) 
                                  for g in Scale.query.order_by('name')]
    form.default_scale.choices.insert(0, ("", "Select..."))

    if form.validate_on_submit():

        if 'firstname' in request.form:
            u1.firstname = request.form['firstname']

        if 'lastname' in request.form:
            u1.lastname = request.form['lastname']

        if 'email' in request.form:
            u1.email = request.form['email']

        if 'password' in request.form:
            u1.set_password(request.form['password'])

        if 'default_scale' in request.form:
            u1.default_scale_name = request.form['default_scale']

        db.session.add(u1)
        db.session.commit()
        flash('Data saved', 'info')

    if u1.default_scale_name:
        form.default_scale.data = u1.default_scale_name


    return render_template('profile.html',
                           form=form)