コード例 #1
0
ファイル: views.py プロジェクト: chinspp/42
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"}))
コード例 #2
0
ファイル: views.py プロジェクト: sevaseva2001/42
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())
コード例 #3
0
ファイル: views.py プロジェクト: ryanrdk/42
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"
        }))
コード例 #4
0
ファイル: views.py プロジェクト: chinspp/42
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())