Skip to content

Commit

Permalink
Merge pull request #22 from douglas-88/dev
Browse files Browse the repository at this point in the history
Template admin
  • Loading branch information
douglas-88 authored Feb 23, 2020
2 parents 01836ee + dcd706e commit 60a518c
Show file tree
Hide file tree
Showing 20 changed files with 1,059 additions and 50 deletions.
63 changes: 55 additions & 8 deletions app/Controller/Admin/PasswordRecoveryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,34 @@

namespace App\Controller\Admin;


use App\Model\User;
use Core\Controller;
use Core\Load;
use Core\Password;
use Core\Redirect;
use Core\Validate;
use Core\PasswordRecovery;
use Slim\Http\Request;
use Slim\Http\Response;

class PasswordRecoveryController extends Controller
{

CONST SECRET = "DEUSNOCONTROLE!!";

public function forgot(){
/**
* Exibe formulário de informar o e-mail para enviar link:
*/
public function index(){

$this->view("admin/esqueceu_senha",["template_admin" => $this->templateAdmin]);

}

public function enviarLinkRecuperarSenha(){
/*
* Checa se o e-mail existe para poder enviar o link por e-mail.
* Se a mensagem foi enviada com sucesso, o usuário é redirecionado para uma tela de confirmação.
*/
public function checkMail(){

$validate = new Validate();
$data = $validate->validate([
Expand All @@ -36,17 +45,55 @@ public function enviarLinkRecuperarSenha(){
}

$config = (object) Load::file("/config.php");
$user = (new User())->select()->where("email",$data["email"])->first();
$user = (new User())->select()->where2(["email","=",$data["email"]])->first();

if(!$user){
echo("Não achou o e-mail: {$data["email"]}");
return false;
flash("warning",error("Email: {$data["email"]} não cadastrado."));
back();
}else{

$recovery = new PasswordRecovery();
dd($recovery->sendMessageLink($user));
$MessageStatus = $recovery->sendMessageLink($user);
if($MessageStatus){
flash("email",$data["email"]);
Redirect::redirect("/reset-password-link-send");
}

}

}

/*
* Verifica se o CÓDIGO existe no BD e se já não passou de 1h desde a solicitação.
* Se estiver tudo certo, o usuário é redirecionado a Tela de criar uma nova senha.
*/
public function checkCode(Request $request,Response $response,$args){

$code = $request->getAttribute("code");
$recovery = new PasswordRecovery();
if($recovery->checkValidateCode($code)){
Redirect::redirect("/recover-password/user/{$code}");
}else{
Redirect::redirect("/forgot-password");
}

}

public function showFormUpdate(Request $request,Response $response,$args){
$code = $request->getAttribute("code");

$this->view("admin/reset_senha",["template_admin" => $this->templateAdmin,"code" => $code]);
}

public function linkConfirm(){
$this->view("admin/link_enviado",["template_admin" => $this->templateAdmin]);
}

public function updatePassword(Request $request,Response $response,$args){
$code = $request->getAttribute("code");
$newPassword = $request->getParsedBodyParam("password");

$password = new PasswordRecovery();
$password->updatePassword($code,$newPassword);
}
}
6 changes: 6 additions & 0 deletions app/Functions/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,10 @@ function recoveryPasswordGenerate(){
$url = $root . "recovery-password/code={$code}";

return $url;
}

function url(){

return $root = (!empty($_SERVER['HTTPS']) ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'];

}
4 changes: 3 additions & 1 deletion app/Model/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@

namespace App\Model;

use Core\Model;

use Core\Model;

class User extends Model
{
protected $table = "users";
protected $fillable = ['name','password','email','phone','avatar','role_id','created'];

public function user(){
$id = $_SESSION["loginInfo"]["idUser"];
$user = $this->select()->where("id",$id)->first();
return $user;

}
}
6 changes: 6 additions & 0 deletions app/traits/Delete.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,10 @@ public function delete(){

return $delete->rowCount();
}

public function delete2(){
$this->binds = [];
$this->sql = "DELETE FROM {$this->table} ";
return $this;
}
}
26 changes: 26 additions & 0 deletions app/traits/Read.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ public function get():array{
return $select->fetchAll();
}

public function exec(){

$select = $this->connection->prepare($this->sql);
$select->execute($this->binds);
return $this;
}
/**
* Melhorar este método para que possa aceitar a o operador AND, por exemplo:
* WHERE field =:field AND field2 =:field2 ...
Expand Down Expand Up @@ -95,6 +101,26 @@ public function where():Model{
return $this;
}

public function where2(array $rules){

$this->sql .= " WHERE ";

foreach ($rules as $key => $value){
if(is_array($rules[$key])){
$this->sql .= "{$rules[$key][0]} {$rules[$key][1]} :{$rules[$key][0]} AND ";
$this->binds[$rules[$key][0]] = $rules[$key][2];
}else{
$this->sql .= "{$rules[0]} {$rules[1]} :{$rules[0]}";
$this->binds[$rules[0]] = $rules[2];
break;
}

}

$this->sql = rtrim($this->sql," AND ");
return $this;
}

public function paginate($perPage){

$this->paginate = new Paginate();
Expand Down
14 changes: 14 additions & 0 deletions app/traits/Update.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,18 @@ public function update(array $attributes):object{
}

}

public function update2(array $attributes){
$this->sql = "UPDATE {$this->table} SET ";

foreach ($attributes as $field => $value){
$this->sql .= "{$field} =:{$field},";
}

$this->sql = rtrim($this->sql,",");
$this->binds = $attributes;

return $this;

}
}
30 changes: 26 additions & 4 deletions bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,53 @@

$config['displayErrorDetails'] = true;
$config['addContentLengthHeader'] = false;
$config['db'] = [
'driver' => 'mysql',
'host' => $_ENV["DB_HOST"],
'database' => $_ENV["DB_DATABASE"],
'username' => $_ENV["DB_USERNAME"],
'password' => $_ENV["DB_PASSWORD"],
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => ''
];

$app = new App(['settings' => $config]);
$container = $app->getContainer();


$container['AdminController'] = function ($container) {
$service = new \App\Controller\Admin\AdminController;
$service = new \App\Controller\Admin\AdminController($container);
return $service;
};

$container['ProfessorController'] = function ($container) {
$service = new \App\Controller\Admin\ProfessorController();
$service = new \App\Controller\Admin\ProfessorController($container);
return $service;
};

$container['LoginController'] = function ($container) {
$service = new \App\Controller\Admin\LoginController();
$service = new \App\Controller\Admin\LoginController($container);
return $service;
};

$container['PasswordRecoveryController'] = function ($container) {
$service = new \App\Controller\Admin\PasswordRecoveryController();
$service = new \App\Controller\Admin\PasswordRecoveryController($container);
return $service;
};

$container['db'] = function ($container) {

$config = $container->get('settings');
$capsule = new \Illuminate\Database\Capsule\Manager;
$capsule->addConnection($config["db"]);
$capsule->setAsGlobal();
$capsule->bootEloquent();


return $capsule;
};

$whoops = new Whoops();
$whoops->run($container);

Expand Down
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
"dopesong/slim-whoops": "^2.3",
"robmorgan/phinx": "^0.11.4",
"intervention/image": "^2.5",
"phpmailer/phpmailer": "^6.1"
"phpmailer/phpmailer": "^6.1",
"illuminate/database": "^6.16",
"illuminate/pagination": "^6.16"
},
"autoload": {
"psr-4": {
Expand Down
Loading

0 comments on commit 60a518c

Please sign in to comment.