Exemplo n.º 1
0
def register():
    if not _cfgb('registration'):
        return redirect("/")
    if request.method == 'POST':
        # Validate
        kwargs = dict()
        followMod = request.form.get('follow-mod')
        email = request.form.get('email')
        username = request.form.get('username')
        password = request.form.get('password')
        confirmPassword = request.form.get('repeatPassword')



        error = check_email_for_registration(email)
        if error:
            kwargs['emailError'] = error

        error = check_username_for_registration(username)
        if error:
            kwargs['usernameError'] = error

        if not password:
            kwargs['passwordError'] = 'Password is required.'
        else:
            if password != confirmPassword:
                kwargs['repeatPasswordError'] = 'Passwords do not match.'
            if len(password) < 5:
                kwargs['passwordError'] = 'Your password must be greater than 5 characters.'
            if len(password) > 256:
                kwargs['passwordError'] = 'We admire your dedication to security, but please use a shorter password.'
        if not kwargs == dict():
            # Fill in config values
            kwargs['site_name'] = _cfg('site-name')
            kwargs['support_mail'] = _cfg('support-mail')
            if email is not None:
                kwargs['email'] = email
            if username is not None:
                kwargs['username'] = username
            kwargs['registration'] = registration = _cfgb('registration')
            print("test")
            return render_template("register.html", **kwargs)
        # All valid, let's make them an account
        user = User(username, email, password)
        user.confirmation = binascii.b2a_hex(os.urandom(20)).decode("utf-8")
        db.add(user)
        db.commit() # We do this manually so that we're sure everything's hunky dory before the email leaves
        if followMod:
            send_confirmation(user, followMod)
        else:
            send_confirmation(user)
        return redirect("/account-pending")
    else:
        return render_template("register.html", **{ "site_name": _cfg('site-name'), "support_mail": _cfg('support-mail'), "registration": _cfgb('registration') })
Exemplo n.º 2
0
def register():
    if not _cfgb('registration'):
        return redirect("/")
    if request.method == 'POST':
        # Validate
        kwargs = dict()
        followMod = request.form.get('follow-mod')
        email = request.form.get('email')
        username = request.form.get('username')
        password = request.form.get('password')
        confirmPassword = request.form.get('repeatPassword')

        error = check_email_for_registration(email)
        if error:
            kwargs['emailError'] = error

        error = check_username_for_registration(username)
        if error:
            kwargs['usernameError'] = error

        if not password:
            kwargs['passwordError'] = 'Password is required.'
        else:
            if password != confirmPassword:
                kwargs['repeatPasswordError'] = 'Passwords do not match.'
            if len(password) < 5:
                kwargs[
                    'passwordError'] = 'Your password must be greater than 5 characters.'
            if len(password) > 256:
                kwargs[
                    'passwordError'] = 'We admire your dedication to security, but please use a shorter password.'
        if not kwargs == dict():
            if email is not None:
                kwargs['email'] = email
            if username is not None:
                kwargs['username'] = username
            kwargs['registration'] = registration = _cfgb('registration')
            print("test")
            return render_template("register.html", **kwargs)
        # All valid, let's make them an account
        user = User(username, email, password)
        user.confirmation = binascii.b2a_hex(os.urandom(20)).decode("utf-8")
        db.add(user)
        db.commit(
        )  # We do this manually so that we're sure everything's hunky dory before the email leaves
        if followMod:
            send_confirmation(user, followMod)
        else:
            send_confirmation(user)
        return redirect("/account-pending")
    else:
        return render_template("register.html",
                               registration=_cfgb('registration'))
Exemplo n.º 3
0
def inject():
    ads = True
    first_visit = True
    dismissed_donation = False
    if 'ad-opt-out' in request.cookies:
        ads = False
    if g.do_not_track:
        ads = False
    if not _cfg("project_wonderful_id"):
        ads = False
    if request.cookies.get('first_visit') != None:
        first_visit = False
    if request.cookies.get('dismissed_donation') != None:
        dismissed_donation = True
    return {
        'mobile': g.mobile,
        'ua_platform': request.user_agent.platform,
        'analytics_id': _cfg("google_analytics_id"),
        'analytics_domain': _cfg("google_analytics_domain"),
        'disqus_id': _cfg("disqus_id"),
        'dnt': g.do_not_track,
        'ads': ads,
        'ad_id': _cfg("project_wonderful_id"),
        'root': _cfg("protocol") + "://" + _cfg("domain"),
        'domain': _cfg("domain"),
        'user': current_user,
        'len': len,
        'any': any,
        'following_mod': following_mod,
        'following_user': following_user,
        'admin': is_admin(),
        'oauth_providers': list_defined_oauths(),
        'wrap_mod': wrap_mod,
        'dumb_object': dumb_object,
        'first_visit': first_visit,
        'request': request,
        'locale': locale,
        'url_for': url_for,
        'strftime': strftime,
        'datetime': datetime,
        'site_name': _cfg('site-name'),
        'support_mail': _cfg('support-mail'),
        'source_code': _cfg('source-code'),
        'irc_channel': _cfg('irc-channel'),
        'donation_link': _cfg('donation-link'),
        'donation_header_link': _cfgb('donation-header-link') if not dismissed_donation else False,
        'registration': _cfgb('registration')
    }
