<!DOCTYPE html>
<html>
    <head>
    <title><%block name="title">${_('Paramecio Login')}</%block></title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <link href='https://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css'>
    <link href="${make_media_url('css/login.css', 'admin')}" rel='stylesheet' type='text/css'>
    <link href="${make_media_url('css/font-awesome.min.css', 'admin')}" rel='stylesheet' type='text/css'>
    <%block name="extra_css">
    </%block>
    <script language="Javascript" src="${make_media_url('js/jquery.min.js', 'admin')}"></script>
    <%block name="extra_js">
    </%block>
    <%block name="ajax">
    <script language="javascript">
        $(document).ready( function () {
        
            $('#login_submit').click( function () {
            
                $('#loading').show();
                
                $('#login_submit').prop('disabled', true);
                
                data_form={'username': $('#username_form').val(), 'password': $('#password_form').val(), 'csrf_token': $("#csrf_token").val(), 'remember_login': 0};
            
                if($('#remember_login:checked').val())
                {
                    
                    data_form.remember_login=$('#remember_login').val();
                }
            
                $.ajax({
                url: "${make_url('admin/login')}",
                method: "POST",
                dataType: "json",
                contentType : 'application/json',
                data: JSON.stringify(data_form)
                }).done(function(data) {
                
                    if(data.error==0)
                    {
                        
                        //location.reload()
                        location.href="${make_url('admin')}";
                    
                    }
                    else
                    {
                     
                        $('#login_submit').prop('disabled', false);
                        
                        //$('#csrf_token').val(data.csrf_token);
                        
                        // Firefox have a horrible and stupid bug and you need attr for set de new csrf_token
                        
                        $('#csrf_token').attr('value', data.csrf_token);
                    
                        $('#loading').hide('slow');

                        if(data.hasOwnProperty('disable')) {
                            
                            $('#username_error').html("${_('Error, your user is disabled, you need support of web administration')}");
                            
                        } if(data.hasOwnProperty('you_cannot_login')) {
                            
                            if(data.you_cannot_login) {
                        
                                $('#username_error').html("${_('Error, excessive tries, wait some minutes for login again')}");
                                
                            }
                            else {
                            
                                $('#username_error').html("${_('Error, wrong username or password')}");
                                
                            }
                        
                        }
                        else {

                            $('#username_error').html("${_('Error, wrong username or password')}");
                            
                        }
                        
                    }
                
                });
                
                return false;
            
            });
        
        });
    </script>
    </%block>
    </head>
    <body>
        <%block name="content">
        <form id="login">
            <div id="title">
                ${_('Paramecio Login')}
            </div>
            ${forms|n}
            <div class="form">
                ${_('Remember login?')} <input type="checkbox" id="remember_login" name="remember_login" value="1">
            </div>
            <div id="submit_block">
                <input type="submit" value="${_('Login')}" class="submit" id="login_submit"/>
                <span id="loading">&nbsp;</span>
            </div>
            % if yes_recovery_login:
                <div class="form"><a href="${make_url('recovery_password')}">${_('Recovery password?')}</a></div>
            % endif
            <!--<div class="form">${_('Remember that only have 3 attempts')}</div>-->
        </form>
        </%block>
    </body>
</html>
