Example #1
0
def verification_email_request(subdomain='www'):
    if current_user.is_authenticated:
        if not (current_user.verified == 0 or current_user.verified is None):
            flash('Your account is already verified', 'success')
            return redirect(url_for("main.index", subdomain=subdomain))
        else:
            send_verification_email(current_user)
            flash("An email with instructions was sent to your address.",
                  "success")
            return redirect(url_for("auth.verify_account",
                                    subdomain=subdomain))
    form = ResetPasswordRequestForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user:
            if user.verified == 0 or user.verified is None:
                send_verification_email(user)
                flash("An email with instructions was sent to your address.",
                      "success")
            else:
                flash("Your account is already verified", "success")
        else:
            flash(
                "The email address is incorrect, use a valid email account or create an account.",
                "danger")
        return redirect(url_for("auth.login", subdomain=subdomain))
    return render_template("auth/send_email_verification.html",
                           subdomain=subdomain,
                           title="Request email verification token",
                           form=form)
Example #2
0
def register(subdomain='www'):
    if current_user.is_authenticated:
        if request.args.get("token") is not None:
            company_id_by_token = verify_invitation_token(
                request.args.get("token"))
            current_user.company_id = company_id_by_token
            db.session.add(current_user)
            db.session.commit()
            flash('Your account as been added to a new company', 'success')
        return redirect(url_for("main.index", subdomain=subdomain))
    if request.args.get("email"):
        form = RegistrationForm(
            username=request.args.get("email").split('@')[0],
            email=request.args.get("email"),
            current_user=current_user)
    else:
        form = RegistrationForm(current_user=current_user)
    if form.validate_on_submit():
        # Check that the user should not be redirected to login with SSO
        tenant = _is_user_or_company_premium_and_fully_managed(
            form.email.data, form, subdomain, request.args)
        if tenant != '':
            return redirect(
                url_for("auth.login", subdomain=subdomain, tenant=tenant))

        checkUser = User.query.filter_by(email=form.email.data).first()
        user = User(username=form.username.data, email=form.email.data)
        # TODO the verification of the domain to add the company_id should be done after the email has been verified
        query_domain = Domains.query.filter_by(
            name=form.email.data.split('@')[1]).first()
        mail_in_blacklist = MailProviders.query.filter_by(
            domain=form.email.data.split('@')[1]).first()
        if mail_in_blacklist:
            flash("Only corporate account are allowed to connect", "danger")
            return redirect(url_for("auth.login", subdomain=subdomain))

        # Verify why this is here, this should be inside verify_account
        if request.args.get("token") is not None:
            company_id_by_token = verify_invitation_token(
                request.args.get("token"))
            user.company_id = company_id_by_token
        if query_domain is not None:
            if query_domain.fully_managed_domain == 1:
                user.company_id = query_domain.company_id
        # Until here

        if checkUser is None:
            user.set_password(form.password.data)
            db.session.add(user)
            db.session.commit()
            login_user(user, remember=True)
            send_verification_email(current_user, subdomain=subdomain)
            flash("Congratulations, you are now a registered user!", "success")
            return redirect(url_for("auth.login", subdomain=subdomain))
        else:
            flash("You have already an account on PulsarNews", "danger")
    return render_template("auth/register.html",
                           subdomain=subdomain,
                           title="Register",
                           form=form)
Example #3
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))
    form = RegistrationForm()
    if form.validate_on_submit():
        user = User(username=form.username.data, email=form.email.data)
        user.set_password(form.password.data)
        db.session.add(user)
        db.session.commit()
        #flash('Congratulations, you are now registered!')
        #return redirect(url_for('auth.login'))
        send_verification_email(user)
        return redirect(url_for('auth.unverified_email'))
    return render_template('auth/register.html', title='Register', form=form)
Example #4
0
def register():
    if current_user.is_authenticated:
        if current_user.check_role(['admin']):
            status = 'True'
        else:
            return redirect(url_for('main.index'))
    else:
        status = current_app.config['REGISTRATION_OPEN']

    form = RegistrationForm()
    
    if form.validate_on_submit():
        user = User(email=form.email.data.lower())
        user.set_password(form.password.data)
        db.session.add(user)
        db.session.commit()
        send_verification_email(user)
        return redirect(url_for('auth.unverified_email'))
    return render_template('auth/register.html', title='Register', form=form, status=status)
Example #5
0
def register():
    # If the user is logged in, skip the register page and go to the profile page
    if current_user.is_authenticated:
        return redirect(url_for('profile.profile'))
    form = RegistrationForm()

    # If the form was submitted and is validated
    if form.validate_on_submit():
        # Create user
        u = User()
        u.username = form.email.data
        u.email = form.email.data
        u.firstname = form.firstname.data
        u.lastname = form.lastname.data
        u.address = form.address.data
        u.city = form.city.data
        u.state = form.state.data
        u.zip_code = form.zip_code.data
        u.phone_number = form.phone_number.data
        u.set_password(form.password.data)
        u.verified = False
        u.active_sub = False
        u.subscription = ""

        # Create stripe user
        customer = stripe.Customer.create(email=u.email)
        u.stripe_id = customer.id

        # Save user to DB
        db.session.add(u)
        db.session.commit()

        # Send verification email to user
        send_verification_email(u)

        # Send user a success message
        flash('Success! Check your email for a verification link', 'success')
        return redirect(url_for('auth.login'))

    return render_template('auth/register.html', title='Register', form=form)
Example #6
0
def resend_email_verification():
    print('resend')
    send_verification_email(current_user)
    flash('Verification email has been sent, please check your inbox.')
    return redirect(url_for('auth.unverified_email'))
Example #7
0
def resend_verify():
    if not current_user.verified:
        send_verification_email(current_user)
        flash("Check your email for the verification link", "info")
    return redirect(url_for('profile.profile'))