Pony.fm/app/controllers/Api/Web/AuthController.php

30 lines
780 B
PHP
Raw Normal View History

2013-07-25 23:33:04 +02:00
<?php
namespace Api\Web;
use Commands\RegisterUserCommand;
class AuthController extends \Controller {
public function postLogin() {
if (!\Auth::attempt(array('email' => \Input::get('email'), 'password' => \Input::get('password')), \Input::get('remember')))
return \Response::json(['messages' => ['username' => 'Invalid username or password']], 400);
return \Response::json(['user' => \Auth::user()]);
}
public function postLogout() {
\Auth::logout();
}
public function postRegister() {
$command = new RegisterUserCommand();
if (!$command->authorize())
return \Response::json([], 403);
$errors = $command->validate();
if ($errors->fails())
return \Response::json([], 400);
return \Response::json($command->execute());
}
}