예제 #1
0
    def check_login(nick_or_email: str, password: str) -> Tuple:
        if recaptcha.verify():
            try:
                UserValidator.check_if_email_exits(nick_or_email)
                UserValidator.check_if_nick_exists(nick_or_email)
                return "Wrong nickname/email/password", "warning", None, None


            except EmailExists:
                email = nick_or_email
                nick = UserValidator.get_nick_from_email(email)
                UserValidator.check_if_activated(email)
                if UserValidator.check_entered_password_with_base(email, password):
                    return "You are successfully logged in", "success", nick, email
                return "Wrong nickname/email/password or not activated", "warning", None, None



            except NickExists:
                nick = nick_or_email
                email = UserValidator.get_email_from_nick(nick)
                UserValidator.check_if_activated(email)
                if UserValidator.check_entered_password_with_base(email, password):
                    return "You are successfully logged in", "success", nick, email
                return "Wrong nickname/email/password or not activated", "warning", None, None

        return "You need to prove captcha", "warning", None, None
예제 #2
0
    def reset_password(self):
        if request.method == 'GET':
            return self._template('reset_password')

        if not recaptcha.verify():
            flash(CAPTCHA_FAILED, 'danger')
            return self._template('reset_password')

        user = User.query.filter_by(email=request.form['email']).first()

        if user and user.is_verified:
            user.verification_token = security.generate_random_token()
            db.session.commit()

            send_message(
                subject='Your password reset request',
                recipients=[user.email],
                html=render_raw_template(
                    'email/password_reset_request.html',
                    user=user,
                    password_reset_link=url_for(
                        'ContentManagementSystem:confirm_password_reset',
                        token=user.verification_token,
                        user=user.id,
                        _external=True
                    )
                )
            )

        flash(PASSWORD_RESET_MAIL_SENT, category='success')
        return redirect(url_for('ContentManagementSystem:login'))
예제 #3
0
def register():
    form = RegisterForm()
    if form.validate_on_submit():
        if recaptcha.verify():
            user = Users(username=form.username.data,
                         email=form.email.data,
                         password=form.password.data,
                         login_count=1,
                         current_login_ip=get_ip(),
                         current_login_at=datetime.datetime.now())
            print user

            db.session.add(user)
            db.session.commit()
            token = generate_confirmation_token(user.email)
            confirm_url = url_for('users.confirm_email_register',
                                  token=token,
                                  _external=True)
            html = render_template("email/welcome.html",
                                   confirm_url=confirm_url,
                                   user=user)
            subject = "Please confirm your email"
            send_email(user.email, subject, html)
            login_user(user, True)
            flash(
                "Welcome <strong>%s</strong> to Menu App. Please go to your inbox and confirm your email."
                % (user.username), "success")
            next = request.args.get("next")
            if not is_safe_url(next):
                return flask.abort(400)
            return redirect(next or url_for("home.index"))
        else:
            flash("Please try again", "danger")
            return redirect(url_for("users.register"))
    return render_template("register.html", form=form)
예제 #4
0
def contact():
    if current_user.is_authenticated:
        form = ContactForm()
    else:
        form = PublicContactForm()
    editable_html_obj = EditableHTML.get_editable_html('contact')
    if request.method == 'POST':
        if form.validate_on_submit():
            if not recaptcha.verify():
                flash("Wrong Captcha, pls try again", 'error')
                return redirect(url_for("public.contact"))
            spam_detect = SpamDetector()

            if current_user.is_authenticated:
                spam_detect.setMessage(form.text.data)
                text_spam = spam_detect.predict()
                spam = False
                if 1 in text_spam:
                    spam = True
                contact_message = ContactMessage(
                    user_id=current_user.id,
                    text=form.text.data,
                    spam=spam
                )
            else:
                spam_detect.setMessage(form.name.data)
                name_spam = spam_detect.predict()
                spam_detect.setMessage(form.text.data)
                text_spam = spam_detect.predict()
                spam = False
                if 1 in name_spam or 1 in text_spam:
                    spam = True
                email = form.email.data
                is_valid = validate_email(email, check_mx=False)
                if not is_valid:
                    flash("The email you entered doesn't exist, pls insert a valid email", 'error')
                    return redirect(url_for("public.contact"))
                contact_message = ContactMessage(
                    name=form.name.data,
                    email=email,
                    text=form.text.data,
                    spam=spam
                )
            db.session.add(contact_message)
            db.session.commit()
            flash('Successfully sent contact message.', 'success')
            return redirect(url_for('public.contact'))
    return render_template('public/contact.html', editable_html_obj=editable_html_obj, form=form)
