Exemple #1
0
def login_user(request):
    if request.user.is_authenticated():
        return HttpResponseRedirect("/")
    error = False
    if request.method == "POST":
        if "SendEmail" in request.POST:
            allusers = UserProfile.objects.all()
            for eachuser in allusers:
                if eachuser.subscribed:
                    send_mail(
                        "My django-app",
                        "Hello, "
                        + eachuser.username
                        + ".\n It is : "
                        + datetime.now().strftime("%I:%M%p on %B %d, %Y"),
                        "*****@*****.**",
                        [eachuser.email],
                        fail_silently=False,
                    )
        else:
            form = ConnexionForm(request.POST)
            if form.is_valid():
                username = form.cleaned_data["username"]
                password = form.cleaned_data["password"]
                user = authenticate(username=username, password=password)
                if user:
                    login(request, user)
                    return HttpResponseRedirect("/", {"user": user})
                else:
                    error = True
    else:
        form = ConnexionForm()
    return render_to_response("form.html", RequestContext(request, {"form": form, "title": "Login"}))
Exemple #2
0
def login_user(request):
    error = False
    if request.method == "POST":
        if "SendEmail" in request.POST:
            allusers = UserProfile.objects.all()
            for eachuser in allusers:
                if (eachuser.subscribed):
                    send_mail('My django-app',
                              'Hello, ' + eachuser.username + ".\n It is : " +
                              datetime.now().strftime("%I:%M%p on %B %d, %Y"),
                              '*****@*****.**', [eachuser.email],
                              fail_silently=False)
        else:
            form = ConnexionForm(request.POST)
            if form.is_valid():
                username = form.cleaned_data["username"]
                password = form.cleaned_data["password"]
                user = authenticate(username=username, password=password)
                if user:
                    login(request, user)
                else:
                    error = True
    else:
        form = ConnexionForm()
    return render(request, 'login.html', locals())
Exemple #3
0
def login_user(request):
    if request.user.is_authenticated():
        return HttpResponseRedirect('/')
    error = False
    if request.method == "POST":
        if "SendEmail" in request.POST:
            allusers = UserProfile.objects.all()
            for eachuser in allusers:
                if (eachuser.subscribed):
                    send_mail('My django-app',
                              'Hello, ' + eachuser.username + ".\n It is : " +
                              datetime.now().strftime("%I:%M%p on %B %d, %Y"),
                              '*****@*****.**', [eachuser.email],
                              fail_silently=False)
        else:
            form = ConnexionForm(request.POST)
            if form.is_valid():
                username = form.cleaned_data["username"]
                password = form.cleaned_data["password"]
                user = authenticate(username=username, password=password)
                if user:
                    login(request, user)
                    return HttpResponseRedirect('/', {"user": user})
                else:
                    error = True
    else:
        form = ConnexionForm()
    return render_to_response(
        'form.html', RequestContext(request, {
            'form': form,
            'title': "Login"
        }))
Exemple #4
0
def login_user(request):
    error = False
    if request.method == "POST":
        if "SendEmail" in request.POST:
            allusers = UserProfile.objects.all()
            for eachuser in allusers:
                if (eachuser.subscribed):
                    send_mail('My django-app', 'Hello, ' + eachuser.username +".\n It is : "+ datetime.now().strftime("%I:%M%p on %B %d, %Y"), '*****@*****.**',[eachuser.email], fail_silently=False)
        else:   
            form = ConnexionForm(request.POST)
            if form.is_valid():
                username = form.cleaned_data["username"]
                password = form.cleaned_data["password"]
                user = authenticate(username=username, password=password)
                if user:
                    login(request, user)
                else:
                    error = True
    else:
        form = ConnexionForm()
    return render(request, 'login.html', locals())