<?php

require_once 'includes/inicio.php';

$cms = 'cms/';
$baseUrl = Util::baseUrl() . $cms;

if (!isset($_GET['token']) || (strlen($_GET['token']) < 30)) {
    Message::error('Código inválido.');
    header('Location: ' . $baseUrl . 'login.php');
} else {
    $validarToken = Usuario::validarToken($_GET['token']);

    if (!$validarToken) {
        Message::error('Código inválido.');
        header('Location: ' . $baseUrl . 'login.php');
    }
}
?>
<!doctype html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7" lang="en"> <![endif]-->
<!--[if IE 7]>    <html class="no-js lt-ie9 lt-ie8" lang="en"> <![endif]-->
<!--[if IE 8]>    <html class="no-js lt-ie9" lang="en"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en"> <!--<![endif]-->
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title>Yak || Cappen.com</title>
    <meta name="description" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <link rel="stylesheet" href="<?php echo $baseUrl; ?>public/css/neo/stylesheet.css">
    <link rel="stylesheet" href="<?php echo $baseUrl; ?>public/css/styleLogin.css">
    <script src="<?php echo $baseUrl; ?>public/js/libs/modernizr-2.5.3.min.js"></script>
</head>
<body>
    <!--[if lt IE 7]><p class=chromeframe>Your browser is <em>ancient!</em> <a href="http://browsehappy.com/">Upgrade to a different browser</a> or <a href="http://www.google.com/chromeframe/?redirect=true">install Google Chrome Frame</a> to experience this site.</p><![endif]-->
    <div class="wrapper">
        <header>
            <h1 class="logo">YAK</h1>
            <h2><span id="left" class="separador"></span>seja bem vindo ao <strong>yak</strong><span id="right" class="separador"></span></h2>
        </header>
        <div id="main">
            <form action="<?php echo $baseUrl; ?>login/recuperar.php" method="post" id="formLogin">
                <input type="hidden" name="token" id="token" value="<?php echo $_GET['token']; ?>" />
                <input type="text" name="senha" id="senha" placeholder="Nova senha" />
                <input type="text" name="confirmar" id="confirmar" placeholder="Confirmar nova senha" />
                <button type="submit"><span>NOVA</span> SENHA</button>
            </form>
            <?php
                // Mensagem de Retorno
                if (Message::hasErrors()) {
                    echo '<h2 class="erro">' . Message::showErrors() . '</h2>';
                }
            ?>
        </div>
    </div>
    <footer>
        <hr />
        <a href="http://www.cappen.com" target="_blank" id="cappen" title="Sistema desenvolvido pela CAPPEN"><span class="hover"><span class="logo"></span></span> Sistema desenvolvido pela CAPPEN</a>
    </footer>

    <script src="<?php echo $baseUrl; ?>public/js/libs/jquery-1.7.1.min.js"></script>
    <script src="<?php echo $baseUrl; ?>public/js/libs/jquery.easing.1.3.js"></script>
    <script src="<?php echo $baseUrl; ?>public/js/validacao.js"></script>
    <script src="<?php echo $baseUrl; ?>public/js/jquery.placeholder.min.js"></script>
    <script>
        $(document).ready(function() {
            $('.clearInput').clearInput();

            $("button[type='submit']").on('click', function (e) {
                e.preventDefault();

                var campos = [
                    {campo: 'token', valor: 'Token recebido no e-mail'},
                    {campo: 'senha', valor: 'Digite a nova senha'},
                    {campo: 'confirmar', valor: 'Confirme a sua nova senha'}
                ];

                var validacao = validaLogin(campos);

                if (validacao == true) {
                    $("#formLogin").submit();
                }
            });
        });
    </script>
</body>
</html>