예제 #5
0
def register_user():
    settings = settingsManage.get_registration()

    # Check if registration is closed
    if settings.switch == 0:
        return render_template("register_closed.html")

    if request.method == "POST":

        # Validate reCAPTCHA
        if recaptcha.verify():
            validate = userManage.validate_new_user(
                request.form["rUser"], request.form["rEmail"],
                request.form["rPass0"], request.form["rPass1"],
                request.form["registerCode"])
        else:
            flash("Please complete the CAPTCHA to continue")
            return render_template(
                "register.html",
                prefill=[request.form["rUser"], request.form["rEmail"]],
                settings=settings)

        # Validate new user data
        if validate != '':
            flash(validate)
            return render_template(
                "register.html",
                prefill=[request.form["rUser"], request.form["rEmail"]],
                settings=settings)
        else:
            # Register user
            userManage.register_user(request.form["rUser"],
                                     request.form["rEmail"],
                                     request.form["rPass0"])
            userSession.auth(request.form["rUser"], request.form["rPass0"])
            return redirect(url_for("user_dashboard"))

    else:
        if "username" in session:
            # Redirect logged-in users to dashboard
            return redirect(url_for("user_dashboard"))
        else:
            # Render registration page
            return render_template("register.html",
                                   prefill=['', ''],
                                   settings=settings)
예제 #6
0
def free_bitcoin():
    render_word = {}
    render_word['time_left'] = None
    render_word['username'] = request.cookies.get('username') if request.cookies.get('username') else ""
    render_word['info_text'] = 'Check balance: <a href="https://faucetbox.com/en/check/' + render_word[
        'username'] + '">link</a>' if render_word['username'] else ""
    render_word['all_balance'] = mongo.db.balance.find_one({})['balance']
    ip = request.remote_addr
    reffer = request.args['ref'] if 'ref' in request.args else None
    form = FreeForm()
    user_data = Free.objects(ip=ip).order_by('-date').limit(1).first()
    if user_data:
        time_left = check_time(user_data)
        render_word['reward'] = user_data['reward']
        if time_left:
            render_word['time_left'] = time_left

            return render_template("free_bitcoin.html", **render_word)
    if form.validate_on_submit()  and recaptcha.verify():
        user_data = Free.objects(wallet=form.wallet.data).order_by('-date').limit(1).first()
        if user_data:
            time_left = check_time(user_data)
            if time_left:
                render_word['time_left'] = time_left
                render_word[
                    'info_text'] = 'Check balance: <a href="https://faucetbox.com/en/check/' + form.wallet.data + '">link</a>' + "<br>Your wallet is used, pls wait 1440 min"
                print form.wallet.data
                return render_template("free_bitcoin.html", **render_word)
        if 'collect' in request.form:
            coin = 300
        elif 'try' in request.form:
            coin = choice([100,200,600])
        send_status = send_money(form.wallet.data, coin, reffer)
        render_word['coin'] = coin
        if send_status[0]:
            Free(wallet=form.wallet.data, ip=ip, reward=coin, reffer=reffer).save()
            response = app.make_response(redirect('/free_bitcoin'))
            response.set_cookie('username', value=form.wallet.data)
            print 'OK'
            return response
        else:
            render_word['info_text'] = "Server error"

    return render_template("free_bitcoin.html", form=form, **render_word)
예제 #7
0
def email_list():
    form = EmailForm()
    if request.method == "POST":
        if recaptcha.verify():
            if form.validate_on_submit():
                if Business.query.filter_by(email=form.email.data).first():
                    flash("You are already signed up for our email list.",
                          "error")
                    return redirect(url_for("index"))
                else:
                    business_to_add = Business(email=form.email.data)
                    db.session.add(business_to_add)
                    db.session.commit()
                    flash("Thank you for signing up for our email list!",
                          "success")
                    return redirect(url_for("index"))
        else:
            flash("Please fill out the recaptcha form.", "error")
    return render_template("email_list/email_list.html", form=form)
예제 #8
0
def contact():
    form = ContactForm()
    if request.method == "POST":
        if recaptcha.verify():
            if form.validate_on_submit():
                try:
                    send_form_email(name=form.name.data,
                                    email=form.email.data,
                                    phone=form.phone.data,
                                    message=form.message.data)
                    flash("Email sent.", "success")
                except:
                    e = sys.exc_info()[0]
                    print("Error: %s" % e)
                    flash(
                        "Email failed to send due to an internal server error. We will resolve this ASAP!",
                        "error")
        else:
            flash("Please fill out the recaptcha form.", "error")
    return render_template("core/contact.html", form=form)
