コード例 #1
0
ファイル: auth.py プロジェクト: Hakayati/paleonaut
def login_and_forward(request, user, forward=None, message=None):
    if user.is_suspended():
        return forward_suspended_user(request, user)

    user.backend = "django.contrib.auth.backends.ModelBackend"
    login(request, user)

    if message is None:
        message = _("Welcome back %s, you are now logged in") % user.username

    request.user.message_set.create(message=message)

    if not forward:
        forward = request.session.get(ON_SIGNIN_SESSION_ATTR, reverse('index'))

    pending_data = request.session.get(PENDING_SUBMISSION_SESSION_ATTR, None)

    if pending_data and (user.email_isvalid or pending_data['type'] not in settings.REQUIRE_EMAIL_VALIDATION_TO):
        submission_time = pending_data['time']
        if submission_time < datetime.datetime.now() - datetime.timedelta(minutes=int(settings.HOLD_PENDING_POSTS_MINUTES)):
            del request.session[PENDING_SUBMISSION_SESSION_ATTR]
        elif submission_time < datetime.datetime.now() - datetime.timedelta(minutes=int(settings.WARN_PENDING_POSTS_MINUTES)):
            user.message_set.create(message=(_("You have a %s pending submission.") % pending_data['data_name']) + " %s, %s, %s" % (
                html.hyperlink(reverse('manage_pending_data', kwargs={'action': _('save')}), _("save it")),
                html.hyperlink(reverse('manage_pending_data', kwargs={'action': _('review')}), _("review")),
                html.hyperlink(reverse('manage_pending_data', kwargs={'action': _('cancel')}), _("cancel"))
            ))
        else:
            return manage_pending_data(request, _('save'), forward)

    return HttpResponseRedirect(forward)
コード例 #2
0
ファイル: auth.py プロジェクト: yyaadet/osqa-cn
def login_and_forward(request, user, forward=None, message=None):
    if user.is_suspended():
        return forward_suspended_user(request, user)

    user.backend = "django.contrib.auth.backends.ModelBackend"
    login(request, user)

    if message is None:
        message = _("Welcome back %s, you are now logged in") % smart_unicode(user.username)

    request.user.message_set.create(message=message)

    if not forward:
        forward = request.session.get(ON_SIGNIN_SESSION_ATTR, reverse('index'))

    pending_data = request.session.get(PENDING_SUBMISSION_SESSION_ATTR, None)

    if pending_data and (user.email_isvalid or pending_data['type'] not in settings.REQUIRE_EMAIL_VALIDATION_TO):
        submission_time = pending_data['time']
        if submission_time < datetime.datetime.now() - datetime.timedelta(minutes=int(settings.HOLD_PENDING_POSTS_MINUTES)):
            del request.session[PENDING_SUBMISSION_SESSION_ATTR]
        elif submission_time < datetime.datetime.now() - datetime.timedelta(minutes=int(settings.WARN_PENDING_POSTS_MINUTES)):
            user.message_set.create(message=(_("You have a %s pending submission.") % pending_data['data_name']) + " %s, %s, %s" % (
                html.hyperlink(reverse('manage_pending_data', kwargs={'action': _('save')}), _("save it")),
                html.hyperlink(reverse('manage_pending_data', kwargs={'action': _('review')}), _("review")),
                html.hyperlink(reverse('manage_pending_data', kwargs={'action': _('cancel')}), _("cancel"))
            ))
        else:
            return manage_pending_data(request, _('save'), forward)

    return HttpResponseRedirect(forward)
コード例 #3
0
def login_and_forward(request, user, forward=None, message=None):
    if user.is_suspended():
        return forward_suspended_user(request, user)

    user.backend = "django.contrib.auth.backends.ModelBackend"
    login(request, user)

    # Store the login action
    UserLoginAction(user=user, ip=request.META['REMOTE_ADDR']).save()

    if message is None:
        message = _("Welcome back %s, you are now logged in") % smart_unicode(
            user.username)

    request.user.message_set.create(message=message)

    if not forward:
        forward = request.session.get(ON_SIGNIN_SESSION_ATTR, reverse('index'))

    pending_data = request.session.get(PENDING_SUBMISSION_SESSION_ATTR, None)

    if pending_data and (user.email_isvalid or pending_data['type']
                         not in settings.REQUIRE_EMAIL_VALIDATION_TO):
        submission_time = pending_data['time']
        if submission_time < datetime.datetime.now() - datetime.timedelta(
                minutes=int(settings.HOLD_PENDING_POSTS_MINUTES)):
            del request.session[PENDING_SUBMISSION_SESSION_ATTR]
        elif submission_time < datetime.datetime.now() - datetime.timedelta(
                minutes=int(settings.WARN_PENDING_POSTS_MINUTES)):
            user.message_set.create(
                message=(_("You have a %s pending submission.") %
                         pending_data['data_name']) + " %s, %s, %s" %
                (html.hyperlink(
                    reverse('manage_pending_data',
                            kwargs={'action': _('save')}), _("save it")),
                 html.hyperlink(
                     reverse('manage_pending_data',
                             kwargs={'action': _('review')}), _("review")),
                 html.hyperlink(
                     reverse('manage_pending_data',
                             kwargs={'action': _('cancel')}), _("cancel"))))
        else:
            return manage_pending_data(request, _('save'), forward)

    additional_get_params = urllib.urlencode(
        dict([k, v.encode('utf-8')] for k, v in request.GET.items()))

    parsed_forward = urlparse(forward)

    # If there is already some parsed query in the URL then change the forward URL
    if parsed_forward.query:
        forward_url = forward + "&%s" % additional_get_params
    else:
        forward_url = forward + "?%s" % additional_get_params

    return HttpResponseRedirect(forward_url)
