__init__.py 文件源码

python
阅读 16 收藏 0 点赞 0 评论 0

项目:lti-demo-haiku 作者: open-craft 项目源码 文件源码
def authentication_hook(self, request, user_id=None, username=None, email=None, extra_params=None):
        extra = extra_params if extra_params else {}

        # automatically generate password from user_id
        password = self._generate_password(user_id, settings.PASSWORD_GENERATOR_NONCE)

        # username and email might be empty, depending on how edX LTI module is configured:
        # there are individual settings for that + if it's embedded into an iframe it never sends
        # email and username in any case
        # so, since we want to track user for both iframe and non-iframe LTI blocks, username is completely ignored
        uname = self._compress_user_name(user_id)
        email = email if email else user_id+'@localhost'
        try:
            User.objects.get(username=uname)
        except User.DoesNotExist:
            try:
                User.objects.create_user(username=uname, email=email, password=password)
            except IntegrityError as e:
                # A result of race condition of multiple simultaneous LTI requests - should be safe to ignore,
                # as password and uname are stable (i.e. not change for the same user)
                logger.info("IntegrityError creating user - assuming result of race condition: %s", e.message)

        authenticated = authenticate(username=uname, password=password)
        login(request, authenticated)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号