{%- set footer_content = get_part('login page footer', get_part('global footer')) %}
{%- set page_title = get_part('login page title', word('Sign in')) %}
{%- set tab_title = get_part('login page tab title', word('Sign in')) %}
{%- if extra_css is not defined %}
{%- set extra_css = get_part('login page extra css') %}
{%- endif %}
{%- if extra_js is not defined %}
{%- set extra_js = get_part('login page extra javascript') %}
{%- endif %}
{%- extends 'flask_user/public_base.html' %}
{%- block content %}
{%- from "base_templates/form_macros.html" import render_field, render_checkbox_field, render_submit_field, myrender_hidden_field %}
          <h1>{{ get_part('login page heading', word('Sign in')) }}</h1>
{{ get_part('login page pre') }}
          {%- if config['USE_PASSWORD_LOGIN'] or ('admin' in request.args and request.args['admin'] == '1') %}
          <form action="" method="POST" class="form" role="form">
            {{ form.hidden_tag() }}
            {%- set field = form.username if user_manager.enable_username else form.email %}
            <div class="da-form-group {% if field.errors %}da-group-has-error{% endif %}">
              <div class="row">
                <div class="col">
                  <label for="{{ field.id }}" class="form-label">{{ word(field.label.text) }}</label>
                </div>
                <div class="col">
                  <div class="text-end">
                  {%- if user_manager.enable_register and not user_manager.require_invitation %}
                  {%- if 'next' in request.args %}
                  <a href="{{ url_for('user.register', next=request.args['next']) }}">
                  {%- else %}
                  <a href="{{ url_for('user.register') }}">
                  {%- endif %}
                    {{ word("New here?  Register.") }}
                  </a>
                  {%- endif %}
                  </div>
                </div>
              </div>
              <div class="row">
                <div class="col">
                  {{ field(class_='form-control', type='email') }}
                </div>
              </div>
              {%- if field.errors %}
                {%- for e in field.errors %}
              <p class="da-has-error text-danger">{{ e }}</p>
                {%- endfor %}
              {%- endif %}
            </div>
            {%- set field = form.password %}
            <div class="da-form-group {% if field.errors %}da-group-has-error{% endif %}">
              <div class="row">
                <div class="col">
                  <label for="{{ field.id }}" class="form-label">{{ word(field.label.text) }}</label>
                </div>
                <div class="col">
                  <div class="text-end">
                  {%- if user_manager.enable_forgot_password %}
                  <a href="{{ url_for('user.forgot_password') }}">
                    {{ word("Forgot your Password?") }}
                  </a>
                  {%- endif %}
                  </div>
                </div>
              </div>
              <div class="row">
                <div class="col">
                  {{ field(class_='form-control') }}
                </div>
              </div>
              {%- if field.errors %}
                {%- for e in field.errors %}
              <p class="da-has-error text-danger">{{ e }}</p>
                {%- endfor %}
              {%- endif %}
            </div>
            {%- if user_manager.enable_remember_me %}
            {{ render_checkbox_field(login_form.remember_me) }}
            {%- endif %}
            {{ get_part('login page submit') }}<div class="form-actions">
              {{ render_submit_field(form.submit) }}
            </div>
          </form>
          {%- if config['USE_GOOGLE_LOGIN'] or config['USE_FACEBOOK_LOGIN'] or config['USE_TWITTER_LOGIN'] or config['USE_AUTH0_LOGIN'] or config['USE_KEYCLOAK_LOGIN'] or config['USE_AZURE_LOGIN'] or config['USE_PHONE_LOGIN'] %}
          <p style="padding: 15px 15px 5px 15px;"><strong>{{ word('or') }}</strong></p>
          {%- endif %}
          {%- endif %}
          {%- if config['USE_PHONE_LOGIN'] %}
          <div class="row danomargin">
            <div class="daiconbox col-md-7"><a role="button" class="danohover" href="{{ url_for('phone_login') }}"><table><tbody><tr><td style="padding-left:4px;vertical-align:middle;"><img alt="" src="{{ url_for('static', filename='app/phone-logo.png', v=config['DA_VERSION']) }}"></td><td style="width:100%;vertical-align:middle;text-align:center;">{{ word('Sign in with your mobile phone') }}</td></tr></tbody></table></a></div>
          </div>
          {%- endif %}
          {%- if config['USE_GOOGLE_LOGIN'] %}
          <div class="row danomargin">
              <div class="daiconbox col-md-7"><a role="button" class="danohover" href="{{ url_for('google_page', next=request.args.get('next', '')) }}"><table><tbody><tr><td style="padding-left:4px;vertical-align:middle;"><img alt="" src="{{ url_for('static', filename='app/google-logo.png', v=config['DA_VERSION']) }}"></td><td style="width:100%;vertical-align:middle;text-align:center;">{{ word('Sign in with Google') }}</td></tr></tbody></table></a></div>
          </div>
          {%- endif %}
          {%- if config['USE_FACEBOOK_LOGIN'] %}
          <div class="row danomargin">
            <div class="daiconbox col-md-7"><a role="button" class="danohover" href="{{ url_for('oauth_authorize', provider='facebook', next=request.args.get('next', '')) }}"><table><tbody><tr><td style="padding-left:4px;vertical-align:middle;"><img alt="" src="{{ url_for('static', filename='app/facebook-logo.png', v=config['DA_VERSION']) }}"></td><td style="width:100%;vertical-align:middle;text-align:center;">{{ word('Sign in with Facebook') }}</td></tr></tbody></table></a></div>
          </div>
          {%- endif %}
          {%- if config['USE_TWITTER_LOGIN'] %}
          <div class="row danomargin">
            <div class="daiconbox col-md-7"><a role="button" class="danohover" href="{{ url_for('oauth_authorize', provider='twitter', next=request.args.get('next', '')) }}"><table><tbody><tr><td style="padding-left:4px;vertical-align:middle;"><img alt="" src="{{ url_for('static', filename='app/twitter-logo.png', v=config['DA_VERSION']) }}"></td><td style="width:100%;vertical-align:middle;text-align:center;">{{ word('Sign in with Twitter') }}</td></tr></tbody></table></a></div>
          </div>
          {%- endif %}
          {%- if config['USE_AUTH0_LOGIN'] %}
          <div class="row danomargin">
            <div class="daiconbox col-md-7"><a role="button" class="danohover" href="{{ url_for('oauth_authorize', provider='auth0', next=request.args.get('next', '')) }}"><table><tbody><tr><td style="padding-left:4px;vertical-align:middle;"><img alt="" src="{{ url_for('static', filename='app/auth0-logo.png', v=config['DA_VERSION']) }}"></td><td style="width:100%;vertical-align:middle;text-align:center;">{{ word('Sign in with Auth0') }}</td></tr></tbody></table></a></div>
          </div>
          {%- endif %}
          {%- if config['USE_KEYCLOAK_LOGIN'] %}
          <div class="row danomargin">
            <div class="daiconbox col-md-7"><a role="button" class="danohover" href="{{ url_for('oauth_authorize', provider='keycloak', next=request.args.get('next', '')) }}"><table><tbody><tr><td style="padding-left:4px;vertical-align:middle;"><img alt="" src="{{ url_for('static', filename='app/keycloak-logo.png', v=config['DA_VERSION']) }}"></td><td style="width:100%;vertical-align:middle;text-align:center;">{{ word('Sign in with Keycloak') }}</td></tr></tbody></table></a></div>
          </div>
          {%- endif %}
          {%- if config['USE_AZURE_LOGIN'] %}
          <div class="row danomargin">
            <div class="daiconbox col-md-7"><a role="button" class="danohover" href="{{ url_for('oauth_authorize', provider='azure', next=request.args.get('next', '')) }}"><table style="height:100%"><tbody><tr><td style="padding-left:4px;vertical-align:middle;"><img alt="" src="{{ url_for('static', filename='app/azure-logo.png', v=config['DA_VERSION']) }}"></td><td style="width:100%;vertical-align:middle;text-align:center;">{{ word('Sign in with Azure') }}</td></tr></tbody></table></a></div>
          </div>
          {%- endif %}{{ get_part('login page post') }}
          {%- if False and config['USE_GOOGLE_LOGIN'] %}
          <script>
          function myOnLoadCallback() {
            console.log("myOnLoadCallback()");
          }
          </script>
          <script src="https://apis.google.com/js/platform.js?onload=myOnLoadCallback" async defer></script>
          <script>
            function onSignIn(googleUser) {
              var profile = googleUser.getBasicProfile();
              console.log('ID: ' + profile.getId());
              console.log('Name: ' + profile.getName());
              console.log('Image URL: ' + profile.getImageUrl());
              console.log('Email: ' + profile.getEmail());
              if (profile.getId()){
                $.ajax({
                  type: 'POST',
                  url: '{{ url_for('oauth_authorize', provider='google', next=request.args.get('next', '')) }}',
                  contentType: 'application/octet-stream; charset=utf-8',
                  success: function(result) {
                    console.log(result);
                    window.location = '{{ url_for('oauth_callback', provider='google', _external=True) }}';
                  },
                  dataType: "json",
                  data: {
                    "id": profile.getId(),
                    "name": profile.getName(),
                    "image": profile.getImageUrl(),
                    "email": profile.getEmail()
                  }
                });
              }
              else if (authResult['error']) {
                console.log('There was an error: ' + authResult['error']);
              }
            }
          </script>
          {%- endif %}
{%- endblock %}
