def login(request): ''' Manage the login of the users ''' other_errors = None if request.user.is_authenticated(): template = 'profile' if is_client(request.user) else 'bookmakers' return redirect(template) auth_form = AuthenticationForm() if request.method == 'POST': auth_form = AuthenticationForm(None, request.POST) if auth_form.is_valid(): auth_login(request, auth_form.get_user()) template = 'profile' if is_client(request.user) else 'bookmakers' return redirect(template) else: other_errors = auth_form.errors.get('__all__') return render(request, "registration/login.html", { 'form': auth_form, 'other_errors': other_errors, })
class DjangoRegistrationDefaultBackend(ExtendedBackendOther, NooptRegistrationBackend): ''' The redirect behaviour will still be controlled by the post_error post_connect functions the form and other settings will be taken from the default backend ''' def post_conect(request, user, action): return redirect('/app/profile') # App views @login_required @user_passes_test(lambda u: is_client(u)) def profile(request): ''' Shows profile page ''' edit_profile = False edit_user = False edit_user_form = EditUserForm(instance=request.user) profile_form = ProfileForm(instance=request.user.profile) fb_form = FbUsernameForm(instance=request.user.profile) # The users has facebook profile? try: fb_profile = FacebookProfile.objects.get(user=request.user) if fb_profile.facebook_id is not None: connected_via_facebook = True else: