Example #1
0
def register():
    try:
        if current_user.is_authenticated:
            return redirect(url_for('main.home'))
        form = RegistrationForm()
        if form.validate_on_submit():

            cus = stripe.Customer.create(email=form.email.data.lower())

            hashed_password = bcrypt.generate_password_hash(form.password.data)
            user = User(name=form.name.data,
                        email=form.email.data.lower(),
                        password=hashed_password,
                        customer_id=cus.id)
            db.session.add(user)
            db.session.commit()
            token = generate_confirmation_token(user.email)
            confirm_url = url_for('users.confirm_email',
                                  token=token,
                                  _external=True)
            html = render_template("activate.html", confirm_url=confirm_url)
            subject = "Please confirm your email"
            send_email(user.email, subject, html)

            login_user(user)

            flash(
                'Your account has been created! A confirmation email has been sent.',
                'success')
            return redirect(url_for('users.account'))
        return render_template("register.html", title="Register", form=form)
    except Exception as e:
        SendErrMail(e)
Example #2
0
def SendErrMail(err):
    if current_user.is_authenticated:
        html = render_template("error.html",
                               user=current_user.email,
                               error=str(err))
    else:
        html = render_template("error.html", user="******", error=str(err))
    subject = "Error Occured"
    send_email("**************", subject, html)
    string = "Error Occured" + str(err)
    flash(string, 'danger')
    return redirect(url_for('main.home'))
Example #3
0
def reset_request():
    if current_user.is_authenticated:
        return redirect(url_for('main.home'))
    form = RequestResetForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        send_email(user)

        flash(
            "An email has been sent to reset the password\n The email token will expire in 30 minutes",
            "info")
        return redirect(url_for('users.login'))
    return render_template('reset_request.html',
                           title='Reset Password',
                           form=form)
Example #4
0
def reset_request():
    if current_user.is_authenticated:
        return redirect(url_for('main.home'))
    form = RequestResetForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        send_email(user)
        flash(
            f"An email has been sent with instructions to reset your password.",
            'info')
        return redirect(url_for('users.login'))
    return render_template('reset_request.html',
                           title="Reset password request",
                           form=form,
                           legend='Request for reset password')
def contact_form_send(domain):
    try:
        website = User.query.filter_by(domain=domain).first()
        form = EmailForm()
        if form.validate_on_submit():
            email = form.email_acc.data
            phone = form.phone.data
            content = form.content.data
            html = render_template("contacted.html", email=email, phone=phone, content=content)
            subject = email + " has contacted you on your website."
            send_email(website.contact_email, subject, html)
            flash("Successfully Contacted", 'success')
            return redirect(url_for('posts.post', domain=website.domain))
        return render_template("post.html", domain=website.domain)
    except Exception as e:
        SendErrMail(e)
Example #6
0
def account():
    try:
        form = EmailForm()
        if form.validate_on_submit():
            email = form.email_acc.data
            phone = form.phone.data
            content = form.content.data
            html = render_template("contacted.html",
                                   email=email,
                                   phone=phone,
                                   content=content)
            subject = email + " has contacted you"
            send_email('*****@*****.**', subject, html)
            flash("Successfully Contacted", 'success')
            return redirect(url_for('users.account'))
        return render_template("account.html", form=form, key=PUB_KEY)
    except Exception as e:
        SendErrMail(e)
Example #7
0
def privacy():
    try:
        form = EmailForm()
        if form.validate_on_submit():
            email = form.email_acc.data
            phone = form.phone.data
            content = form.content.data
            html = render_template("contacted.html",
                                   email=email,
                                   phone=phone,
                                   content=content)
            subject = email + " has contacted you"
            send_email('**************', subject, html)
            flash("Successfully Contacted", 'success')
            return redirect(url_for('main.home'))
        return render_template('privacy-policy.html', form=form)
    except Exception as e:
        SendErrMail(e)
Example #8
0
def resend_confirmation():
    try:
        if not current_user.confirmed:
            token = generate_confirmation_token(current_user.email)
            confirm_url = url_for('users.confirm_email',
                                  token=token,
                                  _external=True)
            html = render_template("activate.html", confirm_url=confirm_url)
            subject = "Please confirm your email"
            send_email(current_user.email, subject, html)
            flash(
                'Your account has been created! A confirmation email has been sent.',
                'success')
            return redirect(url_for('users.account'))
        else:
            flash('Your account is already confirmed.', 'success')
            return redirect(url_for('users.account'))
    except Exception as e:
        SendErrMail(e)
