diff options
Diffstat (limited to 'src/controllers/UserController.php')
-rw-r--r-- | src/controllers/UserController.php | 34 |
1 files changed, 22 insertions, 12 deletions
diff --git a/src/controllers/UserController.php b/src/controllers/UserController.php index 33e945d..02400e9 100644 --- a/src/controllers/UserController.php +++ b/src/controllers/UserController.php @@ -1,6 +1,7 @@ <?php namespace CamilStaps\BotleaguesApi; +use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Hash; use Illuminate\Support\Facades\Input; use Illuminate\Support\Facades\Redirect; @@ -21,21 +22,30 @@ class UserController extends BaseController { return $this->user->findOrFail($id); } - public function edit($id) { - return $this->response->noContent(); + public function update($id) { + if ($id != Auth::user()->id) { + throw new \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException(); + } + + $s = $this->user->find($id); + + if (!empty(Input::get('password'))) + $s->password = Hash::make(Input::get('password')); + + if ($s->save()) { + return $this->show($id); + } else { + throw new Dingo\Api\Exception\UpdateResourceFailedException; + } } public function store() { - try { - $this->user->email = Input::get('email'); - $this->user->password = Hash::make(Input::get('password')); - - if ($this->user->save()) { - return $this->response->created(); - } else { - throw new Dingo\Api\Exception\StoreResourceFailedException; - } - } catch (Exception $e) { + $this->user->email = Input::get('email'); + $this->user->password = Hash::make(Input::get('password')); + + if ($this->user->save()) { + return $this->response->created(); + } else { throw new Dingo\Api\Exception\StoreResourceFailedException; } } |