Ejemplo n.º 1
0
 def parse (self, message):
     provider = Provider.by_mobile(message.peer)
     if provider:
         message.sender = provider.user
     else:
         message.sender = None
     message.was_handled = False
Ejemplo n.º 2
0
 def parse (self, message):
     provider = Provider.by_mobile(message.peer)
     if provider:
         message.sender = provider.user
     else:
         message.sender = None
     message.was_handled = False
Ejemplo n.º 3
0
    def join (self, message, code, last_name, first_name, username=None):
        try:
            clinic = Facility.objects.get(codename__iexact=code)
        except Facility.DoesNotExist:
            raise HandlerFailed(_("The given password is not recognized."))

        if username is None:
            # FIXME: this is going to run into charset issues
            username = (first_name[0] + last_name).lower()
        else:
            # lower case usernames ... also see FIXME above?
            username = username.lower()
        if User.objects.filter(username__iexact=username).count():
            raise HandlerFailed(_(
                "Username '%s' is already in use. " +
                "Reply with: JOIN <last> <first> <username>") % username)

        # todo: use the more generic get_description if possible
        info = {
            "username"   : username,
            "user_first_name" : first_name.title(),
            "user_last_name"  : last_name.title()
        }
        user = User(username=username, first_name=first_name.title(), last_name=last_name.title())
        user.save()

        mobile = message.peer
        in_use = Provider.by_mobile(mobile)
        provider = Provider(mobile=mobile, user=user,
                            clinic=clinic, active=not bool(in_use))
        provider.save()

        if in_use:
            info.update({
                "user_last_name"  : in_use.user.last_name.upper(),
                "user_first_name" : in_use.user.first_name,
                "other"      : in_use.user.username,
                "mobile"     : mobile,
                "clinic"     : provider.clinic.name,
            })
            #message.respond(_(
            #    "Phone %(mobile)s is already registered to %(user_last_name)s, " +
            #   "%(user_first_name)s. Reply with 'CONFIRM %(username)s'.") % info)
            self.int2dom(message, _(
                "Phone %(mobile)s is already registered to %(user_last_name)s, " +
                "%(user_first_name)s. Reply with 'CONFIRM %(username)s'.") % info)
        else:
            info.update({
                "id"        : provider.id,
                "mobile"    : mobile,
                "clinic"    : provider.clinic.name,
                "user_last_name" : last_name.upper()
            })
            self.respond_to_join(message, info)
        log(provider, "provider_registered")            
        return True
Ejemplo n.º 4
0
    def join (self, message, code, last_name, first_name, username=None):
        try:
            clinic = Facility.objects.get(codename__iexact=code)
        except Facility.DoesNotExist:
            raise HandlerFailed(_("The given password is not recognized."))

        if username is None:
            # FIXME: this is going to run into charset issues
            username = (first_name[0] + last_name).lower()
        else:
            # lower case usernames ... also see FIXME above?
            username = username.lower()
        if User.objects.filter(username__iexact=username).count():
            raise HandlerFailed(_(
                "Username '%s' is already in use. " +
                "Reply with: JOIN <last> <first> <username>") % username)

        # todo: use the more generic get_description if possible
        info = {
            "username"   : username,
            "user_first_name" : first_name.title(),
            "user_last_name"  : last_name.title()
        }
        user = User(username=username, first_name=first_name.title(), last_name=last_name.title())
        user.save()

        mobile = message.peer
        in_use = Provider.by_mobile(mobile)
        provider = Provider(mobile=mobile, user=user,
                            clinic=clinic, active=not bool(in_use))
        provider.save()

        if in_use:
            info.update({
                "user_last_name"  : in_use.user.last_name.upper(),
                "user_first_name" : in_use.user.first_name,
                "other"      : in_use.user.username,
                "mobile"     : mobile,
                "clinic"     : provider.clinic.name,
            })
            #message.respond(_(
            #    "Phone %(mobile)s is already registered to %(user_last_name)s, " +
            #   "%(user_first_name)s. Reply with 'CONFIRM %(username)s'.") % info)
            self.int2dom(message, _(
                "Phone %(mobile)s is already registered to %(user_last_name)s, " +
                "%(user_first_name)s. Reply with 'CONFIRM %(username)s'.") % info)
        else:
            info.update({
                "id"        : provider.id,
                "mobile"    : mobile,
                "clinic"    : provider.clinic.name,
                "user_last_name" : last_name.upper()
            })
            self.respond_to_join(message, info)
        log(provider, "provider_registered")            
        return True
Ejemplo n.º 5
0
 def parse (self, message):
     """parser """
     # allow authentication to occur when http tester is used
     if message.peer[:3] == '233':
         mobile = "+" + message.peer
     else:
         mobile = message.peer 
     provider = Provider.by_mobile(mobile)
     if provider:
         message.sender = provider.user
     else:
         message.sender = None
     message.was_handled = False