Example #9
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('main.home'))
    form = RegistrationForm()
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(form.password.data).decode('utf-8')
        user = User(username=form.username.data, email=form.email.data, password=hashed_password,
                    confirmed=False, confirmed_on=None)
        db.session.add(user)
        db.session.commit()
        token = generate_confirmation_token(user.email)
        confirm_url = url_for('users.confirm_email', token=token, _external=True)
        html = render_template('main/activate.html', confirm_url=confirm_url)
        subject = "Please confirm your email"
        send_email(user.email, subject, html)

        login_user(user)

        flash('A confirmation email has been sent via email.', 'success')
        return redirect(url_for("main.home"))
    return render_template('main/register.html', title='Register', form=form)
Example #10
0
def forgotpass():
    try:
        form = ResetPassForm()
        if form.validate_on_submit():
            email = form.email.data.lower()
            user = User.query.filter_by(email=email).first_or_404()
            if user:
                token = generate_confirmation_token(email)
                confirm_url = url_for('users.resetpass',
                                      token=token,
                                      _external=True)
                html = render_template("pass-reset-email.html",
                                       confirm_url=confirm_url)
                subject = "Your Password Reset Link"
                send_email(email, subject, html)
                flash('An email has been sent to reset your password.',
                      'success')
                return redirect(url_for('users.login'))
        return render_template("pass-forgot.html",
                               form=form,
                               title="Password Reset")
    except Exception as e:
        SendErrMail(e)
def charge(domain, plan_type, addon=None, addon2=None):
    website = User.query.filter_by(domain=domain).first()
    if website.id != current_user.id:
        abort(403)
    try:
        cus = stripe.Customer.retrieve(website.customer_id)
    except:
        cus = stripe.Customer.create(
                email=current_user.email,
            )
        current_user.customer_id = cus.id
    if not cus.sources:
        cus.source = request.form['stripeToken']
        cus.save()

    try:
        sub = stripe.Subscription.retrieve(current_user.subscription_id)
        stripe.SubscriptionItem.create(
            subscription=sub.id,
            plan=plan_type,
            quantity=1,
        )

    except:
        sub = stripe.Subscription.create(
            customer=cus.id,
            items=[
            {
              'plan':plan_type,
            },
            ])
        current_user.subscription_id = sub.id

    try:
        if plan_type == "***********":
            current_user.no_ads = True
            db.session.commit()
            html = render_template("purchase.html", user=current_user.email, purchase="Remove Advertisements")
            subject = "A user has bought something"
            send_email("**************", subject, html)
            flash("Payment Successful! Advertisements have been removed", 'success')
            return redirect(url_for('users.account'))
        elif plan_type == "***********":
            website.contact_form = True
            db.session.commit()
            html = render_template("purchase.html", user=current_user.email, purchase="Contact Form")
            subject = "A user has bought something"
            send_email("**************", subject, html)
            flash("Payment Successful! A contact form has been created on your site!", 'success')
            return redirect(url_for('users.account'))
        elif plan_type == "***********":
            website.gallery = True
            db.session.commit()
            html = render_template("purchase.html", user=current_user.email, purchase="Image Gallery")
            subject = "A user has bought something"
            send_email("**************", subject, html)
            flash("Payment Successful! An image gallery has been created on your site! Please add some images.", 'success')
            return redirect(url_for('users.account'))
        elif plan_type == "***********":
            website.newsletter = True
            db.session.commit()
            html = render_template("purchase.html", user=current_user.email, purchase="Newsletter")
            subject = "A user has bought something"
            send_email("**************", subject, html)
            flash("Payment Successful! An email form for newsletters has been created on your site!", 'success')
            return redirect(url_for('users.account'))
        elif plan_type == "***********":
            html = render_template("purchase.html", user=current_user.email, purchase=current_user.custom_domain)
            subject = "A user has bought something"
            send_email("**************", subject, html)
            flash("Payment Successful! Please allow 24 to 48 hours for your domain to propagate.", 'success')
            return redirect(url_for('posts.account'))
        elif plan_type == "***********":
            html = render_template("purchase.html", user=current_user.email, purchase=current_user.custom_email)
            subject = "A user has bought something"
            send_email("**************", subject, html)
            flash("Payment Successful! Please expect an email to discuss your email hosting.", 'success')
            return redirect(url_for('posts.account'))
    except Exception as e:
        SendErrMail(e)