Пример #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 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.')
                return redirect('/')

    else:
        form = RequestAccountForm()

    return render(request, 'request_new_account.html', {'form': form})
Пример #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 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.')
                return redirect('/')
                
    else:
        form = RequestAccountForm()
    
    return render(request, 'request_new_account.html', {'form':form})