示例#1
0
def register(request):
    '''
        API registration view

        displays/validates form and sends email on successful submission
    '''
    if request.method == 'POST':
        form = KeyForm(request.POST)
        if form.is_valid():
            newkey = form.save(commit=False)
            newkey.key = uuid.uuid4().hex
            newkey.status = 'U'
            newkey.save()

            email_msg = render_to_string('locksmith/registration_email.txt',
                                         {'key': newkey})
            email_subject = getattr(settings, 'LOCKSMITH_EMAIL_SUBJECT',
                                    'API Registration')
            send_mail(email_subject, email_msg, settings.DEFAULT_FROM_EMAIL,
                      [newkey.email])
            return render_to_response('locksmith/registered.html',
                                      {'key': newkey},
                                      context_instance=RequestContext(request))
    else:
        form = KeyForm()
    return render_to_response('locksmith/register.html', {'form':form},
                              context_instance=RequestContext(request))
示例#2
0
def register(request):
    '''
        API registration view

        displays/validates form and sends email on successful submission
    '''
    if request.method == 'POST':
        form = KeyForm(request.POST)
        if form.is_valid():
            newkey = form.save(commit=False)
            newkey.key = uuid.uuid4().hex
            newkey.status = 'U'
            newkey.save()

            email_msg = render_to_string('locksmith/registration_email.txt',
                                         {'key': newkey})
            email_subject = getattr(settings, 'LOCKSMITH_EMAIL_SUBJECT',
                                    'API Registration')
            send_mail(email_subject, email_msg, settings.DEFAULT_FROM_EMAIL,
                      [newkey.email])
            return render_to_response('locksmith/registered.html',
                                      {'key': newkey},
                                      context_instance=RequestContext(request))
    else:
        form = KeyForm()
    return render_to_response('locksmith/register.html', {'form': form},
                              context_instance=RequestContext(request))
示例#3
0
def register(request,
             email_template='locksmith/registration_email.txt',
             registration_template=getattr(settings, 'LOCKSMITH_REGISTER_TEMPLATE', 'locksmith/register.html'),
             registered_template=getattr(settings, 'LOCKSMITH_REGISTERED_TEMPLATE', 'locksmith/registered.html'),
            ):
    '''
        API registration view

        displays/validates form and sends email on successful submission
    '''
    if request.method == 'POST':
        form = KeyForm(request.POST)
        if form.is_valid():
            newkey = form.save(commit=False)
            newkey.key = uuid.uuid4().hex
            newkey.status = 'U'
            newkey.save()

            send_key_email(newkey, email_template)
            return render_to_response(registered_template, {'key': newkey, 'LOCKSMITH_BASE_TEMPLATE': settings.LOCKSMITH_BASE_TEMPLATE }, context_instance=RequestContext(request))
    else:
        form = KeyForm()
    return render_to_response(registration_template, {'form':form, 'LOCKSMITH_BASE_TEMPLATE': settings.LOCKSMITH_BASE_TEMPLATE}, context_instance=RequestContext(request))