def _func(request, *args, **kwargs): user = getattr(request, 'user', None) is_authenticated = getattr(user, 'is_authenticated', lambda: False) if ((user is not None and six.callable(is_authenticated) and not is_authenticated()) or user is None): user = None try: creds = args[:len(authentication_arguments)] if len(creds) == 0: raise IndexError # Django's authenticate() method takes arguments as dict user = _authenticate(username=creds[0], password=creds[1], *creds[2:]) if user is not None: args = args[len(authentication_arguments):] except IndexError: auth_kwargs = {} try: for auth_kwarg in authentication_arguments: auth_kwargs[auth_kwarg] = kwargs[auth_kwarg] except KeyError: raise InvalidParamsError( 'Authenticated methods require at least ' '[%s] or {%s} arguments', authentication_arguments) user = _authenticate(**auth_kwargs) if user is not None: for auth_kwarg in authentication_arguments: kwargs.pop(auth_kwarg) if user is None: raise InvalidCredentialsError request.user = user return func(request, *args, **kwargs)
def _func(request, *args, **kwargs): user = getattr(request, "user", None) is_authenticated = getattr(user, "is_authenticated", lambda: False) if (user is not None and callable(is_authenticated) and not is_authenticated()) or user is None: user = None try: creds = args[: len(authentication_arguments)] if len(creds) == 0: raise IndexError user = _authenticate(*creds) if user is not None: args = args[len(authentication_arguments) :] except IndexError: auth_kwargs = {} try: for auth_kwarg in authentication_arguments: auth_kwargs[auth_kwarg] = kwargs[auth_kwarg] except KeyError: raise InvalidParamsError( "Authenticated methods require at least " "[%s] or {%s} arguments", authentication_arguments, ) user = _authenticate(**auth_kwargs) if user is not None: for auth_kwarg in authentication_arguments: kwargs.pop(auth_kwarg) if user is None: raise InvalidCredentialsError request.user = user return func(request, *args, **kwargs)
def login(request): if request.method == "POST": username = request.POST['username'] password = request.POST['password'] user = _authenticate(request, username=username, password=password) if user is not None: _login(request, user) return HttpResponseRedirect(reverse("index")) else: return render(request, "registration/login.html")
def loginPost(request): if logged_in(request): return user(request, request.user.id) else: username = request.POST['username'] password = request.POST['password'] try_user = _authenticate(username=username, password=password) print(try_user) if user is not None: _login(request, try_user) return user(request, try_user.id) else: return render(request, 'routine/login.html', {"error":"Zugangsdaten falsch"})
def clean(self): email = self.cleaned_data.get("email", "").strip().lower() username = email username = username.replace("@", "_") username = username.replace(".", "_") password = self.cleaned_data.get("password", "") self.user = _authenticate(username=username, password=password) if self.user: if self.user.is_active: return self.cleaned_data else: raise forms.ValidationError( "Your account is pending approval.") else: raise forms.ValidationError("Login Failed")