<?php

use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
//Autentificación

Route::get('/', function(){
    if(Auth::check()){
        if(session('user_agent') == 'Admin')
            return redirect('/usuarios');
        else
            return redirect('/buscador');
    }
    else{
        return redirect('/login');
    }
});

Route::get('/recuperarContraseña', 'Inside\AuthController@indexRecPass');
Route::post('/recuperarContraseña', 'Inside\AuthController@sendMailRestore');
Route::get('/cambiarContraseña/{token?}', 'Inside\AuthController@changePassword');
Route::post('/cambiarContraseña', 'Inside\AuthController@saveNewPassword');
Route::get('/error', 'Inside\ErrorController');
Route::get('/login', 'Inside\AuthController@index')->name('login');
Route::post('/', 'Inside\AuthController@authenticate');
Route::get('/historial/{url?}', 'Inside\MainController@generateHistory');
Route::get('/clear-cache', function() {
    Artisan::call('cache:clear');
     return "Cache is cleared";
});

Route::middleware(['auth'])->group(function(){
    Route::get('/logout', 'Inside\AuthController@logout');
    Route::get('/buscador', 'Inside\MainController@index');
    Route::post('/buscador', 'Inside\MainController@generateTicket');
    // Route::post('/recibo','Inside\MainController@generate_recibo');
    
    Route::middleware(['admin'])->group(Function(){
        Route::get('/roles', 'Inside\RolesController@index');
        Route::post('/roles', 'Inside\RolesController@roles');

        Route::get('/bitacora_errores', 'Inside\ErrorsLogController@index');
        Route::post('/bitacora_errores', 'Inside\ErrorsLogController@errors');
    
        Route::get('/bitacora_correos', 'Inside\MailsLogController@index');
        Route::post('/bitacora_correos', 'Inside\MailsLogController@mails');

        Route::get('/usuarios', 'inside\UsersController@index');
        Route::post('/usuarios', 'inside\UsersController@users');
        Route::get('/registrar_usuario', 'inside\UsersController@new');
        Route::post('/registrar_usuario', 'inside\UsersController@save');
        Route::get('/modificar_usuario/{id}', 'inside\UsersController@updated');
        Route::post('/modificar_usuario/{id?}', 'inside\UsersController@save');

    });
});

