public function newAction() { $user = new User(['name' => Request::$post->get('name'), 'username' => Request::$post->get('username'), 'password' => Request::$post->get('password'), 'email' => Request::$post->get('email')]); if ($user->save()) { return $this->jsonResponse(['id' => $user->id, 'username' => $user->username]); } else { return $this->jsonResponse(['errors' => $user->errors()], 400); } }
public function newAction() { $user = User::find('username', Request::$post->get('username')); if ($user && $user->authenticate(Request::$post->get('password'))) { return $this->respondTo(function ($format) use($user) { if (Request::isXhr()) { return $this->jsonResponse(['id' => $user->id, 'username' => $user->username])->addCookie('dreamer', $user->session_hash, time() + 7 * 24 * 60 * 60, '/'); } }); } else { return $this->respondTo(function ($format) { if (Request::isXhr()) { return $this->jsonResponse(['error' => 'Invalid username or password'], 400); } }); } }
protected function getCurrentUser() { if (isset($_COOKIE['dreamer'])) { $this->currentUser = User::find('session_hash', $_COOKIE['dreamer']); } }