Esempio n. 1
0
    def post(self, request, *args, **kw):
        username = request.POST.get('username')
        password = request.POST.get('password')
        user = auth.authenticate(
            request, username=username, password=password)
        if user is not None:
            # user.is_authenticated:
            auth.login(request, user)

        ar = BaseRequest(request)
        # mw = auth.get_auth_middleware()
        # msg = mw.authenticate(username, password, request)
        # if msg:
        #     request.session.pop('username', None)
        #     ar.error(msg)
        # else:
        #     request.session['username'] = username
        #     # request.session['password'] = password
        # ar.success(("Now logged in as %r" % username))
        #     # print "20150428 Now logged in as %r (%s)" % (username, user)
        if user is None:
            ar.error(_("Failed to log in as {}.".format(username)))
        else:
            ar.success(("Now logged in as %r" % username))
        return ar.renderer.render_action_response(ar)
Esempio n. 2
0
 def post(self, request, *args, **kw):
     username = request.POST.get('username')
     password = request.POST.get('password')
     user = auth.authenticate(request, username=username, password=password)
     auth.login(request, user)
     target = '/'
     return http.HttpResponseRedirect(target)
Esempio n. 3
0
    def post(self, request, *args, **kw):
        username = request.POST.get('username')
        password = request.POST.get('password')
        user = auth.authenticate(
            request, username=username, password=password)
        if user is not None:
            # user.is_authenticated:
            auth.login(request, user)

        ar = BaseRequest(request)
        # mw = auth.get_auth_middleware()
        # msg = mw.authenticate(username, password, request)
        # if msg:
        #     request.session.pop('username', None)
        #     ar.error(msg)
        # else:
        #     request.session['username'] = username
        #     # request.session['password'] = password
        # ar.success(("Now logged in as %r" % username))
        #     # print "20150428 Now logged in as %r (%s)" % (username, user)
        if user is None:
            ar.error(_("Failed to log in as {}.".format(username)))
        else:
            ar.success(("Now logged in as %r" % username))
        return ar.renderer.render_action_response(ar)
Esempio n. 4
0
    def post(self, request, *args, **kw):
        username = request.POST.get('username')
        password = request.POST.get('password')
        user = auth.authenticate(
            request, username=username, password=password)
        auth.login(request, user, backend=u'lino.core.auth.backends.ModelBackend')

        return redirect("/")
Esempio n. 5
0
 def post(self, request, *args, **kw):
     username = request.POST.get('username')
     password = request.POST.get('password')
     user = auth.authenticate(
         request, username=username, password=password)
     auth.login(request, user)
     target = '/'
     return http.HttpResponseRedirect(target)
Esempio n. 6
0
 def post(self, request, *args, **kw):
     username = request.POST.get('username')
     password = request.POST.get('password')
     user = auth.authenticate(username, password)
     ar = BaseRequest(request)
     if user is None:
         ar.error("Could not authenticate %r" % username)
     else:
         request.session['username'] = username
         request.session['password'] = password
         ar.success(("Now logged in as %r" % username))
         # print "20150428 Now logged in as %r (%s)" % (username, user)
     return settings.SITE.kernel.render_action_response(ar)
Esempio n. 7
0
File: views.py Progetto: raffas/lino
 def post(self, request, *args, **kw):
     username = request.POST.get('username')
     password = request.POST.get('password')
     user = auth.authenticate(username, password)
     from lino.core import requests
     ar = requests.BaseRequest(request)
     if user is None:
         ar.error("Could not authenticate %r" % username)
         return settings.SITE.ui.render_action_response(ar)
     request.session['username'] = username
     request.session['password'] = password
     ar.success(("Now logged in as %r" % username))
     return settings.SITE.ui.render_action_response(ar)
Esempio n. 8
0
 def run_from_ui(self, ar, **kw):
     pv = ar.action_param_values
     user = auth.authenticate(ar.request,
                              username=pv.username,
                              password=pv.password)
     if user is None:
         ar.error(_("Failed to log in as {}.".format(pv.username)))
     else:
         # user.is_authenticated:
         auth.login(ar.request, user)
         ar.success(_("Now logged in as {}").format(user),
                    close_window=True,
                    goto_url=ar.renderer.front_end.build_plain_url())
Esempio n. 9
0
 def post(self, request, *args, **kw):
     username = request.POST.get('username')
     password = request.POST.get('password')
     user = auth.authenticate(username, password)
     ar = BaseRequest(request)
     if user is None:
         ar.error("Could not authenticate %r" % username)
     else:
         request.session['username'] = username
         request.session['password'] = password
         ar.success(("Now logged in as %r" % username))
         # print "20150428 Now logged in as %r (%s)" % (username, user)
     return settings.SITE.kernel.render_action_response(ar)
