예제 #1
0
def register():
    """Register a new user, and send them a confirmation email."""
    form = RegistrationForm()
    if form.validate_on_submit():
        user = User(
            first_name=form.first_name.data,
            last_name=form.last_name.data,
            email=form.email.data,
            password=form.password.data,
            vcpu_limit=form.vcpu_limit.data,
            memory_limit=form.memory_limit.data,
        )
        db.session.add(user)
        db.session.commit()
        token = user.generate_confirmation_token()
        confirm_link = url_for("account.confirm", token=token, _external=True)
        user.__dict__.pop("storage_files")
        get_queue().enqueue(
            send_email,
            recipient=user.email,
            subject="Confirm Your Account",
            template="account/email/confirm",
            user=user,
            confirm_link=confirm_link,
        )
        flash("A confirmation link has been sent to {}.".format(user.email),
              "warning")
        return redirect(url_for("main.index"))
    return render_template("account/register.html", form=form)
예제 #2
0
def register():
    """Register a new user, and send them a confirmation email."""
    form = RegistrationForm()
    if form.validate_on_submit():
        is_invited = User.query.filter_by(email=form.email.data).first()
        if is_invited is not None:
            if is_invited.password is None:
                user = User(first_name=form.first_name.data,
                            last_name=form.last_name.data,
                            email=form.email.data,
                            password=form.password.data)
                db.session.add(user)
                db.session.commit()
                token = user.generate_confirmation_token()
                confirm_link = url_for('account.confirm',
                                       token=token,
                                       _external=True)
                status = send_email(recipient=user.email,
                                    subject='Confirm Your Account',
                                    template='account/email/confirm',
                                    user=user,
                                    invite_link=confirm_link)
                flash(
                    'A confirmation link has been sent to {}.'.format(
                        user.email), 'warning')
                return redirect(url_for('main.index'))

    if request.method == 'POST':
        flash(
            'Sorry, you are only allowed to register if you have been invited '
            'by the administrator.', 'form-error')

    return render_template('account/register.html', form=form)
예제 #3
0
def register():
    """Register a new user, and send them a confirmation email."""
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))

    form = RegistrationForm()
    if form.validate_on_submit():

        # Implement Password Confirmations
        user = User(
            username=form.username.data,
            key=form.key.data,
            email=form.email.data,
            password=form.password.data,
            confirmed=True)
        # Confirmed is True as default

        db.session.add(user)
        db.session.commit()
        # Email Confirmation
        # token = user.generate_confirmation_token()
        # confirm_link = url_for('account.confirm', token=token, _external=True)
        # get_queue().enqueue(
        #     send_email,
        #     recipient=user.email,
        #     subject='Confirm Your Account',
        #     template='account/email/confirm',
        #     user=user,
        #     confirm_link=confirm_link)
        # flash('A confirmation link has been sent to {}.'.format(user.email),
        #       'warning')
        flash(Markup('Registration Completed<br> Please sign in by clicking <a href="' +
                     url_for('account.login')+'">here</a>'))
        return redirect(url_for('account.register'))
    return render_template('account/register.html', form=form)
예제 #4
0
def register():
    title = 'Create an account'

    if current_user.is_authenticated:
        return redirect(url_for('main.index'))

    form = RegistrationForm()
    if form.validate_on_submit():
        email = form.email.data.lower()
        hashed_password = bcrypt.generate_password_hash(form.password.data).decode('utf-8')
        master_key = generate_pswrd(length=32, special=False)
        encrypted_master_key = encrypt(get_key(form.password.data), master_key)
        user = User(email=email, password=hashed_password, master_key=encrypted_master_key)

        try:
            send_activation_email(user)
            flash('Account created! Verification link has been sent to your email.', 'success')
        except SMTPRecipientsRefused:
            flash('Entered email address is invalid!', 'danger')
            return redirect(url_for('account.register'))
        except:
            user.activated = True
            flash('Account created! You can now log in.', 'success')

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

        return redirect(url_for('account.login'))

    return render_template('account/register.html', title=title, form=form)
