示例#1
0
      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)
示例#2
0
            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)
示例#3
0
            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)
示例#4
0
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")
示例#5
0
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"})
示例#6
0
 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")