def send_account_creation_mail(participant, request):
    subject = "Successful application for Pawsey funded iVEC infrastructure"
    email_hash = str(uuid.uuid4())
    link = "%s%s/%s" % (siteurl(request), 'account-request', email_hash)
    template = EmailTemplate.objects.get(name='Participant Account Request')
    subject, message = template.render_to_string({'participant': participant, 'link': link})
    send_mail(subject, message, participant.email)

    participant.account_email_hash = email_hash
    participant.status_id = Participant.STATUS['EMAIL_SENT']
    participant.account_email_on = datetime.datetime.now()
    participant.save()
예제 #2
0
def account_request(request, email_hash):
    try:
        participant = Participant.objects.get(account_email_hash=email_hash)
    except Participant.DoesNotExist:
        return render_to_response('allocation/invalid_hash.html', {})

    try:
        participant_account = participant.participantaccount
    except ParticipantAccount.DoesNotExist:
        participant_account = ParticipantAccount(participant=participant) 
 
    if request.method == 'POST':
        if participant.fetched_from_ldap():
            form = ParticipantAccountForm(request.POST)
        else:
            form = ParticipantAccountWithPasswordForm(request.POST)

        if form.is_valid():
            participant_account.first_name = form.cleaned_data.get('first_name')
            participant_account.last_name = form.cleaned_data.get('last_name')
            participant_account.institution_id = form.cleaned_data.get('institution').id
            participant_account.phone = form.cleaned_data.get('phone')
            if not participant.fetched_from_ldap():
                participant_account.password_hash = account_services.hash_password(form.cleaned_data.get('password1'))
            account_services.save_account_details(participant)
            request.session[PROCESSED_PARTICIPANT_SESSION_KEY] = email_hash
            return HttpResponseRedirect(siteurl(request) + 'account-details/thanks')
    else:
  
        if participant.fetched_from_ldap():
            data_dict = {}
            data_dict['first_name'] = participant_account.first_name
            data_dict['last_name'] = participant_account.last_name
            data_dict['phone'] = participant_account.phone
            #data_dict['institution'] = participant_account.institution.id
            
            form = ParticipantAccountForm(data=data_dict)
        else:
            form = ParticipantAccountWithPasswordForm()

    return render_to_response('allocation/account_request.html', {
        'form': form, 'participant_email': participant.email
    })