diff --git a/app/Controller/Admin/PasswordRecoveryController.php b/app/Controller/Admin/PasswordRecoveryController.php
index 6262f95..615d4f5 100644
--- a/app/Controller/Admin/PasswordRecoveryController.php
+++ b/app/Controller/Admin/PasswordRecoveryController.php
@@ -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([
@@ -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);
+ }
}
\ No newline at end of file
diff --git a/app/Functions/helpers.php b/app/Functions/helpers.php
index 7ee6a2e..2e86dba 100755
--- a/app/Functions/helpers.php
+++ b/app/Functions/helpers.php
@@ -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'];
+
}
\ No newline at end of file
diff --git a/app/Model/User.php b/app/Model/User.php
index 9e2f477..f4b44f0 100755
--- a/app/Model/User.php
+++ b/app/Model/User.php
@@ -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;
+
}
}
\ No newline at end of file
diff --git a/app/traits/Delete.php b/app/traits/Delete.php
index 796e992..23d178b 100755
--- a/app/traits/Delete.php
+++ b/app/traits/Delete.php
@@ -17,4 +17,10 @@ public function delete(){
return $delete->rowCount();
}
+
+ public function delete2(){
+ $this->binds = [];
+ $this->sql = "DELETE FROM {$this->table} ";
+ return $this;
+ }
}
\ No newline at end of file
diff --git a/app/traits/Read.php b/app/traits/Read.php
index af81d89..b6aa2e9 100755
--- a/app/traits/Read.php
+++ b/app/traits/Read.php
@@ -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 ...
@@ -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();
diff --git a/app/traits/Update.php b/app/traits/Update.php
index d43c412..c819a2e 100755
--- a/app/traits/Update.php
+++ b/app/traits/Update.php
@@ -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;
+
+ }
}
\ No newline at end of file
diff --git a/bootstrap.php b/bootstrap.php
index 58328f1..cd8acd7 100755
--- a/bootstrap.php
+++ b/bootstrap.php
@@ -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);
diff --git a/composer.json b/composer.json
index 56e314b..03f3a9d 100755
--- a/composer.json
+++ b/composer.json
@@ -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": {
diff --git a/composer.lock b/composer.lock
index c94e03c..123e9b4 100755
--- a/composer.lock
+++ b/composer.lock
@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
- "content-hash": "e694316cbc96be32b76ed0fca97b63e9",
+ "content-hash": "0793e010c3dc76b1e8f8ddd5b223af1d",
"packages": [
{
"name": "cakephp/cache",
@@ -374,6 +374,73 @@
"abandoned": "psr/container",
"time": "2017-02-14T19:40:03+00:00"
},
+ {
+ "name": "doctrine/inflector",
+ "version": "1.3.1",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/doctrine/inflector.git",
+ "reference": "ec3a55242203ffa6a4b27c58176da97ff0a7aec1"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/doctrine/inflector/zipball/ec3a55242203ffa6a4b27c58176da97ff0a7aec1",
+ "reference": "ec3a55242203ffa6a4b27c58176da97ff0a7aec1",
+ "shasum": ""
+ },
+ "require": {
+ "php": "^7.1"
+ },
+ "require-dev": {
+ "phpunit/phpunit": "^6.2"
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "1.3.x-dev"
+ }
+ },
+ "autoload": {
+ "psr-4": {
+ "Doctrine\\Common\\Inflector\\": "lib/Doctrine/Common/Inflector"
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Guilherme Blanco",
+ "email": "guilhermeblanco@gmail.com"
+ },
+ {
+ "name": "Roman Borschel",
+ "email": "roman@code-factory.org"
+ },
+ {
+ "name": "Benjamin Eberlei",
+ "email": "kontakt@beberlei.de"
+ },
+ {
+ "name": "Jonathan Wage",
+ "email": "jonwage@gmail.com"
+ },
+ {
+ "name": "Johannes Schmitt",
+ "email": "schmittjoh@gmail.com"
+ }
+ ],
+ "description": "Common String Manipulations with regard to casing and singular/plural rules.",
+ "homepage": "http://www.doctrine-project.org",
+ "keywords": [
+ "inflection",
+ "pluralize",
+ "singularize",
+ "string"
+ ],
+ "time": "2019-10-30T19:59:35+00:00"
+ },
{
"name": "dopesong/slim-whoops",
"version": "2.3.0",
@@ -555,6 +622,260 @@
],
"time": "2019-07-01T23:21:34+00:00"
},
+ {
+ "name": "illuminate/container",
+ "version": "v6.16.0",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/illuminate/container.git",
+ "reference": "7af0de3a43acaa78c4418b548fb2a66b0ce851c6"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/illuminate/container/zipball/7af0de3a43acaa78c4418b548fb2a66b0ce851c6",
+ "reference": "7af0de3a43acaa78c4418b548fb2a66b0ce851c6",
+ "shasum": ""
+ },
+ "require": {
+ "illuminate/contracts": "^6.0",
+ "php": "^7.2",
+ "psr/container": "^1.0"
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "6.x-dev"
+ }
+ },
+ "autoload": {
+ "psr-4": {
+ "Illuminate\\Container\\": ""
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Taylor Otwell",
+ "email": "taylor@laravel.com"
+ }
+ ],
+ "description": "The Illuminate Container package.",
+ "homepage": "https://laravel.com",
+ "time": "2020-01-07T13:47:03+00:00"
+ },
+ {
+ "name": "illuminate/contracts",
+ "version": "v6.16.0",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/illuminate/contracts.git",
+ "reference": "a6c7ef89684ce0e724b42c6bfe4b1107aee28a1d"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/illuminate/contracts/zipball/a6c7ef89684ce0e724b42c6bfe4b1107aee28a1d",
+ "reference": "a6c7ef89684ce0e724b42c6bfe4b1107aee28a1d",
+ "shasum": ""
+ },
+ "require": {
+ "php": "^7.2",
+ "psr/container": "^1.0",
+ "psr/simple-cache": "^1.0"
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "6.x-dev"
+ }
+ },
+ "autoload": {
+ "psr-4": {
+ "Illuminate\\Contracts\\": ""
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Taylor Otwell",
+ "email": "taylor@laravel.com"
+ }
+ ],
+ "description": "The Illuminate Contracts package.",
+ "homepage": "https://laravel.com",
+ "time": "2020-02-08T09:26:21+00:00"
+ },
+ {
+ "name": "illuminate/database",
+ "version": "v6.16.0",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/illuminate/database.git",
+ "reference": "f56c632e93e7ae8f675d5fd0d0b3b0a9eede1d22"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/illuminate/database/zipball/f56c632e93e7ae8f675d5fd0d0b3b0a9eede1d22",
+ "reference": "f56c632e93e7ae8f675d5fd0d0b3b0a9eede1d22",
+ "shasum": ""
+ },
+ "require": {
+ "ext-json": "*",
+ "illuminate/container": "^6.0",
+ "illuminate/contracts": "^6.0",
+ "illuminate/support": "^6.0",
+ "php": "^7.2"
+ },
+ "suggest": {
+ "doctrine/dbal": "Required to rename columns and drop SQLite columns (^2.6).",
+ "fzaninotto/faker": "Required to use the eloquent factory builder (^1.4).",
+ "illuminate/console": "Required to use the database commands (^6.0).",
+ "illuminate/events": "Required to use the observers with Eloquent (^6.0).",
+ "illuminate/filesystem": "Required to use the migrations (^6.0).",
+ "illuminate/pagination": "Required to paginate the result set (^6.0)."
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "6.x-dev"
+ }
+ },
+ "autoload": {
+ "psr-4": {
+ "Illuminate\\Database\\": ""
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Taylor Otwell",
+ "email": "taylor@laravel.com"
+ }
+ ],
+ "description": "The Illuminate Database package.",
+ "homepage": "https://laravel.com",
+ "keywords": [
+ "database",
+ "laravel",
+ "orm",
+ "sql"
+ ],
+ "time": "2020-02-18T15:08:16+00:00"
+ },
+ {
+ "name": "illuminate/pagination",
+ "version": "v6.16.0",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/illuminate/pagination.git",
+ "reference": "7a27077dd60ba6f9c974253795de963a331163b6"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/illuminate/pagination/zipball/7a27077dd60ba6f9c974253795de963a331163b6",
+ "reference": "7a27077dd60ba6f9c974253795de963a331163b6",
+ "shasum": ""
+ },
+ "require": {
+ "ext-json": "*",
+ "illuminate/contracts": "^6.0",
+ "illuminate/support": "^6.0",
+ "php": "^7.2"
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "6.x-dev"
+ }
+ },
+ "autoload": {
+ "psr-4": {
+ "Illuminate\\Pagination\\": ""
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Taylor Otwell",
+ "email": "taylor@laravel.com"
+ }
+ ],
+ "description": "The Illuminate Pagination package.",
+ "homepage": "https://laravel.com",
+ "time": "2020-01-07T13:47:03+00:00"
+ },
+ {
+ "name": "illuminate/support",
+ "version": "v6.16.0",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/illuminate/support.git",
+ "reference": "2f5f449750e6821f2d8c4e993a4ff77c7d7d5cc8"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/illuminate/support/zipball/2f5f449750e6821f2d8c4e993a4ff77c7d7d5cc8",
+ "reference": "2f5f449750e6821f2d8c4e993a4ff77c7d7d5cc8",
+ "shasum": ""
+ },
+ "require": {
+ "doctrine/inflector": "^1.1",
+ "ext-json": "*",
+ "ext-mbstring": "*",
+ "illuminate/contracts": "^6.0",
+ "nesbot/carbon": "^2.0",
+ "php": "^7.2"
+ },
+ "conflict": {
+ "tightenco/collect": "<5.5.33"
+ },
+ "suggest": {
+ "illuminate/filesystem": "Required to use the composer class (^6.0).",
+ "moontoast/math": "Required to use ordered UUIDs (^1.1).",
+ "ramsey/uuid": "Required to use Str::uuid() (^3.7).",
+ "symfony/process": "Required to use the composer class (^4.3.4).",
+ "symfony/var-dumper": "Required to use the dd function (^4.3.4).",
+ "vlucas/phpdotenv": "Required to use the Env class and env helper (^3.3)."
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "6.x-dev"
+ }
+ },
+ "autoload": {
+ "psr-4": {
+ "Illuminate\\Support\\": ""
+ },
+ "files": [
+ "helpers.php"
+ ]
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Taylor Otwell",
+ "email": "taylor@laravel.com"
+ }
+ ],
+ "description": "The Illuminate Support package.",
+ "homepage": "https://laravel.com",
+ "time": "2020-02-14T14:20:14+00:00"
+ },
{
"name": "intervention/image",
"version": "2.5.1",
@@ -625,6 +946,76 @@
],
"time": "2019-11-02T09:15:47+00:00"
},
+ {
+ "name": "nesbot/carbon",
+ "version": "2.30.0",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/briannesbitt/Carbon.git",
+ "reference": "912dff66d2690ca66abddb9b291a1df5f371d3b4"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/briannesbitt/Carbon/zipball/912dff66d2690ca66abddb9b291a1df5f371d3b4",
+ "reference": "912dff66d2690ca66abddb9b291a1df5f371d3b4",
+ "shasum": ""
+ },
+ "require": {
+ "ext-json": "*",
+ "php": "^7.1.8 || ^8.0",
+ "symfony/translation": "^3.4 || ^4.0 || ^5.0"
+ },
+ "require-dev": {
+ "friendsofphp/php-cs-fixer": "^2.14 || ^3.0",
+ "kylekatarnls/multi-tester": "^1.1",
+ "phpmd/phpmd": "^2.8",
+ "phpstan/phpstan": "^0.11",
+ "phpunit/phpunit": "^7.5 || ^8.0",
+ "squizlabs/php_codesniffer": "^3.4"
+ },
+ "bin": [
+ "bin/carbon"
+ ],
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "2.x-dev"
+ },
+ "laravel": {
+ "providers": [
+ "Carbon\\Laravel\\ServiceProvider"
+ ]
+ }
+ },
+ "autoload": {
+ "psr-4": {
+ "Carbon\\": "src/Carbon/"
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Brian Nesbitt",
+ "email": "brian@nesbot.com",
+ "homepage": "http://nesbot.com"
+ },
+ {
+ "name": "kylekatarnls",
+ "homepage": "http://github.com/kylekatarnls"
+ }
+ ],
+ "description": "An API extension for DateTime that supports 281 different languages.",
+ "homepage": "http://carbon.nesbot.com",
+ "keywords": [
+ "date",
+ "datetime",
+ "time"
+ ],
+ "time": "2020-02-07T15:25:46+00:00"
+ },
{
"name": "nikic/fast-route",
"version": "v1.3.0",
@@ -1641,6 +2032,140 @@
],
"time": "2019-11-18T17:27:11+00:00"
},
+ {
+ "name": "symfony/translation",
+ "version": "v5.0.4",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/symfony/translation.git",
+ "reference": "28e1054f1ea26c63762d9260c37cb1056ea62dbb"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/symfony/translation/zipball/28e1054f1ea26c63762d9260c37cb1056ea62dbb",
+ "reference": "28e1054f1ea26c63762d9260c37cb1056ea62dbb",
+ "shasum": ""
+ },
+ "require": {
+ "php": "^7.2.5",
+ "symfony/polyfill-mbstring": "~1.0",
+ "symfony/translation-contracts": "^2"
+ },
+ "conflict": {
+ "symfony/config": "<4.4",
+ "symfony/dependency-injection": "<5.0",
+ "symfony/http-kernel": "<5.0",
+ "symfony/twig-bundle": "<5.0",
+ "symfony/yaml": "<4.4"
+ },
+ "provide": {
+ "symfony/translation-implementation": "2.0"
+ },
+ "require-dev": {
+ "psr/log": "~1.0",
+ "symfony/config": "^4.4|^5.0",
+ "symfony/console": "^4.4|^5.0",
+ "symfony/dependency-injection": "^5.0",
+ "symfony/finder": "^4.4|^5.0",
+ "symfony/http-kernel": "^5.0",
+ "symfony/intl": "^4.4|^5.0",
+ "symfony/service-contracts": "^1.1.2|^2",
+ "symfony/yaml": "^4.4|^5.0"
+ },
+ "suggest": {
+ "psr/log-implementation": "To use logging capability in translator",
+ "symfony/config": "",
+ "symfony/yaml": ""
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "5.0-dev"
+ }
+ },
+ "autoload": {
+ "psr-4": {
+ "Symfony\\Component\\Translation\\": ""
+ },
+ "exclude-from-classmap": [
+ "/Tests/"
+ ]
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Fabien Potencier",
+ "email": "fabien@symfony.com"
+ },
+ {
+ "name": "Symfony Community",
+ "homepage": "https://symfony.com/contributors"
+ }
+ ],
+ "description": "Symfony Translation Component",
+ "homepage": "https://symfony.com",
+ "time": "2020-01-21T08:40:24+00:00"
+ },
+ {
+ "name": "symfony/translation-contracts",
+ "version": "v2.0.1",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/symfony/translation-contracts.git",
+ "reference": "8cc682ac458d75557203b2f2f14b0b92e1c744ed"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/symfony/translation-contracts/zipball/8cc682ac458d75557203b2f2f14b0b92e1c744ed",
+ "reference": "8cc682ac458d75557203b2f2f14b0b92e1c744ed",
+ "shasum": ""
+ },
+ "require": {
+ "php": "^7.2.5"
+ },
+ "suggest": {
+ "symfony/translation-implementation": ""
+ },
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "2.0-dev"
+ }
+ },
+ "autoload": {
+ "psr-4": {
+ "Symfony\\Contracts\\Translation\\": ""
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Nicolas Grekas",
+ "email": "p@tchwork.com"
+ },
+ {
+ "name": "Symfony Community",
+ "homepage": "https://symfony.com/contributors"
+ }
+ ],
+ "description": "Generic abstractions related to translation",
+ "homepage": "https://symfony.com",
+ "keywords": [
+ "abstractions",
+ "contracts",
+ "decoupling",
+ "interfaces",
+ "interoperability",
+ "standards"
+ ],
+ "time": "2019-11-18T17:27:11+00:00"
+ },
{
"name": "symfony/yaml",
"version": "v5.0.4",
diff --git a/phinx.yml b/phinx.yml
index e11a407..152fc11 100755
--- a/phinx.yml
+++ b/phinx.yml
@@ -19,7 +19,7 @@ environments:
host: localhost
name: twig_slim
user: root
- pass: '1475'
+ pass: 'nokia5233'
port: 3306
charset: utf8
diff --git a/public/index.php b/public/index.php
index f51adda..2e1e1a9 100755
--- a/public/index.php
+++ b/public/index.php
@@ -6,8 +6,13 @@
$app->get("/login","LoginController:index")->add($middleware->checkLoggedIn());
$app->post("/login","LoginController:store");
$app->get("/logout","LoginController:destroy");
-$app->get("/forgot-password","PasswordRecoveryController:forgot")->add($middleware->checkLoggedIn());
-$app->post("/forgot-password","PasswordRecoveryController:enviarLinkRecuperarSenha");
+
+$app->get("/forgot-password","PasswordRecoveryController:index")->add($middleware->checkLoggedIn());
+$app->post("/forgot-password","PasswordRecoveryController:checkMail");
+$app->get("/reset-password/code/{code}","PasswordRecoveryController:checkCode")->add($middleware->checkLoggedIn());
+$app->get("/reset-password-link-send","PasswordRecoveryController:linkConfirm");
+$app->get("/recover-password/user/{code}","PasswordRecoveryController:showFormUpdate")->add($middleware->checkLoggedIn());
+$app->post("/reset-password/user/{code}","PasswordRecoveryController:updatePassword");
$app->group("/painel/admin",function() use ($app){
$app->get("[/]","AdminController:index");
diff --git a/src/Controller.php b/src/Controller.php
index f7836f6..7904554 100755
--- a/src/Controller.php
+++ b/src/Controller.php
@@ -4,11 +4,17 @@
namespace Core;
use App\traits\View;
-
+use Slim\Container;
class Controller
{
+ protected $db;
+ public function __construct(Container $c)
+ {
+ $this->db = $c->db;
+ }
+
use View;
}
\ No newline at end of file
diff --git a/src/Email.php b/src/Email.php
index 3eeb8e3..52d434a 100644
--- a/src/Email.php
+++ b/src/Email.php
@@ -10,7 +10,7 @@
class Email extends PHPMailer
{
- public function __construct($html,$exceptions = null)
+ public function __construct($exceptions = null)
{
$this->SMTPDebug = SMTP::DEBUG_OFF;
@@ -24,14 +24,19 @@ public function __construct($html,$exceptions = null)
$this->isHTML(true);
$this->CharSet = 'UTF-8';
$this->setLanguage("pt_br");
- $this->setFrom("dcdouglas64@gmail.com");
- $this->addAddress("conveswebtecnologia@gmail.com");
- $this->addAddress("douglasflamengo_07@hotmail.com");
$this->addAddress("dcdouglas64@gmail.com");
- $this->Subject = "Recuperação de senha";
- $this->Body = $html;
+
parent::__construct($exceptions);
}
+ public function enviar($destinatario,$assunto,$message){
+
+ $this->setFrom("dcdouglas64@gmail.com");
+ $this->Subject = $assunto;
+ $this->Body = $message;
+
+ return $this->send();
+ }
+
}
\ No newline at end of file
diff --git a/src/PasswordRecovery.php b/src/PasswordRecovery.php
index 5f9b279..f5d4960 100644
--- a/src/PasswordRecovery.php
+++ b/src/PasswordRecovery.php
@@ -4,6 +4,8 @@
namespace Core;
use Core\Email;
+use \DateTime;
+use App\Model\User;
class PasswordRecovery extends Model
{
@@ -14,7 +16,6 @@ class PasswordRecovery extends Model
protected $message;
protected $table = "password_recovery";
-
private function codeCreate():void{
$hash = md5(rand());
@@ -24,7 +25,7 @@ private function codeCreate():void{
private function linkCreate():void{
$root = (!empty($_SERVER['HTTPS']) ? 'https' : 'http') . '://' . $_SERVER['HTTP_HOST'] . '/';
- $this->link = $root . "recovery-password/code={$this->code}";
+ $this->link = $root . "reset-password/code/{$this->code}";
}
private function messageCreate(){
@@ -47,10 +48,47 @@ public function sendMessageLink(object $user){
$this->codeCreate();
$this->linkCreate();
$this->recordAttempt();
- $email = new Email($this->link);
- $email = $email->send();
+ $email = new Email();
+ $email = $email->enviar($this->user->email,"Projeto Resgate - Recuperação de Senha","Recupere sua senha clicando no link: ".$this->link."
Obs:Este link tem validade de 1h.");
return $email;
}
+ public function checkValidateCode($code){
+
+ $codeUser = $this->select()->where2(["hash","=",$code])->first();
+
+ if(is_object($codeUser)){
+ $dateatual = new DateTime();
+ $dateresetrecovery = new DateTime($codeUser->created);
+ $intervalDiff = $dateatual->diff($dateresetrecovery);
+ if($intervalDiff->h > 0){
+ $this->delete2()->where2(["hash","=",$code])->exec();
+ flash("warning",error("Link de recuperação de senha EXPIRADO.
Favor solicitar recuperação de senha novamente."));
+ return false;
+ }
+ return true;
+ }
+
+ }
+
+ public function updatePassword(string $code,string $newPassword){
+
+
+ $user = $this->select()->where2(["hash","=",$code])->first();
+ $recoveryId = $user->id;
+ $userId = $user->user_id;
+ if(is_object($user)){
+ $userId = $user->user_id;
+ $user = new User();
+ $status = $user->update2(["password" => Password::make($newPassword)])->where2(["id","=",$userId])->exec();
+ if(empty($status->getErros())){
+ $statusRecover = $this->delete2()->where2(["user_id","=",$userId])->exec();
+ if(empty($statusRecover->getErros())){
+ Redirect::redirect("/login");
+ }
+ }
+ }
+ }
+
}
\ No newline at end of file
diff --git a/views/admin/email_template.html b/views/admin/email_template.html
new file mode 100644
index 0000000..ac43deb
--- /dev/null
+++ b/views/admin/email_template.html
@@ -0,0 +1,22 @@
+
+
+
+ Olá,{{ user->name }} tudo bem? +
+
+ Para alterar sua senha de usuário no site {{ site }}, clique no link abaixo:
+ {{ link }}
+
+ Obs: Esse link tem validade de 1h. +
+