{% extends "layout.html.twig" %}

{% block main %}

  <h4 class="text-success">恭喜，系统已安装成功！</h4>
  {% if response %}
     {{response.content|raw}}
  {% endif %}
  <div class="well key-result-well key-creating">
    正在生成授权码，请稍等...
    <br>
    <small class="text-muted">(如长时间未响应，请刷新页面重试。)</small>
  </div>

  <div class="well key-result-well key-create-fail hide">
    <p class="text-danger">授权码生成失败！ 原因是：</p>
    <p class="text-danger" id="error-reason"></p>
    <p><a href="" class="btn btn-danger">重试</a></p>
  </div>

  <div class="well key-result-well key-created hide">
    <p><strong>AccessKey:</strong> <span id="access-key"></span></p>
    <p><strong>SecretKey:</strong> <span id="secret-key"></span></p>
    <p class="text-warning"><strong>请妥善保管授权码，升级EduSoho系统、购买EduSoho应用、使用EduSoho云服务，都需使用此授权码。</strong></p>
  </div>
    <p>&nbsp;</p>
  <div class="actions">
    <p><a href="start-install.php?step=5" class="btn btn-primary disabled" id="go-btn">进入系统！</a></p>
  </div>


{% endblock %}

{% block bottom_scripts %}
<script>
  seajs.use(['jquery'], function($){
    window.$ = $;

    $.post('start-install.php?step=999', function(response) {
      $('.key-result-well').addClass('hide');
      if (response.accessKey && response.secretKey) {
        $("#access-key").text(response.accessKey);
        $("#secret-key").text(response.secretKey);
        $('.key-created').removeClass('hide');
      } else {
        if(response.error) {
          $("#error-reason").html(response.error);
        } else {
          $("#error-reason").html('生成Key失败，请联系EduSoho官方技术支持！');
        }
        $('.key-create-fail').removeClass('hide');
      }
    }, 'json').done(function(){
      $("#go-btn").removeClass('disabled');
    }).fail(function(){
      $("#error-reason").html('生成Key失败，请联系EduSoho官方技术支持！');
      $('.key-create-fail').removeClass('hide');
    });

  });
</script>

{% endblock %}