Esempio n. 10
0
 def run_from_ui(self, ar, **kw):
     pv = ar.action_param_values
     user = auth.authenticate(
         ar.request, username=pv.username, password=pv.password)
     if user is None:
         ar.error(_("Failed to log in as {}.".format(pv.username)))
     else:
         # user.is_authenticated:
         auth.login(ar.request, user)
         ar.success(
             _("Now logged in as {}").format(user),
             close_window=True,
             goto_url=ar.renderer.plugin.build_plain_url())
Esempio n. 11
0
 def post(self, request, *args, **kw):
     #~ from lino.core import auth
     #~ from django.contrib.sessions.backends.db import SessionStore
     #~ ss = SessionStore()
     username = request.POST.get('username')
     password = request.POST.get('password')
     user = auth.authenticate(username,password)
     if user is None:
         rv = dict(success=False,message="Could not authenticate %r" % username)
         return settings.SITE.ui.render_action_response(rv)
     request.session['username'] = username
     request.session['password'] = password
     #~ request.session['password'] = request.GET.get('password')
     #~ auth.login(request,request.GET.get('username'), request.GET.get('password'))
     #~ ss.save()
     #~ logger.info("20130924 Now logged in as %r" % username)
     rv = dict(success=True,message=("Now logged in as %r" % username))
     return settings.SITE.ui.render_action_response(rv)
Esempio n. 12
0
    def post(self, request, *args, **kw):
        """logs the user in and builds the linoweb.js file for the logged in user"""
        username = request.POST.get('username')
        password = request.POST.get('password')
        # print(username, password)
        user = auth.authenticate(request, username=username, password=password)
        auth.login(request,
                   user,
                   backend=u'lino.core.auth.backends.ModelBackend')

        # target = '/user/settings/'
        def result():
            if not settings.SITE.build_js_cache_on_startup:
                settings.SITE.plugins.react.renderer.build_js_cache(False)
            # http.HttpResponseRedirect(target) # Seems that fetch has some issues with this...
            return json_response({"success": True})

        return with_user_profile(user.user_type, result)
Esempio n. 13
0
    def process_request(self, request):
        # AuthenticationMiddleware is required so that request.user exists.
        if not hasattr(request, 'user'):
            raise ImproperlyConfigured(
                "The Django remote user auth middleware requires the"
                " authentication middleware to be installed.  Edit your"
                " MIDDLEWARE setting to insert"
                " 'django.contrib.auth.middleware.AuthenticationMiddleware'"
                " before the RemoteUserMiddleware class.")
        try:
            username = request.META[self.header]
        except KeyError:
            # If specified header doesn't exist then remove any existing
            # authenticated remote-user, or return (leaving request.user set to
            # AnonymousUser by the AuthenticationMiddleware).
            if self.force_logout_if_no_header and request.user.is_authenticated:
                self._remove_invalid_user(request)
            return
        # If the user is already authenticated and that user is the user we are
        # getting passed in the headers, then the correct user is already
        # persisted in the session and we don't need to continue.
        if request.user.is_authenticated:
            if request.user.get_username() == self.clean_username(
                    username, request):
                return
            else:
                # An authenticated user is associated with the request, but
                # it does not match the authorized user in the header.
                self._remove_invalid_user(request)

        # We are seeing this user for the first time in this session, attempt
        # to authenticate the user.
        user = auth.authenticate(request, remote_user=username)
        if user:
            # User is valid.  Set request.user and persist user in the session
            # by logging the user in.
            request.user = user
            auth.login(request, user)
Esempio n. 14
0
    def process_request(self, request):
        # AuthenticationMiddleware is required so that request.user exists.
        if not hasattr(request, 'user'):
            raise ImproperlyConfigured(
                "The Django remote user auth middleware requires the"
                " authentication middleware to be installed.  Edit your"
                " MIDDLEWARE setting to insert"
                " 'django.contrib.auth.middleware.AuthenticationMiddleware'"
                " before the RemoteUserMiddleware class.")
        try:
            username = request.META[self.header]
        except KeyError:
            # If specified header doesn't exist then remove any existing
            # authenticated remote-user, or return (leaving request.user set to
            # AnonymousUser by the AuthenticationMiddleware).
            if self.force_logout_if_no_header and request.user.is_authenticated:
                self._remove_invalid_user(request)
            return
        # If the user is already authenticated and that user is the user we are
        # getting passed in the headers, then the correct user is already
        # persisted in the session and we don't need to continue.
        if request.user.is_authenticated:
            if request.user.get_username() == self.clean_username(username, request):
                return
            else:
                # An authenticated user is associated with the request, but
                # it does not match the authorized user in the header.
                self._remove_invalid_user(request)

        # We are seeing this user for the first time in this session, attempt
        # to authenticate the user.
        user = auth.authenticate(request, remote_user=username)
        if user:
            # User is valid.  Set request.user and persist user in the session
            # by logging the user in.
            request.user = user
            auth.login(request, user)