<?php

$app->post('/autenticar', function () use($app) {
    helpers::send(!helpers::getParam('usuario', $usuario), '', json_encode(array("usuario" => $usuario)));
});
function getClass($class, $id)
{
    if ($class == 'category' || $class == 'subcategory') {
        if (session::get('id_user') == 0) {
            return true;
        } else {
            if ($class == 'subcategory') {
                if ($id == 'new') {
                    helpers::getParam('id_category', $id);
                }
                $x = $class::find($id);
                if (!x) {
                    $id = -1;
                } else {
                    $id = $x->id_category;
                }
            }
            $p = checkPermisssions(session::get('id_user'));
            foreach ($p as $r) {
                if ($r->id_category == $id) {
                    $err = true;
                }
            }
            if (!$err) {
                return true;
            } else {
                return false;
            }
        }
    } else {
        return true;
    }
}
<?php

$app->post('/autenticar', function () use($app) {
    if (helpers::getParam('usuario', $usuario)) {
        $u = User::where('username', $usuario)->get();
        if (count($u) > 0) {
            if (helpers::getParam('senha', $senha)) {
                $us = User::where('username', $usuario)->where('password', md5(md5($senha)))->get();
                if (count($us) > 0) {
                    foreach ($us as $r) {
                        try {
                            $keyAcesso = md5($r->username . date(DATE_ATOM));
                            $keyAcesso = $keyAcesso . md5($r->password . date(DATE_ATOM));
                            if (count($acesso = Access::where('id_user', $r->id)->get()) > 0) {
                                Access::where('id_user', $r->id)->update(['accesskey' => $keyAcesso]);
                            } else {
                                $acesso = new Access();
                                $acesso->accesskey = $keyAcesso;
                                $acesso->id_user = $r->id;
                                $acesso->save();
                            }
                            $x = User::where('users.id', $r->id)->join('accesses AS a', 'a.id_user', '=', 'users.id')->select('users.*', 'a.accesskey')->get();
                            helpers::send(false, '', $x);
                        } catch (Exception $e) {
                            helpers::send(true, 'Ocorreu um erro ao gerar a key' . $e->getMessage(), '');
                        }
                    }
                } else {
                    helpers::send(true, 'Senha inválida', '');
                }
            } else {