예제 #5
0
def register():
    """Register a new user, and send them a confirmation email."""
    # Prefill email from landing page
    if request.args.get('email'):
        form = RegistrationForm(request.args)
    else:
        form = RegistrationForm()
    if form.validate_on_submit():
        user = User(
            name=form.name.data,
            email=form.email.data,
            password=form.password.data)
        db.session.add(user)
        db.session.commit()
        token = user.generate_confirmation_token()
        confirm_link = url_for('account.confirm', token=token, _external=True)
        flash('A confirmation link has been sent to {}.'.format(user.email), 'warning')
        send_email(
            recipient=form.email.data,
            subject='Confirm Your Account',
            template='account/email/confirm',
            user_name=form.name.data,
            confirm_link=confirm_link
        )
        return redirect(url_for('main.index'))
    return render_template('account/register.html', form=form)
예제 #6
0
def register(subscription=enum.Subscriptions.PERSONAL.value):
    """Register a new user, and send them a confirmation email."""
    form = RegistrationForm()
    if form.validate_on_submit():
        user = db_service.register_new_user(
            form.first_name.data, form.last_name.data, form.email.data,
            form.password.data, form.terms_agree.data, subscription)
        token = db_service.generate_confirmation_token(user)
        confirm_link = url_for('account.confirm', token=token, _external=True)

        send_email(recipient=user.email,
                   subject='Confirm Your Account',
                   template='account/email/confirm',
                   user=user,
                   confirm_link=confirm_link)

        send_email(recipient='*****@*****.**',
                   subject='Stock Score Server: new account registered',
                   template='account/email/new_account_registered',
                   user=user)

        flash(f'A confirmation link has been sent to {user.email}.', 'warning')
        url = account_login(form.email.data, form.password.data, True, request)
        if url:
            return redirect(request.args.get('next') or url_for(url))
    return render_template('account/register_new.html',
                           subscription=subscription,
                           form=form)
예제 #7
0
def register():
    """Register a new user, and send them a confirmation email."""

    # must pass the survey in order to be able to register
    can_register = request.cookies.get('can_register')
    if not can_register:
        return redirect(403)

    # passed survey
    form = RegistrationForm()
    if form.validate_on_submit():
        user = User(
            first_name=form.first_name.data,
            last_name=form.last_name.data,
            email=form.email.data,
            password=form.password.data)
        db.session.add(user)
        db.session.commit()
        token = user.generate_confirmation_token()
        confirm_link = url_for('account.confirm', token=token, _external=True)
        get_queue().enqueue(
            send_email,
            recipient=user.email,
            subject='Confirm Your Account',
            template='account/email/confirm',
            user=user,
            confirm_link=confirm_link)
        flash('A confirmation link has been sent to {}.'.format(user.email),
              'warning')
        return redirect(url_for('main.index'))
    return render_template('account/register.html', form=form)
예제 #8
0
def register():
    """Register a new user."""
    form = RegistrationForm()
    if form.validate_on_submit():
        user = User(first_name=form.first_name.data,
                    last_name=form.last_name.data,
                    email=form.email.data,
                    password=form.password.data)
        db.session.add(user)
        db.session.commit()
        return redirect(url_for('main.index'))
    return render_template('account/register.html', form=form)
예제 #9
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))
    form = RegistrationForm(request.form)
    if form.validate_on_submit():
        user = User(username=form.username.data,
                    email=form.email.data,
                    password=form.password.data)
        db.session.add(user)
        db.session.commit()
        flash('Congratulations, you are now a registered user!')
        return redirect(url_for('account.login'))
    return render_template('account/register.html',
                           title='Register',
                           form=form)
