Example #1
0
    def _register_sms(self, n):
        # validate phone number syntax
        if not n or len(n.strip()) == 0:
            log.debug("number empty - %s" % n)
            return c2s.RegistrationResponse.STATUS_INVALID_USERNAME

        phone = phone_num = n.strip()
        # exclude the initial plus to verify the digits
        if (phone[0] == '+'):
            phone_num = phone[1:]

        # not all digits...
        if not phone_num.isdigit():
            log.debug("number is not all-digits - %s" % phone_num)
            return c2s.RegistrationResponse.STATUS_INVALID_USERNAME

        # replace double-zero with plus
        if phone[0:2] == '00':
            phone = '+' + phone[2:]

        # insert validation record
        # TODO do not use directly - let the storage module do it
        valdb = database.validations(self.broker.db)
        userid = utils.sha1(phone)

        # throttling :P
        if valdb.get_code(userid, True):
            return c2s.RegistrationResponse.STATUS_THROTTLING

        userid += utils.rand_str(8, utils.CHARSBOX_AZN_UPPERCASE)
        ret = valdb.update(userid)
        if ret[0] > 0:
            # send SMS
            code = ret[1]
            sms_from = self.config['registration']['from']

            if self.config['registration']['android_emu']:
                # android emulation
                import os
                os.system('adb emu sms send %s %s' % (sms_from, code))
            else:
                # send sms
                from nexmomessage import NexmoMessage
                msg = {
                    'reqtype' : 'json',
                    'username' : self.config['registration']['nx.username'],
                    'password': self.config['registration']['nx.password'],
                    'from': sms_from,
                    'to': phone
                }
                sms = NexmoMessage(msg)
                # FIXME send just the code for now
                sms.set_text_info(code)
                js = sms.send_request()
                log.debug("sms sent [response=%s]" % js)

            return c2s.RegistrationResponse.STATUS_CONTINUE
        else:
            return c2s.RegistrationResponse.STATUS_ERROR
Example #2
0
    def _register_sms(self, n):
        # validate phone number syntax
        if not n or len(n.strip()) == 0:
            log.debug("number empty - %s" % n)
            return c2s.RegistrationResponse.STATUS_INVALID_USERNAME

        phone = phone_num = n.strip()
        # exclude the initial plus to verify the digits
        if (phone[0] == '+'):
            phone_num = phone[1:]

        # not all digits...
        if not phone_num.isdigit():
            log.debug("number is not all-digits - %s" % phone_num)
            return c2s.RegistrationResponse.STATUS_INVALID_USERNAME

        # replace double-zero with plus
        if phone[0:2] == '00':
            phone = '+' + phone[2:]

        # insert validation record
        # TODO do not use directly - let the storage module do it
        valdb = database.validations(self.broker.db)
        userid = utils.sha1(phone)

        # throttling :P
        if valdb.get_code(userid, True):
            return c2s.RegistrationResponse.STATUS_THROTTLING

        userid += utils.rand_str(8, utils.CHARSBOX_AZN_UPPERCASE)
        ret = valdb.update(userid)
        if ret[0] > 0:
            # send SMS
            code = ret[1]
            sms_from = self.config['registration']['from']

            if self.config['registration']['android_emu']:
                # android emulation
                import os
                os.system('adb emu sms send %s %s' % (sms_from, code))
            else:
                # send sms
                from nexmomessage import NexmoMessage
                msg = {
                    'reqtype': 'json',
                    'username': self.config['registration']['nx.username'],
                    'password': self.config['registration']['nx.password'],
                    'from': sms_from,
                    'to': phone
                }
                sms = NexmoMessage(msg)
                # FIXME send just the code for now
                sms.set_text_info(code)
                js = sms.send_request()
                log.debug("sms sent [response=%s]" % js)

            return c2s.RegistrationResponse.STATUS_CONTINUE
        else:
            return c2s.RegistrationResponse.STATUS_ERROR
Example #3
0
 def extra_storage(self, uids, mime, content, name=None):
     if not name:
         name = utils.rand_str(40)
     filename = os.path.join(self._extra_path, name)
     f = open(filename, 'w')
     f.write(content)
     f.close()
     return (filename, name)
