会话过期时重定向到登录页面

时间:2019-04-19 10:30:44

标签: angular7 adal.js

我将adal.js用于我的角度应用程序。当会话到期时,在控制台中出现错误:

class Category(DistributedModel):
    """
    Model that represents categories for methodologies
    """
    title = models.CharField(
        max_length=200
    )

    def __str__(self):
        return self.title


# Standard file download via /media is disallowed.
fs = FileSystemStorage(location=settings.METHODOLOGIES_FILE_DIR)


class Article(DistributedModel):
    """
    Article model that represents Methodology description.
    It is used on 1. terminal methodology page and
                  2. methodologies list page
    """
    title = models.CharField(
        max_length=200,
        help_text="Title displayed on both methodology page and methodologies list pages."
    )
    slug = models.SlugField(
        unique=True,
        help_text="What should be the unique identifying key word in the url of the page?")
    short_text = models.TextField(
        max_length=500, help_text="Short summary displayed only in preview box on methodologies list page. "
                                  "Max 500 chars."
    )
    full_text = models.TextField(
        help_text="Full article displayed only on terminal methodology page."
    )
    image = models.ImageField(
        null=True,
        blank=True,
        help_text="Recommended width at least 1200px. Please prefer to add images. "
                  "Image used on both pages."
    )
    button_text = models.CharField(
        default='SHOW MORE',
        max_length=100
    )
    category = models.ForeignKey(
        Category,
        on_delete="CASCADE"
    )
    related_articles = models.ManyToManyField(
        "self",
        blank=True,
        help_text="Links of these articles will be displayed at the bottom of the page. "
                  "If empty, articles of the same category will be displayed. "
    )

    file = models.FileField(
        blank=True,
        null=True,
        storage=fs,
        help_text="Upload pdf, doc, xlsx, etc. related to this article. Files will be attached to the end "
                  "of the article for download. "
    )

    created = models.DateTimeField(
        auto_now_add=True
    )
    modified = models.DateTimeField(
        auto_now=True
    )
    created_by = models.ForeignKey(
        User,
        null=True,
        blank=True,
        on_delete="SET_NULL"
    )
    is_displayed = models.BooleanField(
        default=False
    )

    def save(self, *args, **kwargs):
        if not self.created_by:
            # using threadlocals is bad
            self.created_by = get_current_user()
        super(Article, self).save(*args, **kwargs)

但我不想解决一些错误,而是希望将用户重定向到登录页面。如何做到这一点?在adal.js中是否有任何规定-配置?

或者任何人向我展示解决此问题的正确方法?

这是我的配置:

ERROR User login is required
Access to XMLHttpRequest at 'https://login.windows.net/de08c407-19b9-427d-9fe8-edf254300ca7/oauth2/authorize?response_type=code+id_token&redirect_uri=https%3A%2F%2Fiboconfigservice.azurewebsites.net%2F.auth%2Flogin%2Faad%2Fcallback&client_id=828002a4-149f-478c-a318-933ad52b4c4f&scope=openid+profile+email&response_mode=form_post&nonce=58558408a18a4ee2a66e82121b92ea60_20190419101323&state=redir%3D%252Fapi%252FCalendar' (redirected from 'https://xxx.azurewebsites.net/api/ylendar') from origin 'null' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

0 个答案:

没有答案
相关问题