Re: LogIn Class Based View

2022-05-28 Thread waqar khan
I think so problem cleaned data try if this pattern
em= form.cleaned_data['email']
ps= form.cleaned_data['password']
user = authenticate(request,email=em,password=ps)

this is way not solve problem share me error

On Fri, May 27, 2022 at 1:07 AM 'dtdave' via Django users <
django-users@googlegroups.com> wrote:

> I have this function based view which works perfectly but I would like to
> convert to a class based view but am stuck on how to do this:
> This is my fbv:
>
> def loginView(request):
> if request.method == 'POST':
> form = LoginForm(request.POST)
> if form.is_valid():
> cd = form.cleaned_data
> user = authenticate(request,
>email=cd['email'],
>password=cd['password'])
>
> if user is not None:
> login(request, user)
> if user.is_authenticated and user.is_client:
> return redirect('clients:detail') # Go to client
> dashboard
> elif user.is_authenticated and user.is_account_manager:
> return redirect('accountmanagers:detail') #Go to
> account manager dashboard
> else:
>return HttpResponse('Invalid login')
> else:
> # Invalid email or password. Handle as you wish
> form = LoginForm()
>
> return render(request, 'registration/login.html', {'form': form})
>
> I would appreciate any help.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/ea6c54f2-ecc0-407d-a296-e168d509a299n%40googlegroups.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CA%2B08CAN_YD3OF9PvBowO9cE9i5rzdVJ3fEqPnOuKDWMATLyvXA%40mail.gmail.com.


Re: LogIn Class Based View

2022-05-27 Thread Lalit Suthar
refer:
https://docs.djangoproject.com/en/4.0/topics/class-based-views/
https://www.youtube.com/watch?v=Xeh9r0CXBmU&list=PLEsfXFp6DpzTD1BD1aWNxS2Ep06vIkaeW&index=36&t=1s

On Fri, 27 May 2022 at 01:07, 'dtdave' via Django users <
django-users@googlegroups.com> wrote:

> I have this function based view which works perfectly but I would like to
> convert to a class based view but am stuck on how to do this:
> This is my fbv:
>
> def loginView(request):
> if request.method == 'POST':
> form = LoginForm(request.POST)
> if form.is_valid():
> cd = form.cleaned_data
> user = authenticate(request,
>email=cd['email'],
>password=cd['password'])
>
> if user is not None:
> login(request, user)
> if user.is_authenticated and user.is_client:
> return redirect('clients:detail') # Go to client
> dashboard
> elif user.is_authenticated and user.is_account_manager:
> return redirect('accountmanagers:detail') #Go to
> account manager dashboard
> else:
>return HttpResponse('Invalid login')
> else:
> # Invalid email or password. Handle as you wish
> form = LoginForm()
>
> return render(request, 'registration/login.html', {'form': form})
>
> I would appreciate any help.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/ea6c54f2-ecc0-407d-a296-e168d509a299n%40googlegroups.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAGp2JVG6zwbf3i4wfT_BgvTQ07i9ZJwrDiyE%2B%3D3q4y24q4SYFg%40mail.gmail.com.


Re: LogIn Class Based View

2022-05-26 Thread Vishesh Mangla
https://ccbv.co.uk/projects/Django/4.0/django.contrib.auth.views/LoginView/
https://openclassrooms.com/en/courses/7107341-intermediate-django/7263527-create-a-login-page-with-class-based-views

https://stackoverflow.com/questions/56761409/how-to-make-a-login-view-for-django-custom-user

On Fri, May 27, 2022 at 1:07 AM 'dtdave' via Django users <
django-users@googlegroups.com> wrote:

> I have this function based view which works perfectly but I would like to
> convert to a class based view but am stuck on how to do this:
> This is my fbv:
>
> def loginView(request):
> if request.method == 'POST':
> form = LoginForm(request.POST)
> if form.is_valid():
> cd = form.cleaned_data
> user = authenticate(request,
>email=cd['email'],
>password=cd['password'])
>
> if user is not None:
> login(request, user)
> if user.is_authenticated and user.is_client:
> return redirect('clients:detail') # Go to client
> dashboard
> elif user.is_authenticated and user.is_account_manager:
> return redirect('accountmanagers:detail') #Go to
> account manager dashboard
> else:
>return HttpResponse('Invalid login')
> else:
> # Invalid email or password. Handle as you wish
> form = LoginForm()
>
> return render(request, 'registration/login.html', {'form': form})
>
> I would appreciate any help.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/ea6c54f2-ecc0-407d-a296-e168d509a299n%40googlegroups.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CACaE8x6gGXLJ_6kdBAbmjc0xYc%2BnQTgMpgNFn-YqkgmUFGz2PA%40mail.gmail.com.


Re: LogIn Class Based View

2022-05-26 Thread Vishesh Mangla
 Sorry, on looking again I realized that CBV already does this.