Exemplo n.º 4
0
def send_mail(sender, recipients, subject, message, important=False):
    if _cfg("smtp-host") == "":
        return
    smtp = smtplib.SMTP(host=_cfg("smtp-host"), port=_cfgi("smtp-port"))
    if _cfgb("smtp-tls"):
        smtp.starttls()
    if _cfg("smtp-user") != "":
        smtp.login(_cfg("smtp-user"), _cfg("smtp-password"))
    message = MIMEText(message)
    if important:
        message['X-MC-Important'] = "true"
    message['X-MC-PreserveRecipients'] = "false"
    message['Subject'] = subject
    message['From'] = sender
    if len(recipients) > 1:
        message['Precedence'] = 'bulk'
    for group in chunks(recipients, 100):
        if len(group) > 1:
            message['To'] = "undisclosed-recipients:;"
        else:
            message['To'] = ";".join(group)
        print("Sending email from {} to {} recipients".format(
            sender, len(group)))
        smtp.sendmail(sender, group, message.as_string())
    smtp.quit()
Exemplo n.º 5
0
def send_mail(sender, recipients, subject, message, important=False):
    if _cfg("smtp-host") == "":
        return
	smtp = None
	# If there's a config option provided, use starttls
	if _cfgb('tls'):
		smtp = smtplib.SMTP_SSL(_cfg("smtp-host"), _cfgi("smtp-port"), )
	else:		
		smtp = smtplib.SMTP(host=_cfg("smtp-host"), port=_cfgi("smtp-port"), keyfile=open(_cfg('tls-keyfile')), certfile=open(_cfg('tls-certfile')))
	if _cfg("smtp-user") == "" and _cfg("smtp-password") == "":
		smtp.login(_cfg("smtp-user"), _cfg("smtp-password"))
    message = MIMEText(message)
    if important:
        message['X-MC-Important'] = "true"
    message['X-MC-PreserveRecipients'] = "false"
    message['Subject'] = subject
    message['From'] = sender
    for group in chunks(recipients, 100):
        message['To'] = ";".join(group)
        print("Sending email from {} to {} recipients".format(sender, len(group)))
        smtp.sendmail(sender, group, message.as_string())
    smtp.quit()
Exemplo n.º 6
0
def send_mail(sender, recipients, subject, message, important=False):
    if _cfg("smtp-host") == "":
        return
    smtp = smtplib.SMTP(host=_cfg("smtp-host"), port=_cfgi("smtp-port"))
    if _cfgb("smtp-tls"):
        smtp.starttls()
    if _cfg("smtp-user") != "":
        smtp.login(_cfg("smtp-user"), _cfg("smtp-password"))
    message = MIMEText(message)
    if important:
        message['X-MC-Important'] = "true"
    message['X-MC-PreserveRecipients'] = "false"
    message['Subject'] = subject
    message['From'] = sender
    if len(recipients) > 1:
        message['Precedence'] = 'bulk'
    for group in chunks(recipients, 100):
        if len(group) > 1:
            message['To'] = "undisclosed-recipients:;"
        else:
            message['To'] = ";".join(group)
        print("Sending email from {} to {} recipients".format(sender, len(group)))
        smtp.sendmail(sender, group, message.as_string())
    smtp.quit()
Exemplo n.º 7
0
def inject():
    ads = True
    first_visit = True
    dismissed_donation = False
    if 'ad-opt-out' in request.cookies:
        ads = False
    if g.do_not_track:
        ads = False
    if not _cfg("project_wonderful_id"):
        ads = False
    if request.cookies.get('first_visit') != None:
        first_visit = False
    if request.cookies.get('dismissed_donation') != None:
        dismissed_donation = True
    return {
        'mobile':
        g.mobile,
        'ua_platform':
        request.user_agent.platform,
        'analytics_id':
        _cfg("google_analytics_id"),
        'analytics_domain':
        _cfg("google_analytics_domain"),
        'disqus_id':
        _cfg("disqus_id"),
        'dnt':
        g.do_not_track,
        'ads':
        ads,
        'ad_id':
        _cfg("project_wonderful_id"),
        'root':
        _cfg("protocol") + "://" + _cfg("domain"),
        'domain':
        _cfg("domain"),
        'user':
        current_user,
        'len':
        len,
        'any':
        any,
        'following_mod':
        following_mod,
        'following_user':
        following_user,
        'admin':
        is_admin(),
        'oauth_providers':
        list_defined_oauths(),
        'wrap_mod':
        wrap_mod,
        'dumb_object':
        dumb_object,
        'first_visit':
        first_visit,
        'request':
        request,
        'locale':
        locale,
        'url_for':
        url_for,
        'strftime':
        strftime,
        'datetime':
        datetime,
        'site_name':
        _cfg('site-name'),
        'support_mail':
        _cfg('support-mail'),
        'source_code':
        _cfg('source-code'),
        'irc_channel':
        _cfg('irc-channel'),
        'donation_link':
        _cfg('donation-link'),
        'donation_header_link':
        _cfgb('donation-header-link') if not dismissed_donation else False,
        'registration':
        _cfgb('registration')
    }