This commit is contained in:
David Bomba 2015-11-03 19:09:52 +11:00
parent 9b54113b9b
commit 6f320aa624
3 changed files with 5 additions and 9 deletions

View File

@ -32,7 +32,6 @@ class AccountApiController extends Controller
if (Auth::attempt(['email' => $request->email, 'password' => $request->password])) { if (Auth::attempt(['email' => $request->email, 'password' => $request->password])) {
return $this->processLogin($request); return $this->processLogin($request);
//return $this->accountRepo->createToken($request->token_name);
} else { } else {
return 'Invalid credentials'; return 'Invalid credentials';
} }
@ -55,13 +54,9 @@ class AccountApiController extends Controller
private function processLogin(Request $request) private function processLogin(Request $request)
{ {
\Log::info('authed user = '.Auth::user()->email);
//Create a new token only if one does not already exist //Create a new token only if one does not already exist
if(!AccountToken::where('user_id', '=', Auth::user()->id)->firstOrFail()) $this->accountRepo->createToken('ios_api_token');
{
$account_token = $this->accountRepo->createToken($request->token_name);
}
$manager = new Manager(); $manager = new Manager();
$manager->setSerializer(new ArraySerializer()); $manager->setSerializer(new ArraySerializer());

View File

@ -462,7 +462,7 @@ class AccountRepository
$name = trim($name) ?: 'TOKEN'; $name = trim($name) ?: 'TOKEN';
if ($token = AccountToken::scope()->whereName($name)->first()) { if ($token = AccountToken::scope()->whereName($name)->first()) {
return $token->token; return $token;
} }
$token = AccountToken::createNew(); $token = AccountToken::createNew();

View File

@ -1,6 +1,7 @@
<?php namespace App\Ninja\Transformers; <?php namespace App\Ninja\Transformers;
use App\Models\Account; use App\Models\Account;
use App\Models\AccountToken;
use League\Fractal; use League\Fractal;
use League\Fractal\TransformerAbstract; use League\Fractal\TransformerAbstract;
@ -13,9 +14,9 @@ class AccountTransformer extends TransformerAbstract
public function includeAccountTokens($account) public function includeAccountTokens($account)
{ {
$account_tokens = $account->tokens; $account_token = AccountToken::whereAccountId($account->id)->whereName('ios_api_token')->first();
return $this->collection($account_tokens, new AccountTokenTransformer); return $this->collection($account_token, new AccountTokenTransformer);
} }
public function includeUsers($account) public function includeUsers($account)