Sha256: 6fe84f11f237010b32ec02c4f224f85783de03d9db0fefbc74f7f5ac8a706dc2

Contents?: true

Size: 1.33 KB

Versions: 23

Compression:

Stored size: 1.33 KB

Contents

<script src="https://cdn.jsdelivr.net/npm/leancloud-storage/dist/av-min.js"></script>
<script type="text/javascript">
  let appId = '{{ site.Leancloud.appId }}';
  let appKey = '{{ site.Leancloud.appKey }}';
  let serverURL = '{{ site.Leancloud.serverURL }}';
  AV.init({
    appId: appId,
    appKey: appKey,
    serverURL: serverURL,
  });

  const currentUser = AV.User.current();
  
  if (currentUser != null) {
    if (currentUser.get('avatar')) {
      document.getElementById('avatar').getElementsByTagName('img')[0].src = currentUser.get('avatar');
    }
    if (currentUser.get('nickname')) {
      document.querySelector('.site-title a').innerText = "Hi " + currentUser.get('nickname') + " !";
    } else if (currentUser.get('username')) {
      document.querySelector('.site-title a').innerText = "Hi " + currentUser.get('username') + "!";
    }
  }

  function checkLogin() {
    if (currentUser != null) {
      document.body.style.display = 'block';
    } else {
      /* 显示注册或登录页面 */
      let originalUrl = window.location.href;

      window.location.href = '{{ site.baseurl }}/login?redirect=' + encodeURIComponent(originalUrl);
      /* window.location.href = '{{ site.baseurl }}/login'; */
    }
  };
  /* 在页面加载时调用checkLogin函数检查登录状态 */
  window.addEventListener('load', checkLogin);
</script>

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
jekyll-theme-chirpy-customized-upe-4.0.0 _includes/login-check.html
jekyll-theme-chirpy-customized-upe-4.0.0.pre.beta2 _includes/login-check.html
jekyll-theme-chirpy-customized-upe-3.2.0 _includes/login-check.html
jekyll-theme-chirpy-customized-upe-3.2.0.pre.beta3 _includes/login-check.html
jekyll-theme-chirpy-customized-upe-3.2.0.pre.beta2 _includes/login-check.html
jekyll-theme-chirpy-customized-upe-3.2.0.pre.beta1 _includes/login-check.html
jekyll-theme-chirpy-customized-upe-3.1.4 _includes/login-check.html
jekyll-theme-chirpy-customized-upe-3.1.2 _includes/login-check.html
jekyll-theme-chirpy-customized-upe-3.1.1 _includes/login-check.html
jekyll-theme-chirpy-customized-upe-3.1.0 _includes/login-check.html
jekyll-theme-chirpy-customized-upe-3.0.1 _includes/login-check.html
jekyll-theme-chirpy-customized-upe-3.0.0 _includes/login-check.html
jekyll-theme-chirpy-customized-upe-1.0.2 _includes/login-check.html
jekyll-theme-chirpy-customized-upe-1.0.1 _includes/login-check.html
jekyll-theme-chirpy-customized-upe-1.0.0 _includes/login-check.html
jekyll-theme-chirpy-customized-upe-0.1.2 _includes/login-check.html
jekyll-theme-chirpy-customized-upe-0.1.1 _includes/login-check.html
jekyll-theme-chirpy-customized-upe-0.1.0 _includes/login-check.html
jekyll-theme-chirpy-customized-upe-0.0.9 _includes/login-check.html
jekyll-theme-chirpy-customized-upe-0.0.8 _includes/login-check.html