示例#1
0
 def authenticate(self, username=None, password=None, **kwargs):
    # get user by email or phone
    from utils import utils
    profile = utils.get_profile_by_email_or_phone(username)
    if not profile:
        return None
    if profile.user.check_password(password):
        return profile.user
    return None
示例#2
0
 def authenticate(self, username=None, password=None, **kwargs):
     # get user by email or phone
     from utils import utils
     profile = utils.get_profile_by_email_or_phone(username)
     if not profile:
         return None
     if profile.user.check_password(password):
         return profile.user
     return None
示例#3
0
def franchise_signup(request):
    params = request.POST
    username = params.get('username','').strip()
    dealer_id = params.get('dealer_id','').strip()
    dealer_code = params.get('dealer_code','').strip()
    password = params.get('password','').strip()
    error = ''
    
    if not utils.is_valid_email(username):
        error = 'Enter a valid e-mail address.'
    else:
        error = validate_username_and_password(username, password, password)
    
    if not error:
        profile = utils.get_profile_by_email_or_phone(username)
        if profile:
            error = 'Sorry, "%s" profile is not available' % username
            user, profile = utils.get_or_create_user(username,'',password)
            print "user--->",user.id,", profile--->",profile.id
            
        else:
            if network_or_franchise_email(username):
                error = "Network or ICW related to this email already exists"
            else:
                if is_user_entry(username):
                    error = "Email already exists in the database"
                else:
                    try:
                        logged_in_network = Network.objects.get(user=request.user)
                        #Some dcode and d-ids already on production which are same. Hence filter and not equal to 0 check
                        franchise_did = Franchise.objects.filter(network=logged_in_network.parent_network, dealer_id = dealer_id)
                        if franchise_did.count() != 0:
                            error = 'Dealer-ID already exists'
                        if not error:
                            franchise_dcode = Franchise.objects.filter(network=logged_in_network.parent_network, dealer_code = dealer_code)
                            if franchise_dcode.count() != 0:
                                error = 'Dealer-CODE already exists'
                    except Network.DoesNotExist:
                        error = 'Please logout and login again.'
    if not error:
        #Add User in first auth-users   / profiles/ email/ phone/
        user, profile = utils.get_or_create_user(username,'',password)
        franchise = Franchise(user=user,network=logged_in_network.parent_network,role='agent', dealer_id = dealer_id, dealer_code = dealer_code)
        franchise.save()
        message = "ICW '%s' added under '%s' network." % (user, logged_in_network)
    
    if error:
        response = dict(status='failed', html=error)
    else:
        response = dict(status='success', html = message)
    return HttpResponse(simplejson.dumps(response))