} } }); $app->post('/admin/customers/delete/:id', function ($id) use($app) { $customers = new customers(); $customers->deletar($id); $app->flash('sucesso', 'Cliente deletado com sucesso !'); $app->redirect('/admin/customers'); }); $app->post('/admin/customers/edit/:id', function () use($app) { $id = $app->request()->post('customer-id'); $name = $app->request()->post('customer-name'); $email = $app->request()->post('customer-email'); $pass = $app->request()->post('customer-pass'); $conf_pass = $app->request()->post('customer-conf-pass'); $validation = new validation(); $validacoes = array('customer-email' => 'obrigatorio', 'customer-pass' => 'obrigatorio'); $validar = $validation->validar($_POST, $validacoes); if ($pass != $conf_pass) { $app->flash('erro', 'As senhas não conferem. Digite novamente.'); $app->redirect('/admin/customers'); } else { if ($validar) { $attributes = array('name' => $name, 'email' => $email, 'password' => hash::hash($pass)); $customer = new customers(); $customer->atualizar($id, $attributes); $app->flash('sucesso', 'Dados do cliente alterados com sucesso !'); $app->redirect('/admin/customers'); } else { $app->flash('erro', $validation->mostrarErros()); $app->flash('nameAlbum', $name);
$app->get('/area-do-cliente', function () use($app, $twig) { $categories = categories::listar(); $dados = array('categories' => $categories); $template = $twig->loadTemplate('area-do-cliente.html'); $template->display($dados); }); $app->map('/area-do-cliente/logar', function () use($app, $twig) { if ($app->request()->isGet()) { $template = $twig->loadTemplate('home.html'); $template->display($dados); } else { $view = $app->view(); $view->setTemplatesDirectory(TEMPLATE_ADMIN); $email = $app->request()->post('email'); $pass = $app->request()->post('pass'); $validation = new validation(); $validacoes = array('email' => 'obrigatorio|email', 'pass' => 'obrigatorio'); $validar = $validation->validar($_POST, $validacoes); if ($validar) { $customer = new customers(); $customer->setCampos(array('email', 'password')); $logado = $customer->logar($email, hash::hash($pass)); if (count($logado) == 1) { $_SESSION['user_logado'] = true; $_SESSION['name'] = $logado->name; $categories = categories::listar(); $customer = customers::where('name', $_SESSION['name']); $id = $customer->id; $dados = array('categories' => $categories, 'logado' => $_SESSION['user_logado'], 'customer' => $customer); $app->redirect('/area-do-cliente/' . $id); } else {