コード例 #4
0
ファイル: auth.py プロジェクト: pombredanne/osqa-ng
def login_and_forward(request, user, forward=None, message=None):
    if user.is_suspended():
        return forward_suspended_user(request, user)

    user.backend = "django.contrib.auth.backends.ModelBackend"
    login(request, user)

    # Store the login action
    UserLoginAction(user=user, ip=request.META["REMOTE_ADDR"]).save()

    if message is None:
        message = _("Welcome back %s, you are now logged in") % smart_unicode(user.username)

    messages.success(request, message)

    if not forward:
        forward = request.session.get(ON_SIGNIN_SESSION_ATTR, reverse("index"))

    pending_data = request.session.get(PENDING_SUBMISSION_SESSION_ATTR, None)

    if pending_data and (user.email_isvalid or pending_data["type"] not in settings.REQUIRE_EMAIL_VALIDATION_TO):
        submission_time = pending_data["time"]
        if submission_time < datetime.datetime.now() - datetime.timedelta(
            minutes=int(settings.HOLD_PENDING_POSTS_MINUTES)
        ):
            del request.session[PENDING_SUBMISSION_SESSION_ATTR]
        elif submission_time < datetime.datetime.now() - datetime.timedelta(
            minutes=int(settings.WARN_PENDING_POSTS_MINUTES)
        ):
            messages.success(
                request,
                (_("You have a %s pending submission.") % pending_data["data_name"])
                + " %s, %s, %s"
                % (
                    html.hyperlink(reverse("manage_pending_data", kwargs={"action": _("save")}), _("save it")),
                    html.hyperlink(reverse("manage_pending_data", kwargs={"action": _("review")}), _("review")),
                    html.hyperlink(reverse("manage_pending_data", kwargs={"action": _("cancel")}), _("cancel")),
                ),
            )
        else:
            return manage_pending_data(request, _("save"), forward)

    additional_get_params = urllib.urlencode(dict([k, v.encode("utf-8")] for k, v in request.GET.items()))

    parsed_forward = urlparse(forward)

    # If there is already some parsed query in the URL then change the forward URL
    if parsed_forward.query:
        forward_url = forward + "&%s" % additional_get_params
    else:
        forward_url = forward + "?%s" % additional_get_params

    return HttpResponseRedirect(forward_url)
コード例 #5
0
ファイル: auth.py プロジェクト: jandetlefsen/aqso
def login_and_forward(request, user, forward=None, message=None):
    if user.is_suspended():
        return forward_suspended_user(request, user)

    user.backend = "django.contrib.auth.backends.ModelBackend"
    login(request, user)

    # Store the login action
    UserLoginAction(user=user, ip=request.META["REMOTE_ADDR"]).save()

    if message is None:
        message = _("Welcome back %s, you are now logged in") % smart_unicode(user.username)

    request.user.message_set.create(message=message)

    if not forward:
        forward = request.session.get(ON_SIGNIN_SESSION_ATTR, reverse("index"))

    pending_data = request.session.get(PENDING_SUBMISSION_SESSION_ATTR, None)

    if pending_data and (user.email_isvalid or pending_data["type"] not in settings.REQUIRE_EMAIL_VALIDATION_TO):
        submission_time = pending_data["time"]
        if submission_time < datetime.datetime.now() - datetime.timedelta(
            minutes=int(settings.HOLD_PENDING_POSTS_MINUTES)
        ):
            del request.session[PENDING_SUBMISSION_SESSION_ATTR]
        elif submission_time < datetime.datetime.now() - datetime.timedelta(
            minutes=int(settings.WARN_PENDING_POSTS_MINUTES)
        ):
            user.message_set.create(
                message=(_("You have a %s pending submission.") % pending_data["data_name"])
                + " %s, %s, %s"
                % (
                    html.hyperlink(reverse("manage_pending_data", kwargs={"action": _("save")}), _("save it")),
                    html.hyperlink(reverse("manage_pending_data", kwargs={"action": _("review")}), _("review")),
                    html.hyperlink(reverse("manage_pending_data", kwargs={"action": _("cancel")}), _("cancel")),
                )
            )
        else:
            return manage_pending_data(request, _("save"), forward)

    return HttpResponseRedirect(forward)