Exemplo n.º 1
0
def a_citizen_02_VIEW_AnotherEmailValidation(request):
    
    contextDict = {}    
    if not request.META['duo_citizen'].directEmailValidated: 
        citizen = request.META['duo_citizen']
          
        # Generate email validation instance and put equivalent url into the mail
        a_mgrEmailValidate_02_instance = a_mgrEmailValidate_02()
        a_mgrEmailValidate_02_instance.user = citizen.direct
        a_mgrEmailValidate_02_instance.save(request=request)
        
        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'  : '',
                                    'site_name'             : settings.SITE_NAME,
                                 }
    
        a_citizen_02.sendEmailEWrapper(request, subject, [citizen.direct.email], bodyTemplate=bodyTemplate, bodyContextDict=bodyContextDict) 

        result_text = 'Email validation Email sent to %s' % (citizen.direct.email)
        contextDict = {'vTitle':'Success'}    
    else:
        result_text = 'Email validation Email NOT sent. Your email address is already validated'
        contextDict = {'vTitle':'Error'}    

    contextDict['main_1'] = a_citizen_02.processTemplate_01(request,'a_citizen_02/templates/R_preferences.html',{'result_text':result_text})    
    return a_citizen_02.processTemplate_01(request, 'BASE.html', contextDict, mode='view')          
Exemplo n.º 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')