Example #1
0
use PlataformaVirtual\User;
/*
 |--------------------------------------------------------------------------
 | Application Routes
 |--------------------------------------------------------------------------
 |
 | Here is where you can register all of the routes for an application.
 | It's a breeze. Simply tell Laravel the URIs it should respond to
 | and give it the controller to call when that URI is requested.
 |
*/
Route::post('signin', function () {
    $credentials = Input::only('email', 'password');
    $correo = Input::get('email');
    if ($token = JWTAuth::attempt($credentials)) {
        $user = \PlataformaVirtual\User::where("email", "=", $correo)->where('vigencia', '=', true)->first();
        $empleado = PlataformaVirtual\Models\Empleado::find($user->codigopersona);
        if ($user->is('admin') && Input::get('tipo') == 1) {
            return response()->json(compact('token'));
        } elseif ($user->is('mype') && Input::get('tipo') == 2) {
            //            if(true){} validar vigencia tipo definido o no
            return response()->json(['tokenN' => $token, 'tipoEmpleado' => $empleado->tipo], 200);
        } elseif ($user->is('client') && Input::get('tipo') == 3) {
            return response()->json(compact('token'));
        } else {
            return response()->json(['error' => 'No tiene Permisos.'], 401);
        }
    }
    return response()->json(['error' => 'Datos Invalidos o Incompletos.'], 401);
});
Route::post('/signup', function () {
 /**
  * Create a new user instance after a valid registration.
  *
  * @param  array  $data
  * @return User
  */
 protected function create(array $data)
 {
     return User::create(['name' => $data['name'], 'email' => $data['email'], 'password' => bcrypt($data['password'])]);
 }