コード例 #1
0
 def authenticate(self, request, username=None, orderid=None):
     try:
         if orderid:
             try:
                 if utils.is_future_ecom(request.client.client):
                     order = Order.objects.filter(
                         reference_order_id=orderid, state='pending_order')
                     if order:
                         order = order[0]
                     else:
                         return None
                 else:
                     order = Order.objects.get(id=orderid)
             except Order.DoesNotExist:
                 return None
             profile = None
             if utils.is_valid_email(username):
                 input_type = "email"
             elif utils.is_valid_mobile(username):
                 input_type = "mobile"
             else:
                 input_type = "id"
             if input_type == "email":
                 try:
                     email = Email.objects.get(email=username)
                     profile = email.user
                 except Email.DoesNotExist:
                     return None
             if input_type == "mobile":
                 try:
                     phone = Phone.objects.get(phone=username)
                     profile = phone.user
                 except Phone.DoesNotExist:
                     return None
             if profile:
                 if order.user == profile:
                     return profile.user
         return None
     except Profile.DoesNotExist:
         return None
     return None
コード例 #2
0
 def authenticate(self, request, username=None, orderid=None):
     try:
         if orderid:
             try:
                 if utils.is_future_ecom(request.client.client):
                     order = Order.objects.filter(reference_order_id=orderid,state='pending_order')
                     if order:
                         order = order[0]
                     else:
                         return None
                 else:
                     order = Order.objects.get(id=orderid)
             except Order.DoesNotExist:
                 return None
             profile = None
             if utils.is_valid_email(username):
                 input_type = "email"
             elif utils.is_valid_mobile(username):
                 input_type = "mobile"
             else:
                 input_type = "id"
             if input_type == "email":
                 try:
                     email = Email.objects.get(email=username)
                     profile = email.user              
                 except Email.DoesNotExist:
                     return None
             if input_type == "mobile":
                 try:
                     phone = Phone.objects.get(phone=username)
                     profile = phone.user
                 except Phone.DoesNotExist:
                     return None
             if profile:
                 if order.user == profile:
                     return profile.user
         return None
     except Profile.DoesNotExist:
         return None
     return None
コード例 #3
0
    def authenticate(self, username=None, password=None, **kwargs):
        try:
            profile = None
            if utils.is_valid_email(username):
                input_type = "email"
            elif utils.is_valid_mobile(username):
                input_type = "mobile"
            else:
                input_type = "id"
            if input_type == 'email':
                try:
                    email = Email.objects.get(email=username)
                    profile = email.user
                except Email.DoesNotExist:
                    return None
            if input_type == 'mobile':
                try:
                    phone = Phone.objects.get(phone=username)
                    profile = phone.user
                except Phone.DoesNotExist:
                    return None
            if profile:
                #profile = Profile.objects.get(primary_phone=username)
                salt = profile.salt
                passcode = profile.passcode

                generated_passcode = hashlib.md5(salt).hexdigest()
                generated_passcode += hashlib.md5(
                    password.encode('ascii', 'ignore')).hexdigest()
                generated_passcode = hashlib.md5(
                    generated_passcode).hexdigest()
                if passcode == generated_passcode:
                    return profile.user
            return None
        except Profile.DoesNotExist:
            return None
        return None
コード例 #4
0
    def authenticate(self, username=None, password=None, **kwargs):
        try:
            profile = None
            if utils.is_valid_email(username):
                input_type = "email"
            elif utils.is_valid_mobile(username):
                input_type = "mobile"
            else:
                input_type = "id"
            if input_type == 'email':
                try:
                    email = Email.objects.get(email=username)
                    profile = email.user              
                except Email.DoesNotExist:
                    return None
            if input_type == 'mobile':
                try:
                    phone = Phone.objects.get(phone=username)
                    profile = phone.user
                except Phone.DoesNotExist:
                    return None
            if profile:
            #profile = Profile.objects.get(primary_phone=username)
                salt = profile.salt
                passcode = profile.passcode

                generated_passcode = hashlib.md5(salt).hexdigest()
                generated_passcode += hashlib.md5(password.encode(
                    'ascii', 'ignore')).hexdigest()
                generated_passcode = hashlib.md5(generated_passcode).hexdigest()
                if passcode == generated_passcode:
                    return profile.user
            return None
        except Profile.DoesNotExist:
            return None
        return None
