Beispiel #1
0
def login_to(request):
    if request.method == "POST":
        form = login_form(request.POST)
        if form.is_valid():
            user = form.cleaned_data["username"]
            username = user
            passw = form.cleaned_data["password"]
            user = authenticate(username=user, password=passw)

            if user is not None:
                login(request, user)
                try:
                    pro = user.get_profile()
                    privillege = pro.privillege
                except:
                    privillege = 3

                return HttpResponseRedirect("/login/home?privillege=%s&username=%s" % (privillege, username))

            else:
                return render_to_response(
                    "login/login.html",
                    {"form": form, "message": "Check your username or password"},
                    context_instance=RequestContext(request),
                )
        else:
            return render_to_response("login/login.html", {"form": form}, context_instance=RequestContext(request))
    else:
        return HttpResponseRedirect("/login/")
Beispiel #2
0
def login(request):

    data = {'a': 'doroste'}
    if request.method == 'POST':
        form = login_form(request.POST)
        if form.is_valid():
            f = form.cleaned_data
            if sign_in.objects.filter(username=f['user'],
                                      password=hashlib.md5(
                                          f['pas'].encode()).hexdigest()):
                return JsonResponse(data)
            else:
                return JsonResponse({'data': 'True'})
        else:
            return JsonResponse({'data': 'True'})
    else:
        form = login_form()
        return render(request, 'login/login.html', {'form': form})
Beispiel #3
0
def login_page(request):
    form = login_form()
    return render_to_response("login/login.html", {"form": form}, context_instance=RequestContext(request))