예제 #10
0
def register():
    """Register a new user, and send them a confirmation email."""
    form = RegistrationForm()
    if form.validate_on_submit():
        user = User(
            # first_name=form.first_name.data,
            # last_name=form.last_name.data,
            username=form.username.data,
            full_name=form.full_name.data,
            email=form.email.data,
            password=form.password.data)
        # try:
        #     hyp_client.create_account(user.email, email=user.email,
        #                               display_name=user.email)
        # except HTTPError as ex:
        #     # FIXME: Make the service respond with an appropriate status code and
        #     # machine-readable error if the user account already exists
        #     email_err = 'user with email address {} already exists'.format(user.email)
        #     username_err = 'user with username {} already exists'.format(user.email)
        #     content = ex.response.content
        #     if email_err not in content and username_err not in content:
        #         raise ex
        # username = "******".format(user.first_name.lower(), user.last_name.lower())
        current_app.hypothesis_client.create_account(
            user.username, email=user.email, display_name=user.full_name)
        db.session.add(user)
        db.session.commit()
        # token = user.generate_confirmation_token()
        # confirm_link = url_for('account.confirm', token=token, _external=True)
        # get_queue().enqueue(
        #     send_email,
        #     recipient=user.email,
        #     subject='Confirm Your Account',
        #     template='account/email/confirm',
        #     user=user,
        #     confirm_link=confirm_link)
        # flash('A confirmation link has been sent to {}.'.format(user.email),
        #       'warning')

        # Bypass email confirmation
        user.force_confirm_account()
        return redirect(url_for('main.index'))
        # return redirect(url_for('account.manage'))
    return render_template('account/register.html', form=form)
예제 #11
0
def register():
    """Register a new user, and send them a confirmation email."""
    form = RegistrationForm()
    if form.validate_on_submit():
        user = User(first_name=form.first_name.data,
                    last_name=form.last_name.data,
                    email=form.email.data,
                    password=form.password.data)
        user.save()
        token = user.generate_confirmation_token()
        confirm_link = url_for('account.confirm', token=token, _external=True)
        send_email.queue(recipient=user.email,
                         subject='Confirm Your Account',
                         template='account/email/confirm',
                         user=user,
                         confirm_link=confirm_link)
        flash(f'A confirmation link has been sent to {user.email}.', 'warning')
        return redirect(url_for('main.index'))
    return render_template('account/register.html', form=form)
예제 #12
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))
    form = RegistrationForm(request.form)
    if form.validate_on_submit():
        user = User(username=form.username.data,
                    email=form.email.data,
                    password=form.password.data)
        db.session.add(user)
        db.session.commit()
        flash('Congratulations, you are now a registered user!')
        return redirect(url_for('account.login'))
    categories = Category.query.order_by(Category.name.desc())
    cart_items = g.cart.cart_items
    cart_quantity = sum([item.amount for item in cart_items])

    return render_template('account/register.html',
                           categories=categories,
                           cart_quantity=cart_quantity,
                           title='Register',
                           form=form)
예제 #13
0
def register():
    """Register a new user, and send them a confirmation email."""
    form = RegistrationForm()
    if form.validate_on_submit():
        user = User(first_name=form.first_name.data,
                    last_name=form.last_name.data,
                    email=form.email.data,
                    password=form.password.data)
        db.session.add(user)
        db.session.commit()
        token = user.generate_confirmation_token()
        confirm_link = url_for('account.confirm', token=token, _external=True)
        send_email_async(app=current_app._get_current_object(),
                         recipient=user.email,
                         subject='Confirm Your Account',
                         template='account/email/confirm',
                         user=user,
                         confirm_link=confirm_link)
        flash('A confirmation link has been sent to {}.'.format(user.email),
              'warning')
        return redirect(url_for('main.index'))
    return render_template_with_nav_info('account/register.html', form=form)
