diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 00000000..a7a86767 Binary files /dev/null and b/.DS_Store differ diff --git a/src/.DS_Store b/src/.DS_Store new file mode 100644 index 00000000..9502d5c2 Binary files /dev/null and b/src/.DS_Store differ diff --git a/src/Api/Controllers/AuthController.php b/src/Api/Controllers/AuthController.php index 2b6fbc9c..9dd0fdd6 100644 --- a/src/Api/Controllers/AuthController.php +++ b/src/Api/Controllers/AuthController.php @@ -20,9 +20,9 @@ use Canvas\Notifications\ResetPassword; use Canvas\Notifications\Signup; use Canvas\Notifications\UpdateEmail; -use Canvas\Traits\AuthTrait; -use Canvas\Traits\SocialLoginTrait; -use Canvas\Traits\TokenTrait; +use Canvas\Contracts\AuthTrait; +use Canvas\Contracts\SocialLoginTrait; +use Canvas\Contracts\TokenTrait; use Exception; use Phalcon\Http\Response; use Phalcon\Validation\Validator\Confirmation; @@ -341,34 +341,6 @@ public function loginBySocial() : Response ); } - /** - * Send the user how filled out the form to the specify email - * a link to reset his password. - * - * @return Response - */ - public function recover() : Response - { - $request = $this->request->getPostData(); - - $validation = new CanvasValidation(); - $validation->add('email', new EmailValidator(['message' => _('The email is not valid.')])); - - $validation->validate($request); - - $email = $validation->getValue('email'); - - $recoverUser = Users::getByEmail($email); - $recoverUser->generateForgotHash(); - - $resetPassword = new ResetPassword($recoverUser); - $resetPassword->setFrom($recoverUser); - - $recoverUser->notify($resetPassword); - - return $this->response(_('Check your email to recover your password')); - } - /** * Reset the user password. * diff --git a/src/Api/Controllers/FilesystemController.php b/src/Api/Controllers/FilesystemController.php index 0f08b6fe..c1fa3e3e 100644 --- a/src/Api/Controllers/FilesystemController.php +++ b/src/Api/Controllers/FilesystemController.php @@ -5,7 +5,7 @@ namespace Canvas\Api\Controllers; use Canvas\Models\FileSystem; -use Canvas\Traits\FileManagementTrait; +use Canvas\Contracts\FileManagementTrait; class FilesystemController extends BaseController { diff --git a/src/Api/Controllers/FilesystemEntitiesController.php b/src/Api/Controllers/FilesystemEntitiesController.php index 377d0d8e..2dc7fda6 100644 --- a/src/Api/Controllers/FilesystemEntitiesController.php +++ b/src/Api/Controllers/FilesystemEntitiesController.php @@ -5,7 +5,7 @@ namespace Canvas\Api\Controllers; use Canvas\Models\FileSystemEntities; -use Canvas\Traits\FileManagementTrait; +use Canvas\Contracts\FileManagementTrait; /** * Class BaseController. diff --git a/src/Api/Controllers/UsersController.php b/src/Api/Controllers/UsersController.php index d1eb4d72..b84db62e 100644 --- a/src/Api/Controllers/UsersController.php +++ b/src/Api/Controllers/UsersController.php @@ -14,7 +14,7 @@ use Phalcon\Http\Response; use Phalcon\Validation\Validator\PresenceOf; use Baka\Contracts\Http\Api\CrudBehaviorTrait; -use Canvas\Traits\UsersTrait; +use Canvas\Contracts\UsersTrait; class UsersController extends BaseController { diff --git a/src/Api/Controllers/UsersInviteController.php b/src/Api/Controllers/UsersInviteController.php index 16cac031..c9c7460d 100644 --- a/src/Api/Controllers/UsersInviteController.php +++ b/src/Api/Controllers/UsersInviteController.php @@ -12,7 +12,7 @@ use Canvas\Models\Users; use Canvas\Models\UsersInvite; use Canvas\Notifications\Invitation; -use Canvas\Traits\AuthTrait; +use Canvas\Contracts\AuthTrait; use Exception; use Phalcon\Http\Response; use Phalcon\Security\Random; diff --git a/src/Auth/Models/Companies.php b/src/Auth/Models/Companies.php index bf6311b9..03b0b25d 100644 --- a/src/Auth/Models/Companies.php +++ b/src/Auth/Models/Companies.php @@ -16,16 +16,6 @@ class Companies extends Model public ?string $website = null; public int $users_id; - /** - * Initialize method for model. - */ - public function initialize() - { - $this->setSource('companies'); - $this->belongsTo('users_id', 'Baka\Auth\Models\Users', 'id', ['alias' => 'user']); - $this->hasMany('id', 'Baka\Auth\Models\CompanySettings', 'id', ['alias' => 'settings']); - } - /** * Model validation. * diff --git a/src/Traits/AuthTrait.php b/src/Contracts/AuthTrait.php similarity index 89% rename from src/Traits/AuthTrait.php rename to src/Contracts/AuthTrait.php index a38dc066..0a62a124 100644 --- a/src/Traits/AuthTrait.php +++ b/src/Contracts/AuthTrait.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Canvas\Traits; +namespace Canvas\Contracts; use Canvas\Models\Sessions; use Canvas\Auth\Auth; @@ -175,46 +175,32 @@ public function signup() : Response } /** - * Recover user information, by getting the email for the reset pass form. - * - * @method POST - * @url /v1/recover + * Send the user how filled out the form to the specify email + * a link to reset his password. * * @return Response */ public function recover() : Response { - //if the user submited the form and passes the security check then we start checking - $email = $this->request->getPost('email', 'email'); + $request = $this->request->getPostData(); - $validation = new Validation(); + $validation = new CanvasValidation(); $validation->add('email', new PresenceOf(['message' => _('The email is required.')])); - $validation->add('email', new EmailValidator(['message' => _('The email is invalid.')])); + $validation->add('email', new EmailValidator(['message' => _('The email is not valid.')])); - $messages = $validation->validate($this->request->getPost()); - if (count($messages)) { - foreach ($messages as $message) { - throw new Exception($message); - } - } + $validation->validate($request); - /** - * check if the user email exist - * if it does creat the user activation key to send - * send the user email. - * - * if it doesnt existe then send the erro msg - */ - if ($recoverUser = Users::getByEmail($email)) { - $recoverUser->user_activation_forgot = $recoverUser->generateActivationKey(); - $recoverUser->update(); + $email = $validation->getValue('email'); - $message = _('Please check your email inbox to complete the password recovery.'); - } else { - $message = _('There is no account registered with that email.'); - } + $recoverUser = Users::getByEmail($email); + $recoverUser->generateForgotHash(); + + $resetPassword = new ResetPassword($recoverUser); + $resetPassword->setFrom($recoverUser); + + $recoverUser->notify($resetPassword); - return $this->response($message); + return $this->response(_('Check your email to recover your password')); } /** diff --git a/src/Traits/EventManagerAwareTrait.php b/src/Contracts/EventManagerAwareTrait.php similarity index 98% rename from src/Traits/EventManagerAwareTrait.php rename to src/Contracts/EventManagerAwareTrait.php index 43c72025..ce311bf0 100644 --- a/src/Traits/EventManagerAwareTrait.php +++ b/src/Contracts/EventManagerAwareTrait.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Canvas\Traits; +namespace Canvas\Contracts; use Phalcon\Di; use Phalcon\Events\ManagerInterface as EventsManager; diff --git a/src/Traits/FileManagementTrait.php b/src/Contracts/FileManagementTrait.php similarity index 99% rename from src/Traits/FileManagementTrait.php rename to src/Contracts/FileManagementTrait.php index cc8c1d4b..c801e89e 100644 --- a/src/Traits/FileManagementTrait.php +++ b/src/Contracts/FileManagementTrait.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Canvas\Traits; +namespace Canvas\Contracts; use Baka\Http\Exception\UnprocessableEntityException; use Canvas\Filesystem\Helper; diff --git a/src/Traits/FileSystemModelTrait.php b/src/Contracts/FileSystemModelTrait.php similarity index 99% rename from src/Traits/FileSystemModelTrait.php rename to src/Contracts/FileSystemModelTrait.php index ac5b03e2..eadadb84 100644 --- a/src/Traits/FileSystemModelTrait.php +++ b/src/Contracts/FileSystemModelTrait.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Canvas\Traits; +namespace Canvas\Contracts; use Canvas\Dto\Files; use Canvas\Mapper\FileMapper; diff --git a/src/Traits/FractalTrait.php b/src/Contracts/FractalTrait.php similarity index 95% rename from src/Traits/FractalTrait.php rename to src/Contracts/FractalTrait.php index ed4cdfd7..312e6054 100644 --- a/src/Traits/FractalTrait.php +++ b/src/Contracts/FractalTrait.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Canvas\Traits; +namespace Canvas\Contracts; use League\Fractal\Manager; use League\Fractal\Serializer\JsonApiSerializer; @@ -29,7 +29,8 @@ trait FractalTrait * * @return array */ - protected function format(string $method, $results, string $transformer, string $resource, array $relationships = [], array $fields = []): array { + protected function format(string $method, $results, string $transformer, string $resource, array $relationships = [], array $fields = []): array + { $url = envValue('APP_URL', 'http://localhost'); $manager = new Manager(); $manager->setSerializer(new JsonApiSerializer($url)); diff --git a/src/Traits/NotificationsTrait.php b/src/Contracts/NotificationsTrait.php similarity index 98% rename from src/Traits/NotificationsTrait.php rename to src/Contracts/NotificationsTrait.php index 08fa9166..91c15471 100644 --- a/src/Traits/NotificationsTrait.php +++ b/src/Contracts/NotificationsTrait.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Canvas\Traits; +namespace Canvas\Contracts; use Canvas\Models\SystemModules; use Canvas\Models\Notifications; diff --git a/src/Traits/PermissionsTrait.php b/src/Contracts/PermissionsTrait.php similarity index 99% rename from src/Traits/PermissionsTrait.php rename to src/Contracts/PermissionsTrait.php index c0f08e25..66ebe10e 100644 --- a/src/Traits/PermissionsTrait.php +++ b/src/Contracts/PermissionsTrait.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Canvas\Traits; +namespace Canvas\Contracts; use Baka\Http\Exception\InternalServerErrorException; use Baka\Http\Exception\UnauthorizedException; @@ -79,7 +79,7 @@ public function assignRoleById(int $id) : bool "users_id" => $this->getId(), "apps_id" => $role->apps_id, "companies_id" => $this->currentCompanyId() - ]],[ + ]], [ "users_id" => $this->getId(), "roles_id" => $role->getId(), "apps_id" => $role->apps_id, diff --git a/src/Traits/RequestJwtTrait.php b/src/Contracts/RequestJwtTrait.php similarity index 94% rename from src/Traits/RequestJwtTrait.php rename to src/Contracts/RequestJwtTrait.php index 030df088..0134eb4c 100644 --- a/src/Traits/RequestJwtTrait.php +++ b/src/Contracts/RequestJwtTrait.php @@ -2,8 +2,7 @@ declare(strict_types=1); -namespace Canvas\Traits; - +namespace Canvas\Contracts; /** * Trait TokenTrait. diff --git a/src/Traits/ResponseTrait.php b/src/Contracts/ResponseTrait.php similarity index 96% rename from src/Traits/ResponseTrait.php rename to src/Contracts/ResponseTrait.php index 9040282b..5dcf5413 100644 --- a/src/Traits/ResponseTrait.php +++ b/src/Contracts/ResponseTrait.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Canvas\Traits; +namespace Canvas\Contracts; use Canvas\Http\Response; use Phalcon\Mvc\Micro; diff --git a/src/Traits/SocialLoginTrait.php b/src/Contracts/SocialLoginTrait.php similarity index 99% rename from src/Traits/SocialLoginTrait.php rename to src/Contracts/SocialLoginTrait.php index f79b8241..14cc54f6 100644 --- a/src/Traits/SocialLoginTrait.php +++ b/src/Contracts/SocialLoginTrait.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Canvas\Traits; +namespace Canvas\Contracts; use Canvas\Auth\Auth; use Baka\Http\Exception\UnprocessableEntityException; diff --git a/src/Traits/SubscriptionPlanLimitTrait.php b/src/Contracts/SubscriptionPlanLimitTrait.php similarity index 99% rename from src/Traits/SubscriptionPlanLimitTrait.php rename to src/Contracts/SubscriptionPlanLimitTrait.php index 2fac52ba..d6f05aec 100644 --- a/src/Traits/SubscriptionPlanLimitTrait.php +++ b/src/Contracts/SubscriptionPlanLimitTrait.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Canvas\Traits; +namespace Canvas\Contracts; use function Baka\getShortClassName; use Canvas\Exception\SubscriptionPlanLimitException; diff --git a/src/Traits/TokenTrait.php b/src/Contracts/TokenTrait.php similarity index 97% rename from src/Traits/TokenTrait.php rename to src/Contracts/TokenTrait.php index 46504b5e..45cdf909 100644 --- a/src/Traits/TokenTrait.php +++ b/src/Contracts/TokenTrait.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Canvas\Traits; +namespace Canvas\Contracts; use Lcobucci\JWT\Parser; use Lcobucci\JWT\Token; diff --git a/src/Traits/UsersAssociatedTrait.php b/src/Contracts/UsersAssociatedTrait.php similarity index 98% rename from src/Traits/UsersAssociatedTrait.php rename to src/Contracts/UsersAssociatedTrait.php index a9a832d0..54f85381 100644 --- a/src/Traits/UsersAssociatedTrait.php +++ b/src/Contracts/UsersAssociatedTrait.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Canvas\Traits; +namespace Canvas\Contracts; use Canvas\Models\Companies; use Canvas\Models\Roles; diff --git a/src/Traits/UsersTrait.php b/src/Contracts/UsersTrait.php similarity index 97% rename from src/Traits/UsersTrait.php rename to src/Contracts/UsersTrait.php index fe042408..c2d11fcf 100644 --- a/src/Traits/UsersTrait.php +++ b/src/Contracts/UsersTrait.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Canvas\Traits; +namespace Canvas\Contracts; use Canvas\Auth\Models\Companies; use Canvas\Auth\Models\Users; diff --git a/src/Middleware/NotFoundMiddleware.php b/src/Middleware/NotFoundMiddleware.php index 6d39a58c..bd54f078 100644 --- a/src/Middleware/NotFoundMiddleware.php +++ b/src/Middleware/NotFoundMiddleware.php @@ -5,7 +5,7 @@ namespace Canvas\Middleware; use Canvas\Http\Response; -use Canvas\Traits\ResponseTrait; +use Canvas\Contracts\ResponseTrait; use Phalcon\Mvc\Micro; use Phalcon\Mvc\Micro\MiddlewareInterface; use Phalcon\Di\Injectable; diff --git a/src/Middleware/ThrottleMiddleware.php b/src/Middleware/ThrottleMiddleware.php index d67c0f6d..cf0d6c57 100644 --- a/src/Middleware/ThrottleMiddleware.php +++ b/src/Middleware/ThrottleMiddleware.php @@ -5,7 +5,7 @@ namespace Canvas\Middleware; use Canvas\Http\Response; -use Canvas\Traits\ResponseTrait; +use Canvas\Contracts\ResponseTrait; use Phalcon\Mvc\Micro; use Phalcon\Mvc\Micro\MiddlewareInterface; use Phalcon\Mvc\User\Plugin; diff --git a/src/Middleware/TokenBase.php b/src/Middleware/TokenBase.php index 75391de5..afe3e7f4 100644 --- a/src/Middleware/TokenBase.php +++ b/src/Middleware/TokenBase.php @@ -4,8 +4,8 @@ namespace Canvas\Middleware; -use Canvas\Traits\TokenTrait; -use Canvas\Traits\SubscriptionPlanLimitTrait; +use Canvas\Contracts\TokenTrait; +use Canvas\Contracts\SubscriptionPlanLimitTrait; use Phalcon\Mvc\Micro\MiddlewareInterface; /** diff --git a/src/Models/Apps.php b/src/Models/Apps.php index a80d7496..8f054f6b 100644 --- a/src/Models/Apps.php +++ b/src/Models/Apps.php @@ -7,7 +7,7 @@ use Baka\Contracts\EventsManager\EventManagerAwareTrait; use Baka\Database\Apps as BakaApps; use Canvas\Cli\Jobs\Apps as JobsApps; -use Canvas\Traits\UsersAssociatedTrait; +use Canvas\Contracts\UsersAssociatedTrait; use Phalcon\Security\Random; class Apps extends BakaApps diff --git a/src/Models/Companies.php b/src/Models/Companies.php index d2eae5d0..d3a898d3 100644 --- a/src/Models/Companies.php +++ b/src/Models/Companies.php @@ -8,8 +8,8 @@ use Baka\Contracts\Database\HashTableTrait; use Baka\Contracts\EventsManager\EventManagerAwareTrait; use Baka\Http\Exception\InternalServerErrorException; -use Canvas\Traits\FileSystemModelTrait; -use Canvas\Traits\UsersAssociatedTrait; +use Canvas\Contracts\FileSystemModelTrait; +use Canvas\Contracts\UsersAssociatedTrait; use Carbon\Carbon; use Exception; use Phalcon\Di; diff --git a/src/Models/Users.php b/src/Models/Users.php index 704ba08d..2bd165ea 100644 --- a/src/Models/Users.php +++ b/src/Models/Users.php @@ -13,9 +13,9 @@ use Baka\Hashing\Password; use Baka\Validations\PasswordValidation; use Canvas\Auth\App as AppAuth; -use Canvas\Traits\FileSystemModelTrait; -use Canvas\Traits\PermissionsTrait; -use Canvas\Traits\SubscriptionPlanLimitTrait; +use Canvas\Contracts\FileSystemModelTrait; +use Canvas\Contracts\PermissionsTrait; +use Canvas\Contracts\SubscriptionPlanLimitTrait; use Carbon\Carbon; use Exception; use Phalcon\Di; diff --git a/src/Models/UsersInvite.php b/src/Models/UsersInvite.php index a1412c90..4101d02f 100644 --- a/src/Models/UsersInvite.php +++ b/src/Models/UsersInvite.php @@ -4,7 +4,7 @@ namespace Canvas\Models; use Baka\Database\Exception\ModelNotFoundException; -use Canvas\Traits\SubscriptionPlanLimitTrait; +use Canvas\Contracts\SubscriptionPlanLimitTrait; use Phalcon\Di; class UsersInvite extends AbstractModel diff --git a/tests/integration/library/Traits/SubscriptionLimitCest.php b/tests/integration/library/Traits/SubscriptionLimitCest.php index 2012609e..7f5abdd9 100644 --- a/tests/integration/library/Traits/SubscriptionLimitCest.php +++ b/tests/integration/library/Traits/SubscriptionLimitCest.php @@ -4,7 +4,7 @@ use Gewaer\Models\Apps; use IntegrationTester; -use Canvas\Traits\SubscriptionPlanLimitTrait; +use Canvas\Contracts\SubscriptionPlanLimitTrait; use Gewaer\Models\Users; use Helper\Integration; @@ -20,7 +20,6 @@ class SubscriptionLimitCest */ public function getModelKey(IntegrationTester $I) { - $classKey = $this->getSubscriptionPlanLimitModelKey(); $I->assertTrue($classKey == 'subscriptionlimitcest_total');