Ejemplo n.º 1
0
def welcome_page(token):
    # return user to home page if they are already logged in
    if current_user.is_authenticated:
        return redirect(url_for('main.home'))
    # check that the token is correct, and not expired
    guest = Users.verify_reset_token(token)
    form = RSVPForm()
    if guest is None:
        flash(
            'The link you were sent is either invalid or has expired. Please contact Kirk.',
            'danger')
        return redirect(url_for('main.home'))
    else:
        # update user record in db to reflect their RSVP form values
        if form.validate_on_submit():
            guest.rsvp = True
            guest.is_attending = form.is_attending.data
            guest.password = bcrypt.generate_password_hash(
                form.password.data).decode('utf-8')
            db.session.commit()
            login_user(guest)
            return redirect(url_for('main.home'))
        return render_template('welcome.html',
                               title="Welcome To Our Wedding",
                               form=form,
                               guest=guest)
Ejemplo n.º 2
0
def register():
    if current_user.is_authenticated:
        abort(400)
    data = request.get_json()

    if not data or not 'password' in data or not 'username' in data or not 'first_name' in data \
            or not 'last_name' in data or not 'gender' in data or not 'birth_date' in data or not 'email' in data:
        abort(400)
    check_user = User.query.filter_by(email=data['email']).first()
    if check_user:
        return 'Email Taken'
    check_user = User.query.filter_by(username=data['username']).first()
    if check_user:
        return 'Username Taken'
    hashed_password = bcrypt.generate_password_hash(
        data['password']).decode('utf-8')
    user = User(username=data['username'],
                first_name=data['first_name'],
                last_name=data['last_name'],
                gender=data['gender'],
                birth_date=datetime.datetime.now(),
                email=data['email'],
                password=hashed_password)
    db.session.add(user)
    db.session.commit()
    return 'Created'
Ejemplo n.º 3
0
def add_guests():
    # page restricted to admins. Redirect is user is not an admin (bride/groom)
    if current_user.guest_type != 'Admin':
        return redirect(url_for('main.home'))
    else:
        # generate and render AddGuestForm
        form = AddGuestForm()
        # if form alidated successfully, add form values to database as a new guest
        if form.validate_on_submit():
            # generate a random encrypted password for the guest
            password = bcrypt.generate_password_hash(
                secrets.token_hex(8)).decode('utf-8')
            # additional guests form field is rendered as a string, below converts it to an integer
            additional_guests_int = int(form.additional_guests.data)
            user = Users(
                name=form.name.data,
                email=form.email.data,
                password=password,
                additional_guests=additional_guests_int,
                additional_guest_names=form.additional_guest_names.data,
                guest_type=form.guest_type.data,
                language=form.language.data)
            db.session.add(user)
            db.session.commit()
            flash(f'{form.name.data} has been added to the guest list.',
                  'success')
            return redirect(url_for('admin.dashboard'))
        elif request.method == 'GET':
            # prepopulate phone number form field with '+44'
            form.number.data = '+44'
        return render_template('add_guests.html',
                               title='Add Guests',
                               form=form)
Ejemplo n.º 4
0
def register():
	if current_user.is_authenticated:
		return redirect(url_for('home'))
	form = RegistrationForm()
	if form.validate_on_submit():
		session['email_id']=form.email.data
		session['hashed_password']=bcrypt.generate_password_hash(form.password.data).decode('utf-8')
		send_varification_email(session['email_id'])
		flash('Your account has been created! Please complete your profile.','success')
		return redirect(url_for('login'))
	return render_template('register.html' ,title='Register', form = form)
Ejemplo n.º 5
0
def reset_password(token):
	if current_user.is_authenticated:
		return redirect(url_for('home'))
	ins = Institute.verify_reset_token(token)
	if ins is None:
		flash('That is invalid or expired token')
		return redirect(url_for('request_reset'))
	form = ResetPasswordForm()
	if form.validate_on_submit():
		hashed_password = bcrypt.generate_password_hash(form.password.data).decode('utf-8')
		ins.password = hashed_password
		db.session.commit()
		flash('Your Password has been updated , Now You Can Log in!!','success')
		return redirect(url_for('login'))
	return render_template('reset_password.html', title='Reset Password', form = form)
Ejemplo n.º 6
0
def signup():
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    form = RegistrationForm()
    if form.validate_on_submit():
        hashed_pw = bcrypt.generate_password_hash(form.password.data).decode('utf-8')
        session['email'] = form.email.data
        session['password'] = hashed_pw
        try:
            redirect_url = auth.get_authorization_url()
        except tweepy.TweepError:
            flash("Authorization problem!", 'info')
            return redirect(url_for('signup'))
        return redirect(redirect_url)
    return render_template("signup.html", title="signup", form=form)
Ejemplo n.º 7
0
def reset_token(token):
    if current_user.is_authenticated:
        return redirect(url_for('main.home'))
    # call method from User class of models.py
    user = Users.verify_reset_token(token)
    if user is None:
        flash('Password reset has expired or is invalid. Please try again.',
              'warning')
        return redirect(url_for('users.reset_request'))
    # if user is valid:
    form = ResetPasswordForm()
    if form.validate_on_submit():
        # take password value and hash it using bcrypt
        hashed_password = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        user.password = hashed_password
        db.session.commit()
        flash(f'Your password has been updated. You are now able to log in.',
              'success')
        return redirect(url_for('users.login'))
    return render_template('reset_token.html',
                           title='Reset Password',
                           form=form)