Пример #1
0
    def test_passwords_equality_validator(self):
        form = EditProfileForm(first_name='Adam',
                               last_name='Mertz',
                               email='*****@*****.**',
                               password='******',
                               confirm='pass')
        self.assertTrue(form.validate(),
                        'password/confirm must validate to be equal')

        form = EditProfileForm(first_name='Adam',
                               last_name='Mertz',
                               email='*****@*****.**',
                               password='******',
                               confirm='not pass')
        self.assertFalse(form.validate(),
                         'password/confirm must be false when not equal')
Пример #2
0
 def test_email_validator(self):
     form = EditProfileForm(first_name='Adam',
                            last_name='Mertz',
                            email='blah')
     self.assertFalse(
         form.validate(),
         'email should validate it is in the form of an email address')
Пример #3
0
def profile():
    if 'email' not in session:
        return redirect(url_for('login'))
   
    user = User.query.filter_by(email = session['email']).first()

    if user is None:
        return redirect(url_for('login'))
    else:
        form = EditProfileForm()
        if request.method == 'POST':
            if form.validate() == False:
                return render_template('profile.html', form=form, title='profile', user=user)
            elif form.submit.data is True:
                user = User.query.filter_by(email=session['email']).first()
                if len(form.password.data) > 0:
                    user.password = form.password.data
                user.name = form.name.data
                db.session.commit()
	    elif form.verify.data is True:
		token = generate_confirmation_token(session['email'])
                confirm_url = url_for('confirm', token=token, _external=True)
    		html = render_template('confirm.html', confirm_url=confirm_url)
		subject = "Mylink: confirm email"
		send_email(session['email'], subject, html)
		return render_template('verificationsent.html')

            return redirect(url_for('index'))
        user = User.query.filter_by(email=session['email']).first()

        return render_template('profile.html', form=form, title='profile', user=user)
Пример #4
0
def editProfile():
    """
    The '/editProfile' route will direct a logged in user to edit their profile
    """
    if 'username' not in session:
        return redirect(url_for('index'))
    if session['type_of_user'] == 'superuser':
        return redirect(url_for('dashboard_superuser'))
    if session['type_of_user'] == 'applicant':
        return redirect(url_for('dashboard_applicant'))

    form = EditProfileForm()
    username = session['username']
    info = User.get_user_info(username)
    if request.method == 'GET':
        return render_template('editProfile.html', form=form, info=info)
    elif request.method == 'POST':
        if form.email.data != info['email'] and not Applicant.is_unique_email(
                form.email.data):
            flash('Email is taken. Please choose another email')
            return render_template('editProfile.html', form=form, info=info)
        else:
            User.set_email(username, form.email.data)

        if form.validate():
            if len(form.password.data) > 0:
                User.set_password(username, form.password.data)
            User.set_first_name(username, form.first_name.data)
            User.set_last_name(username, form.last_name.data)
            User.set_phone(username, form.phone.data)
            User.set_about(username, form.about.data)
            if len(form.resume.data) > 0:
                User.set_resume(username, form.resume.data)
            if len(form.interests.data) > 0:
                User.set_interests(username, form.interests.data)
            if len(form.portfolio.data) > 0:
                User.set_portfolio(username, form.portfolio.data)
            return redirect(url_for('user', name=username))
        else:
            return render_template('editProfile.html', form=form, info=info)
Пример #5
0
 def test_last_name_required(self):
     form = EditProfileForm(first_name='adam', email='*****@*****.**')
     self.assertFalse(form.validate(), 'last_name must be required')
Пример #6
0
 def test_email_required(self):
     form = EditProfileForm(
         first_name='Adam',
         last_name='Mertz',
     )
     self.assertFalse(form.validate(), 'email should be required')