예제 #1
0
def request_new_account(request):
    if request.method == 'POST':
        form = RequestAccountForm(request.POST)
        if form.is_valid():
            try:
                user = User.objects.get(username=request.POST["username"])
                message = "This username already exists. Please choose another username."
                return render(request, 'request_new_account.html', {'form':form, 'action_result':message})
            except:
                Request(username=request.POST["username"], password=request.POST["password1"],
                        first_name=request.POST["firstname"], last_name=request.POST["lastname"],
                        email=request.POST["email"]).save()
                messages.add_message(request, messages.INFO, 'User Account Request sent to the administrator.')
                # Send mail to the user and the admin
                context = {'lastname': request.POST["lastname"],
                           'firstname': request.POST["firstname"],
                           'URI': MDCS_URI}
                email = request.POST["email"]
                send_mail(recipient_list=[email], subject='Account Request', pathToTemplate='admin/email/request_account_for_user.html',
                          context=context)
                send_mail_to_administrators(subject='Account Request',
                                            pathToTemplate='admin/email/request_account_for_admin.html',
                                            context=context)
                return redirect('/')
                
    else:
        form = RequestAccountForm()
    
    return render(request, 'request_new_account.html', {'form': form})
예제 #2
0
def accept_request(request):
    request_id = request.POST['requestid']

    response_dict = {}

    userRequest = Request.objects.get(pk=request_id)
    try:
        existingUser = User.objects.get(username=userRequest.username)
        response_dict = {'errors': 'User already exists.'}
    except:
        user = User.objects.create_user(username=userRequest.username,
                                        password=userRequest.password,
                                        first_name=userRequest.first_name,
                                        last_name=userRequest.last_name,
                                        email=userRequest.email)
        user.save()
        userRequest.delete()
        # Send mail to the user
        context = {
            'lastname': userRequest.last_name,
            'firstname': userRequest.first_name,
            'URI': MDCS_URI
        }
        send_mail(subject='Account approved',
                  pathToTemplate='admin/email/request_account_approved.html',
                  context=context,
                  recipient_list=[userRequest.email])

    return HttpResponse(json.dumps(response_dict),
                        content_type='application/javascript')
예제 #3
0
def request_new_account(request):
    if request.method == 'POST':
        form = RequestAccountForm(request.POST)
        if form.is_valid():
            try:
                user = User.objects.get(username=request.POST["username"])
                message = "This username already exists. Please choose another username."
                return render(request, 'request_new_account.html', {'form':form, 'action_result':message})
            except:
                Request(username=request.POST["username"], password=request.POST["password1"],
                        first_name=request.POST["firstname"], last_name=request.POST["lastname"],
                        email=request.POST["email"]).save()
                messages.add_message(request, messages.INFO, 'User Account Request sent to the administrator.')
                # Send mail to the user and the admin
                context = {'lastname': request.POST["lastname"],
                           'firstname': request.POST["firstname"],
                           'URI': MDCS_URI}
                email = request.POST["email"]
                send_mail(recipient_list=[email], subject='Account Request', pathToTemplate='admin/email/request_account_for_user.html',
                          context=context)
                send_mail_to_administrators(subject='Account Request',
                                            pathToTemplate='admin/email/request_account_for_admin.html',
                                            context=context)
                return redirect('/')
                
    else:
        form = RequestAccountForm()
    
    return render(request, 'request_new_account.html', {'form':form})
예제 #4
0
def deny_request(request):
    request_id = request.POST['requestid']
    
    userRequest = Request.objects.get(pk=request_id)
    userRequest.delete()
    # Send mail to the user
    context = {'lastname': userRequest.last_name,
               'firstname': userRequest.first_name,
               'URI': MDCS_URI}
    send_mail(subject='Account denied', pathToTemplate='admin/email/request_account_denied.html',
              context=context, recipient_list=[userRequest.email])
    
    return HttpResponse(json.dumps({}), content_type='application/javascript')
예제 #5
0
def deny_request(request):
    request_id = request.POST['requestid']

    userRequest = Request.objects.get(pk=request_id)
    userRequest.delete()
    # Send mail to the user
    context = {
        'lastname': userRequest.last_name,
        'firstname': userRequest.first_name,
        'URI': MDCS_URI
    }
    send_mail(subject='Account denied',
              pathToTemplate='admin/email/request_account_denied.html',
              context=context,
              recipient_list=[userRequest.email])

    return HttpResponse(json.dumps({}), content_type='application/javascript')
예제 #6
0
def accept_request(request):
    request_id = request.POST['requestid']
    
    response_dict = {}
    
    userRequest = Request.objects.get(pk=request_id)
    try:
        existingUser = User.objects.get(username=userRequest.username)
        response_dict = {'errors': 'User already exists.'} 
    except:
        user = User.objects.create_user(username=userRequest.username, password=userRequest.password, first_name=userRequest.first_name, last_name=userRequest.last_name, email=userRequest.email)
        user.save()
        userRequest.delete()
        # Send mail to the user
        context = {'lastname': userRequest.last_name,
                   'firstname': userRequest.first_name,
                   'URI': MDCS_URI}
        send_mail(subject='Account approved', pathToTemplate='admin/email/request_account_approved.html',
                  context=context, recipient_list=[userRequest.email])
        
    return HttpResponse(json.dumps(response_dict), content_type='application/javascript')