예제 #9
0
def index():

    if request.method == 'GET':
        return render_template('registration/index.html')
    elif request.method == 'POST' and recaptcha.verify():
        full_name = request.form['full_name']
        email = request.form['email']
        login = request.form['login']
        password = request.form['password']
        confirm_password = request.form['confirm_password']
    else:
        return render_template('registration/index.html', captcha_error='Recaptcha error!')

    if confirm_password != password:
        return render_template('registration/index.html', error_password="******")

    user_email = User.query.filter(User.email == email).first()
    user_login = User.query.filter(User.login == login).first()

    if user_email and user_email.email == email:
        return render_template('registration/index.html', error_email="This email is already exist!")

    elif user_login and user_login.login == login:
        return render_template('registration/index.html', error_login="******")

    elif full_name and email and login and password:
        try:
            user = user_datastore.create_user(full_name=full_name, email=email, login=login, password=password)
            role = Role.query.filter(Role.name == 'user').first()
            user_datastore.add_role_to_user(user, role)
            db.session.add(user)
            db.session.commit()

        except:
            return render_template('registration/index.html', error_message="Something wrong, please try again!")


    return redirect(url_for_security('login'))
예제 #10
0
    def send_message(self):
        go_to = request.form.get('after_success', '/')
        redirection = redirect(go_to)

        if not recaptcha.verify():
            flash(CAPTCHA_FAILED, 'danger')
            return redirection

        try:
            name = request.form['name']
            email = request.form['email']
            subject = request.form['subject']
            content = request.form['content']
        except KeyError:
            flash('Something gone wrong - not all fields are present!',
                  'danger')
            return redirection

        if not name or not content or not subject or not email:
            flash('Please, fill in all fields', 'warning')
            return redirection

        if not User.is_mail_correct(email):
            flash('Provided email address is not correct', 'warning')
            return redirection

        success = send_message(
            subject=subject,
            body=content,
            recipients=current_app.config['CONTACT_LIST'],
            reply_to='{0} <{1}>'.format(name, email),
        )

        if success:
            flash('Message sent!', 'success')

        return redirection
예제 #11
0
def index():

    if request.method == 'GET':
        return render_template('contact/index.html')
    elif request.method == 'POST' and recaptcha.verify():
        name = request.form['name']
        email = request.form['email']
        title = request.form['title']
        text = request.form['message']
    else:
        return render_template('contact/index.html', captcha_error='Recaptcha error!')

    if name and email and title and text:
        try:
            message = Messages(name=name, title=title, email=email, text=text)
            db.session.add(message)
            db.session.commit()
        except:
            print('Something wrong! Please, try again.')
            return render_template('contact/index.html')

    feedback_message = Message('Thank you for your attention!', sender=Configuration.ADMINS[0],
              recipients=[email])
    feedback_message.body = render_template("contact/feedback_message.txt",
            name=name)

    customer_message = Message(title, sender=Configuration.ADMINS[0],
                               recipients=[Configuration.ADMINS[0]])
    customer_message.body = render_template("contact/customer_message.txt",
                                            name=name, title=title, email=email, text=text)

    with app.app_context():
        mail.send(feedback_message)
        mail.send(customer_message)

    return redirect(url_for('index'))
예제 #12
0
 def check_recaptcha():
     if not recaptcha.verify():
         raise RecaptchaIsMissing
예제 #13
0
    def sign_up(self):
        if request.method == 'GET':
            return self._template('register')

        if not recaptcha.verify():
            flash(CAPTCHA_FAILED, 'danger')
            return self._template('register')

        consent = request.form.get('consent', False)

        if not consent:
            flash(
                'Data policy consent is required to proceed.',
                'danger'
            )
            return self._template('register')

        email = request.form.get('email', '')
        password = request.form.get('password', '')

        claim_success = False

        try:
            new_user = User(email, password, access_level=0)
            db.session.add(new_user)
            db.session.commit()

            html_message = render_raw_template(
                'email/registration.html',
                user=new_user,
                email_sign_up_message=self._system_setting('email_sign_up_message') or '',
                activation_link=url_for(
                    'ContentManagementSystem:activate_account',
                    token=new_user.verification_token,
                    user=new_user.id,
                    _external=True
                )
            )

            sent = send_message(
                subject='Your account activation link',
                recipients=[new_user.email],
                html=html_message
            )

            if sent:
                claim_success = True

        except ValidationError as e:
            flash(e.message, 'danger')
            return self._template('register')
        except IntegrityError:
            db.session.rollback()

        already_a_user = User.query.filter_by(email=email).count()

        if already_a_user:
            claim_success = True
        else:
            flash(
                'Something went wrong when creating your account. '
                'If the problem reoccurs please contact us.',
                'danger'
            )

        if claim_success:
            flash(SIGNED_UP_OR_ALREADY_USER_MSG, 'success')
            # TODO: create a dedicated "Thank you, but activate your account now" page?
            return redirect(url_for('ContentManagementSystem:login'))

        return self._template('register')