예제 #14
0
def register():
    """Register a new user, and send them a confirmation email."""
    form = RegistrationForm()
    if form.validate_on_submit():
        user = User(user_name=form.user_name.data,
                    full_name=form.full_name.data,
                    email=form.email.data,
                    password=form.password.data)
        db.session.add(user)
        db.session.commit()
        token = user.generate_confirmation_token()
        confirm_link = url_for('account.confirm', token=token, _external=True)
        get_queue().enqueue(send_email,
                            recipient=user.email,
                            subject='Confirm Your Account',
                            template='account/email/confirm',
                            user=user,
                            confirm_link=confirm_link)
        flash(
            gettext('A confirmation link has been sent to {}.').format(
                user.email), 'warning')
        return redirect(url_for('main.index'))
    return render_template('account/register.html', form=form)
예제 #15
0
def register():
    """Register a new user, and send them a confirmation email."""
    form = RegistrationForm()
    if form.validate_on_submit():
        user = User(first_name=form.first_name.data,
                    last_name=form.last_name.data,
                    email=form.email.data,
                    password=form.password.data)
        db_session_add(user)
        token = user.generate_confirmation_token()
        confirm_link = url_for('account.confirm', token=token, _external=True)
        get_queue().enqueue(send_email,
                            recipient=user.email,
                            subject='Confirm Your Account',
                            template='account/email/confirm',
                            user=user,
                            confirm_link=confirm_link)
        flash('A confirmation link has been sent to {}.'.format(user.email),
              'warning')
        login_user(user)
        return jsonify(status='ok')
    return render_template('account/register.html',
                           form=form,
                           title="Register")
예제 #16
0
def register():
    """Register a new user, and send them a confirmation email."""
    form = RegistrationForm()
    if form.is_submitted():
        print("submitted")

    if form.validate_on_submit():
        print("valid")

    print(form.errors)
    if form.validate_on_submit():
        user = User(
            first_name=form.first_name.data,
            last_name=form.last_name.data,
            email=form.email.data,
            password=form.password.data,
            phone_number=form.phone_number.data,
            street=form.street.data,
            city=form.city.data,
            state=form.state.data,
            zip_code = form.zip_code.data,
            organization_corporation=form.organization_corporation.data,
            pa_residency =form.pa_residency.data,
            confirmed=False,
            role_id=1)
        db.session.add(user)
        if form.pa_residency.data == "Yes":
            volunteer = Volunteer(
                first_name=form.first_name.data,
                last_name=form.last_name.data,
                email=form.email.data,
                phone_number=form.phone_number.data,
                address_street=form.street.data,
                address_city=form.city.data,
                address_state=form.state.data,
                address_zip_code = form.zip_code.data,
                organization = form.organization_corporation.data,
                year_pa = form.pa_residency.data,
                status1=Status.NOT_SUBMITTED,
                status2=Status.NOT_SUBMITTED,
                status3=Status.NOT_NEEDED,
                status4=Status.NOT_SUBMITTED
            )
        if form.pa_residency.data == "No":
            volunteer = Volunteer(
                first_name=form.first_name.data,
                last_name=form.last_name.data,
                email=form.email.data,
                phone_number=form.phone_number.data,
                address_street=form.street.data,
                address_city=form.city.data,
                address_state=form.state.data,
                address_zip_code = form.zip_code.data,
                organization = form.organization_corporation.data,
                year_pa = form.pa_residency.data,
                status1=Status.NOT_SUBMITTED,
                status2=Status.NOT_SUBMITTED,
                status3=Status.NOT_SUBMITTED,
                status4=Status.NOT_SUBMITTED
            )
        db.session.add(volunteer)
        # db.session.query(user)
        db.session.commit()

        token = user.generate_confirmation_token()
        confirm_link = url_for('account.confirm', token=token, _external=True)
        get_queue().enqueue(
            send_email,
            recipient=user.email,
            subject='Confirm Your Account',
            template='account/email/confirm',
            user=user,
            confirm_link=confirm_link)
        flash('A confirmation link has been sent to {}.'.format(user.email),
              'warning')
        return redirect(url_for('main.index'))
    return render_template('account/register.html', form=form)