Пример #1
0
    def mw_request_duoUsage(request):
        from a_citizen_02.models import a_citizen_02
        if request.META['HTTP_HOST'] == settings.FACEBOOK_HTTP_HOST:
            request.META['duo_Usage']                   = 'FACEBOOK'
            request.META['duo_mapHost']                 = settings.DIRECT_HTTP_HOST
            request.META['duo_Direct']                  = False
            request.META['duo_FormActionPrepend']       = 'http://apps.new.facebook.com'        # 'http://apps.facebook.com'
            request.META['duo_citizen']                 = a_citizen_02.getCurrentFromFacebook(request)
            
            # If 'duo_citizen' returned isnt an instance of a_citizen_02 then getCurrentFromFacebook failed.
            # Probably because the current FB user isn't logged in and hasn't given access to the application.
            # In that case redirect them to the output returned from getCurrentFromFacebook as this is the
            # standard facebook login url for this app
            if not isinstance(request.META['duo_citizen'], a_citizen_02):
                return request.META['duo_citizen']
        
            # Force language to Facebook users preference
            if 'fb_sig_locale' in request.POST:
                from django.utils import translation
                translation.activate(request.POST['fb_sig_locale'])
                request.LANGUAGE_CODE = translation.get_language()
        
        elif request.META['HTTP_HOST'] == settings.DIRECT_HTTP_HOST or request.META['HTTP_HOST'] == settings.DIRECT_HTTP_HOST[4:]:
            request.META['duo_Usage']                 = 'DIRECT'
            request.META['duo_mapHost']               = request.META['HTTP_HOST']
            request.META['duo_Direct']                = True
            request.META['duo_FormActionPrepend']     = 'http://'+request.META['HTTP_HOST']
            request.META['duo_citizen']               = a_citizen_02.getCurrentFromDirect(request)
#            print "*** request.META['duo_citizen'] = %s" % (request.META['duo_citizen'])
        else:
            contextDict = {}
            outString = "Unknown request.META['HTTP_HOST'] = (%s), settings.DIRECT_HTTP_HOST = (%s)"  % (request.META['HTTP_HOST'], settings.DIRECT_HTTP_HOST)
            contextDict['main_1'] = outString

            # rest is a hack to allow this to continue gracefully. previously to this it would error out into an Apache error which
            # really didn't help find the problem.
            from a_base_02.models import secDict
            request.META['citizen_rights']            = secDict['s_guest']
            request.META['duo_Usage']                 = 'DIRECT'
            request.META['duo_mapHost']               = request.META['HTTP_HOST']
            request.META['duo_Direct']                = True
            request.META['duo_FormActionPrepend']     = 'http://'+request.META['HTTP_HOST']
            request.META['duo_citizen']               = a_citizen_02.getCurrentFromDirect(request)
        
            return a_base_02.processTemplate_01(request, 'BASE.html', contextDict, mode='view')   
        
        engine_permissions.setUserPermissions(request)
   
        return None
Пример #2
0
def a_citizen_02_VIEW_Register(request, cit_id='', rv1='', rv2=''):
    
    
    contextDict         = {'vTitle':'New Citizen Registration'}    
    action_view         = 'a_citizen_02_VIEW_Register'
    action_kwargs       = {}

    # Later if this is non zero it contains the citizen_id of the user who issued this invite
    inviteRegistration = 0
    
    if cit_id and rv1 and rv2:
        # Determine if the request exists
        try:
            friend = a_citizen_02.objects.get(pk=cit_id)
            qs = a_friends_externalRequest_01.objects.get(citizen=friend, rand_value1=rv1, rand_value2=rv2)
            inviteRegistration  = cit_id
            action_kwargs       = {'cit_id':cit_id,'rv1':rv1,'rv2':rv2,}
        except ObjectDoesNotExist:
            pass
        
    form_action         = a_citizen_02.build_form_action(request, action_view, action_kwargs)
    
    form_class          = Form_a_citizen_02_registerNewUser
    form_object         = None                                                                       
    form_template       = 'F_register.html'
    form_context_dict   = {}
    form_build_dict     = {}                                                                                    
    result_dict         = a_citizen_02.get_result_dict(request, form_action, form_class, form_object, form_template, form_context_dict, form_build_dict, resetFormOnSuccess=True)    
    
    if result_dict['success']:
        from a_mgrApplication_03.views import a_mgrApplication_03_newCitizenDefaultSubscriptions
        instance = result_dict['formInstance'].save(commit=False) 

        # -----------------------------------------------------
        # process form results
        # conversion: args[0] = instance, args[1] = request, args[2] = result_dict['cleanData'], args[3] = redirectReason   
        
        # save user object
        user = User.objects.create_user(result_dict['cleanData']['userName'], result_dict['cleanData']['email'], result_dict['cleanData']['pass1'])
        user.first_name = result_dict['cleanData']['firstName']
        user.last_name  = result_dict['cleanData']['lastName']
        user.save()
        
        # create citizen object
        citizenInstance =  a_citizen_02.birthNewCitizen(request, direct=user, reasonJoined=result_dict['cleanData']['reasonJoined'])
    
        a_citizen_02.sendUserMessage(request, "Welcome to %s." % (settings.SITE_NAME), toCitizen=citizenInstance, body="Please validate your email address by clicking on the link in the email that was sent to %s."%(user.email), type='sys')
        
        # Manually log this user in
        user = authenticate(username=result_dict['cleanData']['userName'], password=result_dict['cleanData']['pass1'])        
        if user is not None and user.is_active:
            login(request, user)   
            
        # auto subscribe user to all apps
        request.META['duo_citizen'] = a_citizen_02.getCurrentFromDirect(request)            
        a_mgrApplication_03_newCitizenDefaultSubscriptions(request)
                
        # Generate email validation instance and put equivalent url into the mail
        a_mgrEmailValidate_02_instance = a_mgrEmailValidate_02()
        a_mgrEmailValidate_02_instance.user = user
        a_mgrEmailValidate_02_instance.save(request=request)
        
        invite_friendRequest = ''
        if inviteRegistration:
            a_friends_externalRequest_01.approve(request, friend, rv1, rv2, citizenInstance)
            invite_friendRequest = 'Your friendship with %s is ready pending approval from them.' % (friend)
        
        subject                = "Welcome to %s" % (settings.SITE_NAME)
        bodyTemplate           = 'E_welcome.html'
        bodyContextDict        = {
                                    'BASE_URL'              : settings.DIRECT_HTTP_HOST, 
                                    'validtionURL'          : a_mgrEmailValidate_02_instance.returnValidationUrl(request),
                                    'invite_friendRequest'  : invite_friendRequest,
                                    'site_name'             : settings.SITE_NAME,
                                 }
    
        a_citizen_02.sendEmailEWrapper(request, subject, [user.email], bodyTemplate=bodyTemplate, bodyContextDict=bodyContextDict)   
        # -----------------------------------------------------

        return a_citizen_02.redirectView(request, 'a_citizen_02_VIEW_Welcome', 'welcome')
    else:
        contextDict['main_1'] = result_dict['out']
        return a_citizen_02.processTemplate_01(request, 'BASE.html', contextDict, mode='view')