Skip to content

Commit

Permalink
Moves the dispatch mail logic from repository to controller
Browse files Browse the repository at this point in the history
To follow the style to keep more logic inside the controllers, the dispatching
of the email job is moved from the repository.
  • Loading branch information
artstorm committed Jul 23, 2015
1 parent fb9ab8b commit 5c03f68
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 22 deletions.
16 changes: 14 additions & 2 deletions api/app/Http/Controllers/UserController.php
Expand Up @@ -6,14 +6,18 @@
use Illuminate\Http\Request;
use App\Models\UserCredential;
use Illuminate\Support\MessageBag;
use App\Jobs\SendPasswordResetEmail;
use App\Exceptions\ValidationException;
use Laravel\Lumen\Routing\DispatchesJobs;
use App\Extensions\Lock\Manager as Lock;
use App\Repositories\UserRepository as Repository;
use App\Http\Validators\UserValidator as Validator;
use Spira\Responder\Contract\ApiResponderInterface as Responder;

class UserController extends ApiController
{
use DispatchesJobs;

/**
* Permission Lock Manager.
*
Expand Down Expand Up @@ -105,12 +109,20 @@ public function putOne($id, Request $request)
* Reset user password.
*
* @param string $id
*
* @return Response
*/
public function resetPassword($id)
{
$this->repository->resetPassword($id);
$this->validateId($id);

try {
$user = $this->repository->find($id);
} catch (ModelNotFoundException $e) {
$this->responder->errorNotFound();
}

$token = $this->repository->makeLoginToken($id);
$this->dispatch(new SendPasswordResetEmail($user, $token));

return response(null, 202);
}
Expand Down
20 changes: 0 additions & 20 deletions api/app/Repositories/UserRepository.php
@@ -1,15 +1,11 @@
<?php namespace App\Repositories;

use App\Models\User;
use App\Jobs\SendPasswordResetEmail;
use Laravel\Lumen\Routing\DispatchesJobs;
use Illuminate\Contracts\Cache\Repository as Cache;
use Illuminate\Database\ConnectionResolverInterface as Connection;

class UserRepository extends BaseRepository
{
use DispatchesJobs;

/**
* Login token time to live in minutes.
*
Expand Down Expand Up @@ -80,20 +76,4 @@ public function makeLoginToken($id)

return $token;
}

/**
* Reset user password.
*
* @param string $id
* @return void
*/
public function resetPassword($id)
{
// Note:
// This might probably be moved to the controller when the architecture
// update is applied.
$user = $this->find($id);
$token = $this->makeLoginToken($id);
$this->dispatch(new SendPasswordResetEmail($user, $token));
}
}

0 comments on commit 5c03f68

Please sign in to comment.