Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
webbingbrasil/users-module / Commands / Handlers / BeginResetProcessCommandHandler.php
Size: Mime:
<?php namespace Modules\Users\Commands\Handlers;

use Modules\Core\Contracts\Authentication;
use Modules\Users\Events\UserHasBegunResetProcess;
use Modules\Users\Exceptions\UserNotFoundException;
use Modules\Users\Repositories\UserRepository;

class BeginResetProcessCommandHandler
{
    /**
     * @var UserRepository
     */
    private $user;
    /**
     * @var Authentication
     */
    private $auth;

    public function __construct(UserRepository $user, Authentication $auth)
    {
        $this->user = $user;
        $this->auth = $auth;
    }

    /**
     * Handle the command
     *
     * @param $command
     * @throws UserNotFoundException
     * @return mixed
     */
    public function handle($command)
    {
        $user = $this->findUser((array)$command);

        $code = $this->auth->createReminderCode($user);

        event(new UserHasBegunResetProcess($user, $code));
    }

    private function findUser($credentials)
    {
        $user = $this->user->findByCredentials((array)$credentials);
        if ($user) {
            return $user;
        }

        throw new UserNotFoundException();
    }
}