<div class="modal-header">
    <button type="button" class="close" ng-click="close()" aria-label="Close"><span aria-hidden="true">&times;</span></button>
    <h4 class="modal-title">
        <i class="fa fa-key"></i> Two-step Login <small>email</small>
    </h4>
</div>
<form name="authTwoStepForm" ng-submit="authTwoStepForm.$valid && auth(authModel)" api-form="authPromise"
      ng-if="!authed">
    <div class="modal-body">
        <p>Enter your master password to modify two-step login settings.</p>
        <div class="callout callout-danger validation-errors" ng-show="authTwoStepForm.$errors">
            <h4>Errors have occurred</h4>
            <ul>
                <li ng-repeat="e in authTwoStepForm.$errors">{{e}}</li>
            </ul>
        </div>
        <div class="form-group" show-errors>
            <label for="masterPassword">Master Password</label>
            <input type="password" id="masterPassword" name="MasterPasswordHash" ng-model="authModel.masterPassword"
                   class="form-control" required api-field />
        </div>
    </div>
    <div class="modal-footer">
        <button type="submit" class="btn btn-primary btn-flat" ng-disabled="authTwoStepForm.$loading">
            <i class="fa fa-refresh fa-spin loading-icon" ng-show="authTwoStepForm.$loading"></i>Continue
        </button>
        <button type="button" class="btn btn-default btn-flat" ng-click="close()">Close</button>
    </div>
</form>
<form name="submitTwoStepForm" ng-submit="submitTwoStepForm.$valid && submit(updateModel)" api-form="submitPromise"
      ng-if="authed" autocomplete="off">
    <div class="modal-body">
        <div ng-if="enabled">
            <div class="callout callout-success">
                <h4><i class="fa fa-check-circle"></i> Enabled</h4>
                <p>Two-step log via email is enabled on your account.</p>
            </div>
            Email: <strong>{{updateModel.email}}</strong>
        </div>
        <div ng-if="!enabled">
            <div class="callout callout-danger validation-errors" ng-show="submitTwoStepForm.$errors">
                <h4>Errors have occurred</h4>
                <ul>
                    <li ng-repeat="e in submitTwoStepForm.$errors">{{e}}</li>
                </ul>
            </div>
            <p>Setting up two-step login with email is easy, just follow these steps:</p>
            <h4>1. Enter the email that you wish to receive verification codes</h4>
            <div class="form-group" show-errors>
                <label for="token" class="sr-only">Email</label>
                <input type="text" id="email" name="Email" placeholder="Email" ng-model="updateModel.email"
                       class="form-control" required api-field />
            </div>
            <button type="button" class="btn btn-default btn-flat" ng-click="sendEmail(updateModel)" ng-disabled="emailLoading">
                <i class="fa fa-refresh fa-spin loading-icon" ng-show="emailLoading"></i>
                Send Email
            </button>
            <span class="text-green" ng-if="emailSuccess">Verification code email was sent.</span>
            <span class="text-red" ng-if="emailError">An error occurred when trying to send the email.</span>
            <h4 style="margin-top: 30px;">
                2. Enter the resulting 6 digit verification code from the email
            </h4>
            <div class="form-group" show-errors>
                <label for="token" class="sr-only">Verification Code</label>
                <input type="text" id="token" name="Token" placeholder="Verification Code" ng-model="updateModel.token"
                       class="form-control" required api-field />
            </div>
        </div>
    </div>
    <div class="modal-footer">
        <button type="submit" class="btn btn-primary btn-flat" ng-disabled="submitTwoStepForm.$loading">
            <i class="fa fa-refresh fa-spin loading-icon" ng-show="submitTwoStepForm.$loading"></i>
            {{enabled ? 'Disable' : 'Enable'}}
        </button>
        <button type="button" class="btn btn-default btn-flat" ng-click="close()">Close</button>
    </div>
</form>