예제 #1
0
파일: views.py 프로젝트: LaurenUnq/Piscine
def login_user(request):
    error=False
    if request.method == 'POST':
        form = SignInForm(request.POST)
        if form.is_valid():
            username = form.cleaned_data["username"]
            raw_password = form.cleaned_data["password"]
            user = authenticate(username=username, password=raw_password)
            if user:
                login(request,user)
                groupe = User.objects.filter(groups__name='client', id=user.id) #On cherche si notre utilisateur est un client
                if not groupe: #Si aucun objet n'est retourné, il n'est pas client
                    estClient = False
                else:           #Sinon, c'est un client
                    estClient =True
                request.session['estClient'] = estClient #On mémorise cette information
                request = init_panier(request)
                request = init_reservation(request) #On initiliase le panier et le panier_reservation de l'utilisateur

                if estClient:
                    return redirect('homepage')
                else:
                    return redirect('gestion/dashboard/')
            else:
                error=True
                #ErrorMessage = "Username ou mot de passe incorrect"
    else:
        form= SignInForm()
    return render(request, 'signin.html', locals())
예제 #2
0
def sign_in(request):
    form = SignInForm()

    if request.method == "POST":
        form = SignInForm(request.POST)
        if form.is_valid():
            username = request.POST['username']
            password = request.POST['password']
            user = authenticate(username=username, password=password)
            if user is not None:
                login(request, user)
                return redirect("/")

    return render(request, 'sign_in.html', locals())
예제 #3
0
파일: views.py 프로젝트: schmico/teamedup
def login_view(request):
    next = request.GET.get('next')
    # subdomain = request.META['HTTP_HOST'].split('.')[0]
    # try:
    #     org = Organization.objects.get(slug=subdomain)
    # except (Organization.DoesNotExist, Organization.MultipleObjectsReturned) as e:
    #     raise Http404
    form = SignInForm()
    if request.method == 'POST':
        form = SignInForm(request.POST)
        if form.is_valid():
            email = form.cleaned_data.get('email')
            password = form.cleaned_data.get('password')
            user = authenticate(email=email, password=password)
            if user is not None:
                login(request, user)
                if user.name == '':
                    messages.add_message(request, messages.SUCCESS, _('Please update your profile'))
                    return redirect('settings')
                else:
                    messages.add_message(request, messages.SUCCESS, _('Your have signed in successfully'))
                    return redirect('/app/')
    return render(request, 'app/login.html', locals())