Skip to content

Commit

Permalink
Move traits from Traits folder to Contracts folder
Browse files Browse the repository at this point in the history
  • Loading branch information
rwhite27 committed Nov 20, 2020
1 parent fc91259 commit daac863
Show file tree
Hide file tree
Showing 30 changed files with 51 additions and 104 deletions.
Binary file added .DS_Store
Binary file not shown.
Binary file added src/.DS_Store
Binary file not shown.
34 changes: 3 additions & 31 deletions src/Api/Controllers/AuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
*
Expand Down
2 changes: 1 addition & 1 deletion src/Api/Controllers/FilesystemController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Canvas\Api\Controllers;

use Canvas\Models\FileSystem;
use Canvas\Traits\FileManagementTrait;
use Canvas\Contracts\FileManagementTrait;

class FilesystemController extends BaseController
{
Expand Down
2 changes: 1 addition & 1 deletion src/Api/Controllers/FilesystemEntitiesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Canvas\Api\Controllers;

use Canvas\Models\FileSystemEntities;
use Canvas\Traits\FileManagementTrait;
use Canvas\Contracts\FileManagementTrait;

/**
* Class BaseController.
Expand Down
2 changes: 1 addition & 1 deletion src/Api/Controllers/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
2 changes: 1 addition & 1 deletion src/Api/Controllers/UsersInviteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 0 additions & 10 deletions src/Auth/Models/Companies.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
46 changes: 16 additions & 30 deletions src/Traits/AuthTrait.php → src/Contracts/AuthTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Canvas\Traits;
namespace Canvas\Contracts;

use Canvas\Models\Sessions;
use Canvas\Auth\Auth;
Expand Down Expand Up @@ -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'));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Canvas\Traits;
namespace Canvas\Contracts;

use Phalcon\Di;
use Phalcon\Events\ManagerInterface as EventsManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Canvas\Traits;
namespace Canvas\Contracts;

use Baka\Http\Exception\UnprocessableEntityException;
use Canvas\Filesystem\Helper;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Canvas\Traits;
namespace Canvas\Contracts;

use Canvas\Dto\Files;
use Canvas\Mapper\FileMapper;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Canvas\Traits;
namespace Canvas\Contracts;

use League\Fractal\Manager;
use League\Fractal\Serializer\JsonApiSerializer;
Expand All @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Canvas\Traits;
namespace Canvas\Contracts;

use Canvas\Models\SystemModules;
use Canvas\Models\Notifications;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Canvas\Traits;
namespace Canvas\Contracts;

use Baka\Http\Exception\InternalServerErrorException;
use Baka\Http\Exception\UnauthorizedException;
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

declare(strict_types=1);

namespace Canvas\Traits;

namespace Canvas\Contracts;

/**
* Trait TokenTrait.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Canvas\Traits;
namespace Canvas\Contracts;

use Canvas\Http\Response;
use Phalcon\Mvc\Micro;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Canvas\Traits;
namespace Canvas\Contracts;

use Canvas\Auth\Auth;
use Baka\Http\Exception\UnprocessableEntityException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Canvas\Traits;
namespace Canvas\Contracts;

use function Baka\getShortClassName;
use Canvas\Exception\SubscriptionPlanLimitException;
Expand Down
2 changes: 1 addition & 1 deletion src/Traits/TokenTrait.php → src/Contracts/TokenTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Canvas\Traits;
namespace Canvas\Contracts;

use Lcobucci\JWT\Parser;
use Lcobucci\JWT\Token;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Canvas\Traits;
namespace Canvas\Contracts;

use Canvas\Models\Companies;
use Canvas\Models\Roles;
Expand Down
2 changes: 1 addition & 1 deletion src/Traits/UsersTrait.php → src/Contracts/UsersTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Canvas\Traits;
namespace Canvas\Contracts;

use Canvas\Auth\Models\Companies;
use Canvas\Auth\Models\Users;
Expand Down
2 changes: 1 addition & 1 deletion src/Middleware/NotFoundMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/Middleware/ThrottleMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/Middleware/TokenBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Models/Apps.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/Models/Companies.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions src/Models/Users.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/Models/UsersInvite.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions tests/integration/library/Traits/SubscriptionLimitCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -20,7 +20,6 @@ class SubscriptionLimitCest
*/
public function getModelKey(IntegrationTester $I)
{

$classKey = $this->getSubscriptionPlanLimitModelKey();

$I->assertTrue($classKey == 'subscriptionlimitcest_total');
Expand Down

0 comments on commit daac863

Please sign in to comment.