コード例 #5
0
def migrate_subscriptions():
    start = datetime(day=1, month=4, year=2011)
    subscripions_qs = FtbDealsLogin.objects.filter(registration_time__gte=start)
    newsletter = NewsLetter.objects.get(pk=2)
    for subscription in subscripions_qs:
        if SubscriptionSync.objects.filter(ext_id=subscription.id):
            #print 'Skipping %s: Already synced' % subscription.id
            continue
        email = subscription.email_address or ''
        mobile = subscription.mobile_number or ''
        name = subscription.register_name or ''
        if len(email) > 50 or len(name) > 100:
            #print 'Skipping %s: Long data' % subscription.id
            continue

        source = 'atg'
        if subscription.facebook_user == 1:
            source = 'facebook-atg'

        profile = None

        is_valid_email = False
        e = None
      	if utils.is_valid_email(email):
            is_valid_email = True
            try:
                e = Email.objects.get(email=email)
                profile = e.user
            except Email.DoesNotExist:
                pass

        is_valid_mobile = False
        m = None                 
        if utils.is_valid_mobile(mobile):
            is_valid_mobile = True
            try:
                m = Phone.objects.get(phone=mobile)
                profile = m.user
            except Phone.DoesNotExist:
                pass

        if not is_valid_mobile and is_valid_email:
            #print 'Skipping %s, %s, %s: Invalid data' % (email, mobile, name)
            continue

        if not profile:
            # Create a new profile in our system
            if is_valid_email:
                usr, profile = utils.get_or_create_user(email, email,
                                   password=None, first_name=name)
            if not is_valid_email:
                usr, profile = utils.get_or_create_user(mobile, '',
                                   password=None, first_name=name)

        if not profile:
            # Still not able to create profile
            #print 'Skipping %s, %s, %s: No profile' % (email, mobile, name)
            continue

	if not e:
            try:
                e = Email.objects.get(email=email)
            except Email.DoesNotExist:
                # Create a new email
                e = Email()
                e.user = profile
                e.email = email
                e.save()

        if not m:
            try:
                m = Phone.objects.get(phone=mobile)
            except Phone.DoesNotExist:
                m = Phone()
                m.user = profile
                m.phone = mobile
                m.save()

        # Create an entry into the subscription table 
        subscr = DailySubscription()
        subscr.email_alert_on = e
        subscr.sms_alert_on = m
        subscr.source = source
        subscr.timestamp = subscription.registration_time
        subscr.newsletter = newsletter
        subscr.save()

        link = SubscriptionSync()
        link.ext_id = subscription.id
        link.account = 'futurebazaar'
        link.save() 
コード例 #6
0
ファイル: migrate-subscriptions.py プロジェクト: daasara/riba
def migrate_subscriptions():
    start = datetime(day=1, month=4, year=2011)
    subscripions_qs = FtbDealsLogin.objects.filter(
        registration_time__gte=start)
    newsletter = NewsLetter.objects.get(pk=2)
    for subscription in subscripions_qs:
        if SubscriptionSync.objects.filter(ext_id=subscription.id):
            #print 'Skipping %s: Already synced' % subscription.id
            continue
        email = subscription.email_address or ''
        mobile = subscription.mobile_number or ''
        name = subscription.register_name or ''
        if len(email) > 50 or len(name) > 100:
            #print 'Skipping %s: Long data' % subscription.id
            continue

        source = 'atg'
        if subscription.facebook_user == 1:
            source = 'facebook-atg'

        profile = None

        is_valid_email = False
        e = None
        if utils.is_valid_email(email):
            is_valid_email = True
            try:
                e = Email.objects.get(email=email)
                profile = e.user
            except Email.DoesNotExist:
                pass

        is_valid_mobile = False
        m = None
        if utils.is_valid_mobile(mobile):
            is_valid_mobile = True
            try:
                m = Phone.objects.get(phone=mobile)
                profile = m.user
            except Phone.DoesNotExist:
                pass

        if not is_valid_mobile and is_valid_email:
            #print 'Skipping %s, %s, %s: Invalid data' % (email, mobile, name)
            continue

        if not profile:
            # Create a new profile in our system
            if is_valid_email:
                usr, profile = utils.get_or_create_user(email,
                                                        email,
                                                        password=None,
                                                        first_name=name)
            if not is_valid_email:
                usr, profile = utils.get_or_create_user(mobile,
                                                        '',
                                                        password=None,
                                                        first_name=name)

        if not profile:
            # Still not able to create profile
            #print 'Skipping %s, %s, %s: No profile' % (email, mobile, name)
            continue

        if not e:
            try:
                e = Email.objects.get(email=email)
            except Email.DoesNotExist:
                # Create a new email
                e = Email()
                e.user = profile
                e.email = email
                e.save()

        if not m:
            try:
                m = Phone.objects.get(phone=mobile)
            except Phone.DoesNotExist:
                m = Phone()
                m.user = profile
                m.phone = mobile
                m.save()

        # Create an entry into the subscription table
        subscr = DailySubscription()
        subscr.email_alert_on = e
        subscr.sms_alert_on = m
        subscr.source = source
        subscr.timestamp = subscription.registration_time
        subscr.newsletter = newsletter
        subscr.save()

        link = SubscriptionSync()
        link.ext_id = subscription.id
        link.account = 'futurebazaar'
        link.save()