Beispiel #1
0
    def __getitem__(self, buddy):
        '''
        This is where the magic happens -- if the buddy does not exist,
        then a new 'blank' buddy will be returned with only the name and
        protocol set.

        @param buddy    the name to use for the buddy
        '''
        if not buddy: raise NameError

        if (util.is_email(buddy) and self in (self.protocol.buddies, self.protocol.circle_buddies)):
            try:
                return dict.__getitem__(self, buddy)
            except KeyError:
                return self.setdefault(str(buddy),
                                       self.DefaultClass(name=buddy, msn=self.protocol))
        else:
            is_sms = validate_sms(buddy)
            is_int = funcs.isint(buddy)

            if (is_sms or is_int) and self is self.protocol.m_buddies:
                try:
                    return dict.__getitem__(self, buddy)
                except KeyError:
                    return dict.setdefault(self, str(buddy),
                                           self.DefaultClass(name=buddy, msn=self.protocol))

        log.critical('Unknown buddy was requested: %r, %r', type(buddy), buddy)
        raise KeyError(buddy)
Beispiel #2
0
    def auth(self, cookie=None, username=None, password=None,cache=True):
        if cookie is not None and type(cookie) == str:
            self.__cookie = util.cookie2dic(cookie)
            self.__session.cookies.update(self.__cookie)
            if cache:
                self.__save_cookie()
        if username is not None and password is not None:
            r1=self.__get(self.__DOMAIN)
            d = pq(r1.text)
            xsrf = d("input[name=_xsrf]").val()

            kw=None
            if util.is_email(username):
                kw = "email"
            if util.is_phone(username):
                kw = "phone_num"
            data={kw: username, "password": password, "captcha_type": "cn","_xsrf":xsrf}
            r = self.__post("/login/" + kw, data)
            self.__cookie = r.cookies
            if cache:
                self.__save_cookie()
            return True
        if os.path.exists(self.__CACHE_NAME):
            self.__cookie =self.__get_cookie()
            self.__session.cookies.update(self.__cookie)
Beispiel #3
0
def profile(request, id):
    try:
        person = Person.objects.get(id = id)
    except Person.DoesNotExist:
        return HttpResponseNotFound("Bad Id")
    if request.user.id != person.user.id:
        return HttpResponseForbidden('Not for your eyes')
    if request.method == 'GET':
        return {'person' : person, 'services' : Service.objects.all()}
    elif request.method == 'PUT':
        errors = {}
        try:
            with transaction.commit_on_success():
                data = json.loads(request.raw_post_data)
                if int(data['id']) != person.id:
                    return HttpResponseForbidden('Not for your eyes')
                #Save the info
                updated = data['person']
                person.description = updated['description']
                person.name = updated['name']
                person.ok_contact = updated['ok_contact']
                em = updated['email']
                if not is_email(em):
                    errors['email'] = 'Enter a valid email'
                else:
                    person.user.email = em
                ph = updated['phone']
                if not is_phone(ph):
                    errors['phone'] = 'Enter a valid phone number (xxx-xxx-xxxx)'
                else:
                    person.phone = ph
                person.beer = updated['beer']
            
                person.lat = Decimal(updated['lat'])
                person.lng = Decimal(updated['lng'])

                existing_services = set([s.name for s in person.services.all()])
                updated_services = set([s['name'] for s in updated['services']])

                to_add = updated_services - existing_services
                to_delete = existing_services - updated_services                
                for a in to_add:
                    try:
                        person.services.add(Service.objects.get(name = a))
                    except Service.DoesNotExist:
                        pass
                for d in to_delete:
                    try:
                        person.services.remove(Service.objects.get(name = d))
                    except Service.DoesNotExist:
                        pass
                person.save()
                person.user.save()
        except ValueError:
            pass

        
        return {'person' : person, 'services' : Service.objects.all(), 'errors' : errors}
Beispiel #4
0
    def OnAddEmail(self, email):
        blist  = self.blist
        emails = blist.get_contact_info(self.info_key, 'email')
        emails = list(emails) if emails is not None else []

        if not is_email(email):
            MessageBox(_('Please enter a valid email address (ie: [email protected])'),
                       _('Invalid Email Address'), style = wx.ICON_ERROR)

        elif email in emails:
            MessageBox(_('That email is already registered with this buddy.'),
                       _('Add Email Address'))

        else:
            emails.append(email)
            blist.set_contact_info(self.info_key, 'email', emails)
            self.OnLoseFocus()
            return email
Beispiel #5
0
    def _wrapper(self, buddy_name_or_email, *a, **k):
        log.info('doing user search for %r', buddy_name_or_email)
        if util.is_email(buddy_name_or_email):
            email = buddy_name_or_email
            name = None
        else:
            name = buddy_name_or_email
            email = None

        def success(sent, recvd):
            log.info('got success for usersearch! %r, %r', sent, recvd)
            body = recvd.get('body', {})
            buddy_id = body.get('UserID', body.get('ContactID'))
            if buddy_id is None:
                log.error('buddy_id for %r not found! probably doesn\'t exist', buddy_name_or_email)
            f(self, buddy_id, *a, **k)

        self.api.user_search(username=name, email=email, success=success)
Beispiel #6
0
    def _wrapper(self, buddy_name_or_email, *a, **k):
        log.info('doing user search for %r', buddy_name_or_email)
        if util.is_email(buddy_name_or_email):
            email = buddy_name_or_email
            name = None
        else:
            name = buddy_name_or_email
            email = None

        def success(sent, recvd):
            log.info('got success for usersearch! %r, %r', sent, recvd)
            body = recvd.get('body', {})
            buddy_id = body.get('UserID', body.get('ContactID'))
            if buddy_id is None:
                log.error('buddy_id for %r not found! probably doesn\'t exist',
                          buddy_name_or_email)
            f(self, buddy_id, *a, **k)

        self.api.user_search(username=name, email=email, success=success)
Beispiel #7
0
    def OnAddEmail(self, email):
        blist = self.blist
        emails = blist.get_contact_info(self.info_key, 'email')
        emails = list(emails) if emails is not None else []

        if not is_email(email):
            MessageBox(_(
                'Please enter a valid email address (ie: [email protected])'),
                       _('Invalid Email Address'),
                       style=wx.ICON_ERROR)

        elif email in emails:
            MessageBox(_('That email is already registered with this buddy.'),
                       _('Add Email Address'))

        else:
            emails.append(email)
            blist.set_contact_info(self.info_key, 'email', emails)
            self.OnLoseFocus()
            return email
Beispiel #8
0
 def validate(self, _str):
     import util
     return util.is_email(_str)