Example #4
0
 def extra_storage(self, uids, mime, content, name = None):
     if not name:
         name = utils.rand_str(40)
     filename = os.path.join(self._extra_path, name)
     f = open(filename, 'w')
     f.write(content)
     f.close()
     return (filename, name)
Example #5
0
 def revalidate(self):
     valdb = database.validations(self.broker.db)
     userid = self.userid[:utils.USERID_LENGTH] + utils.rand_str(8, utils.CHARSBOX_AZN_UPPERCASE)
     log.debug("revalidating user %s as %s" % (self.userid, userid))
     ret = valdb.update(userid)
     if ret[0] > 0:
         return ret[1]
     else:
         return False
Example #6
0
 def revalidate(self):
     valdb = database.validations(self.broker.db)
     userid = self.userid[:utils.USERID_LENGTH] + utils.rand_str(
         8, utils.CHARSBOX_AZN_UPPERCASE)
     log.debug("revalidating user %s as %s" % (self.userid, userid))
     ret = valdb.update(userid)
     if ret[0] > 0:
         return ret[1]
     else:
         return False
Example #7
0
    def login(self, request, data):
        '''Create a channel for the requested userid.'''
        try:
            auth = data['auth']
            userid = token.verify_user_token(auth, self.broker.keyring, self.broker.fingerprint)
        except:
            import traceback
            traceback.print_exc()
            log.debug("token verification failed!")
            return utils.unauthorized(request)

        sid = utils.rand_str(40, utils.CHARSBOX_AZN_LOWERCASE)
        ch = EndpointChannel(self, sid, userid)
        self.broker.register_user_consumer(userid, ch, supports_mailbox=True, pending=False)
        log.debug("user %s logged in." % (userid, ))

        self.channels[sid] = ch
        return { 'id' : sid }
Example #8
0
    def login(self, request, data):
        '''Create a channel for the requested userid.'''
        try:
            auth = data['auth']
            userid = token.verify_user_token(auth, self.broker.keyring,
                                             self.broker.fingerprint)
        except:
            import traceback
            traceback.print_exc()
            log.debug("token verification failed!")
            return utils.unauthorized(request)

        sid = utils.rand_str(40, utils.CHARSBOX_AZN_LOWERCASE)
        ch = EndpointChannel(self, sid, userid)
        self.broker.register_user_consumer(userid,
                                           ch,
                                           supports_mailbox=True,
                                           pending=False)
        log.debug("user %s logged in." % (userid, ))

        self.channels[sid] = ch
        return {'id': sid}
Example #9
0
    def extra_storage(self, uids, mime, content, name=None):
        '''Store a big file in the storage system.'''
        # TODO do not store files with same md5sum, they are supposed to be duplicates

        if not name:
            name = utils.rand_str(40)
        # content to filesystem
        filename = os.path.join(self._extra_path, name)
        f = open(filename, 'w')
        f.write(content)
        f.close()

        # calculate md5sum for file
        # this is intentionally done to verify that the file is not corruputed on disk
        md5sum = utils.md5sum(filename)

        # store in attachments
        for rcpt in uids:
            # TODO check insert errors
            self.attdb.insert(rcpt[:utils.USERID_LENGTH], name, mime, md5sum)

        return (filename, name)
Example #10
0
    def extra_storage(self, uids, mime, content, name = None):
        '''Store a big file in the storage system.'''
        # TODO do not store files with same md5sum, they are supposed to be duplicates

        if not name:
            name = utils.rand_str(40)
        # content to filesystem
        filename = os.path.join(self._extra_path, name)
        f = open(filename, 'w')
        f.write(content)
        f.close()

        # calculate md5sum for file
        # this is intentionally done to verify that the file is not corruputed on disk
        md5sum = utils.md5sum(filename)

        # store in attachments
        for rcpt in uids:
            # TODO check insert errors
            self.attdb.insert(rcpt[:utils.USERID_LENGTH], name, mime, md5sum)

        return (filename, name)
Example #11
0
 def message_id(self):
     return utils.rand_str(30)
Example #12
0
 def message_id(self):
     return utils.rand_str(30)