https://ccbv.co.uk/projects/Django/4.0/django.contrib.auth.views/LoginView/
https://openclassrooms.com/en/courses/7107341-intermediate-django/7263527-create-a-login-page-with-class-based-views

https://stackoverflow.com/questions/56761409/how-to-make-a-login-view-for-django-custom-user

On Fri, May 27, 2022 at 1:07 AM 'dtdave' via Django users <
django-users@googlegroups.com> wrote:

> I have this function based view which works perfectly but I would like to
> convert to a class based view but am stuck on how to do this:
> This is my fbv:
>
> def loginView(request):
> if request.method == 'POST':
> form = LoginForm(request.POST)
> if form.is_valid():
> cd = form.cleaned_data
> user = authenticate(request,
>email=cd['email'],
>password=cd['password'])
>
> if user is not None:
> login(request, user)
> if user.is_authenticated and user.is_client:
> return redirect('clients:detail') # Go to client
> dashboard
> elif user.is_authenticated and user.is_account_manager:
> return redirect('accountmanagers:detail') #Go to
> account manager dashboard
> else:
>return HttpResponse('Invalid login')
> else:
> # Invalid email or password. Handle as you wish
> form = LoginForm()
>
> return render(request, 'registration/login.html', {'form': form})
>
> I would appreciate any help.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/ea6c54f2-ecc0-407d-a296-e168d509a299n%40googlegroups.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CACaE8x7xCs634EU-QO%3D%2BhYNsU8z-3s3xyNExufAdkQpscJUgog%40mail.gmail.com.


Re: LogIn Class Based View

2022-05-26 Thread Vishesh Mangla
Sorry, on looking again I realized that CBV already does this.
https://ccbv.co.uk/projects/Django/4.0/django.contrib.auth.views/LoginView/
https://openclassrooms.com/en/courses/7107341-intermediate-django/7263527-create-a-login-page-with-class-based-views

Btw,

On Fri, May 27, 2022 at 2:26 AM Vishesh Mangla 
wrote:

> I think it's good, function based views offer you more flexibility. If you
> are not liking your code it's because your function should be split up into
> smaller functions, or use a class without it being a view.
>
> On Fri, 27 May 2022, 01:07 'dtdave' via Django users, <
> django-users@googlegroups.com> wrote:
>
>> I have this function based view which works perfectly but I would like to
>> convert to a class based view but am stuck on how to do this:
>> This is my fbv:
>>
>> def loginView(request):
>> if request.method == 'POST':
>> form = LoginForm(request.POST)
>> if form.is_valid():
>> cd = form.cleaned_data
>> user = authenticate(request,
>>email=cd['email'],
>>password=cd['password'])
>>
>> if user is not None:
>> login(request, user)
>> if user.is_authenticated and user.is_client:
>> return redirect('clients:detail') # Go to client
>> dashboard
>> elif user.is_authenticated and user.is_account_manager:
>> return redirect('accountmanagers:detail') #Go to
>> account manager dashboard
>> else:
>>return HttpResponse('Invalid login')
>> else:
>> # Invalid email or password. Handle as you wish
>> form = LoginForm()
>>
>> return render(request, 'registration/login.html', {'form': form})
>>
>> I would appreciate any help.
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/ea6c54f2-ecc0-407d-a296-e168d509a299n%40googlegroups.com
>> 
>> .
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CACaE8x4RTf0k3DKcKfxhiFcXckGFKp8tifQGVF_FpxXBQcAkdg%40mail.gmail.com.


Re: LogIn Class Based View

2022-05-26 Thread Vishesh Mangla
I think it's good, function based views offer you more flexibility. If you
are not liking your code it's because your function should be split up into
smaller functions, or use a class without it being a view.

On Fri, 27 May 2022, 01:07 'dtdave' via Django users, <
django-users@googlegroups.com> wrote:

> I have this function based view which works perfectly but I would like to
> convert to a class based view but am stuck on how to do this:
> This is my fbv:
>
> def loginView(request):
> if request.method == 'POST':
> form = LoginForm(request.POST)
> if form.is_valid():
> cd = form.cleaned_data
> user = authenticate(request,
>email=cd['email'],
>password=cd['password'])
>
> if user is not None:
> login(request, user)
> if user.is_authenticated and user.is_client:
> return redirect('clients:detail') # Go to client
> dashboard
> elif user.is_authenticated and user.is_account_manager:
> return redirect('accountmanagers:detail') #Go to
> account manager dashboard
> else:
>return HttpResponse('Invalid login')
> else:
> # Invalid email or password. Handle as you wish
> form = LoginForm()
>
> return render(request, 'registration/login.html', {'form': form})
>
> I would appreciate any help.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/ea6c54f2-ecc0-407d-a296-e168d509a299n%40googlegroups.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CACaE8x5iCrx496xhUCw5wZ3hgXe2cmFRy2k2iPNub%3DxJdC4V5g%40mail.gmail.com.