Example #1
0
class Validations:
    def __init__(self):
        self.config = ReConfig()
        self.OUR_DOMAIN = self.config.get_ourdomain()

    def re_readconfig(self):
        del self.config
        self.config = ReConfig()
        self.OUR_DOMAIN = self.config.get_ourdomain()

    def getdomain(self, a):
        return a.split('@')[-1]

    def getuserid(self, a):
        return a.split('@')[0]

    def isourdomain(self, a):
        return self.getdomain(a) == self.OUR_DOMAIN

    def valid_uuid4(self, a):
        userid = self.getuserid(a)
        try:
            val = uuid.UUID(userid, version=4)
        except ValueError:
            # If it's a value error, then the string
            # is not a valid hex code for a UUID.
            return False

        # If the uuid_string is a valid hex code,
        # but an invalid uuid4,
        # the UUID.__init__ will convert it to a
        # valid uuid4. This is bad for validation purposes.
        return val.hex == userid

    def isregistereduser(self, a):
        """ check whether the user address is a registered one or generated one """
        return not self.valid_uuid4(a)
Example #2
0
readdress_configs = ReConfig()
support_mail = readdress_configs.ConfigSectionMap('SUPPORT')['SUPPORT_MAIL']
feedback_mail = readdress_configs.ConfigSectionMap('FEEDBACK')['FEEDBACK_MAIL']
contact_mail = readdress_configs.ConfigSectionMap('CONTACT')['CONTACT_MAIL']

supportlist = [support_mail, feedback_mail, contact_mail]

#class for all db operations using mongodb
db = dbops.MongoORM()

#instanttiate class for common validations
valids = validations.Validations()

#below regex objs are for handling new thread mails
taddrcomp = re.compile('([\w.-]+(#)[\w.-]+)@' +
                       readdress_configs.get_ourdomain())

subcomp = re.compile('#')

rclient = StrictRedis()
ps = rclient.pubsub()
ps.subscribe(['configmodified'])


def newmapaddr(a, n=None, setExpiry=None):
    sendInvite2User = False
    mapped = db.getmapped(a)
    if not mapped:
        ''' better to add ttl for this address '''
        mapped = uuid.uuid4().hex + '@' + readdress_configs.get_ourdomain()
        db.insertUser(a, mapped, n, setExpiry)
Example #3
0
import hmac
import base64
import datetime
import pluscodes
from tornado.log import logging, gen_log
from motor import MotorClient
from tornado.gen import coroutine
from redis import StrictRedis
from validate_email import validate_email
from validations import PhoneValidations
from tornado.httpclient import AsyncHTTPClient
from config import ReConfig

readdress_configs = ReConfig()
#default_configs = readdress_configs.ConfigSectionMap('DEFAULT')
OUR_DOMAIN = readdress_configs.get_ourdomain()
if OUR_DOMAIN is None:
    raise ValueError("OUR_DOMAIN Not configured")


class BaseHandler(tornado.web.RequestHandler):
    def validate(self, request):
        gen_log.info('authenticatepost for ' + request.path)
        authkey = self.settings['Mandrill_Auth_Key'][request.path].encode()
        if 'X-Mandrill-Signature' in request.headers:
            rcvdsignature = request.headers['X-Mandrill-Signature']
        else:
            gen_log.info('Invalid post from ' + request.remote_ip)
            return False
        data = 'https://' + OUR_DOMAIN + request.path
        argkeys = sorted(request.arguments.keys())