예제 #1
0
파일: views.py 프로젝트: NamPNQ/vp.repo
def registerClient(request):
    """This is for the installation process of VPW. Email is mandatory and used
       to check the unique of the remote system. Both email and name could be 
       sent through POST or GET.
            email    email of the client (required and unique)
            name     name of the client (required).
    """
    try:
        time.sleep(REGISTER_DELAY)   # dirty way to reduce multiple request
        email = request.GET.get('email', '') or request.POST.get('email', '')  
        name = request.GET.get('name', '') or request.POST.get('name', '')  
        # not allow same client ID or reusing
        if not email or not name or Client.objects.filter(email=email):
            response = Response({}, status=status.HTTP_400_BAD_REQUEST)
        else:
            client_id = generateClientID(request.META.get('REMOTE_ADDR', ''))
            client = Client(client_id = client_id,
                            name = name,
                            email = email,
                            secret_key = generateClientKey(email or 'empty')
                            )
            client.save()
            response = Response({'client_id': client_id,
                                'secret': client.secret_key
                                },
                                status=status.HTTP_201_CREATED)
        return response
    except:
        raise
예제 #2
0
def createClient(client_dict=None):
    """docstring for createClient"""
    if not client_dict:
        client_dict = {
            "name": "Test Client",
            "client_id": "test_client",
            "secret_key": "this is not a secret",
            "email": "*****@*****.**",
        }
    client = APIClient(**client_dict)
    client.save()
    return client
예제 #3
0
파일: views.py 프로젝트: NamPNQ/vp.repo
def clientRegView(request):
    """ Dashboard view, for registering API Client """
    if request.method == 'POST':
        form = ClientRegForm(request.POST)
        if form.is_valid():
            client = APIClient()
            client.name = form['name'].value()
            client.client_id = form['client_id'].value()
            client.email = form['email'].value()
            client.organization = form['organization'].value()
            client.secret_key = generateClientKey(client.email)
            client.save()
            return redirect('/dashboard/clients/')
    else:
        form = ClientRegForm()
    return render(request, 'client_reg.html', {'form':form})