From 641343e38df2efbd2a23f425f8a49b9795b21ded Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Sun, 26 Apr 2015 17:58:30 +0200 Subject: user routes --- src/controllers/UserController.php | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) (limited to 'src/controllers') 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 @@ 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; } } -- cgit v1.2.3