logIn($request['email'], $request['password']); if ($token !== false) { return Response::json(array( 'data' => $token, 'error' => false, ), 200); } return Response::json(array( 'data' => 'Could not log in: incorrect data', 'error' => true, ), 401); } return Response::json(array( 'data' => 'Could not log in: required information missing', 'error' => true, ), 400); } case 'create-account': { if (isset($request['email']) && isset($request['password'])) { $user = new User(); if (!$user->emailExists($request['email'])) { $token = $user->create($request['email'], $request['password']); if ($token !== false) { return Response::json(array( 'data' => $token, 'error' => false, ), 201); } return Response::json(array( 'data' => 'Could not create account: database error', 'error' => true, ), 500); } return Response::json(array( 'data' => 'Could not create account: duplicate email', 'error' => true, ), 403); } return Response::json(array( 'data' => 'Could not create account: required information missing', 'error' => true, ), 400); } case 'get-all-dictionary-names': { if ($token !== false) { $user = new User(); $all_dictionaries = $user->listAllDictionaryNames($token); if ($all_dictionaries !== false) { return Response::json(array( 'data' => $all_dictionaries, 'error' => false, ), 200); } return Response::json(array( 'data' => 'Could not get dictionaries: invalid token', 'error' => true, ), 400); } return Response::json(array( 'data' => 'Could not get dictionaries: no token provided', 'error' => true, ), 403); } case 'create-new-dictionary': { if ($token !== false) { $user = new User(); $new_token = $user->createNewDictionary($token); if ($new_token !== false) { return Response::json(array( 'data' => $new_token, 'error' => false, ), 200); } return Response::json(array( 'data' => 'Could not create dictionary: incorrect data', 'error' => true, ), 401); } return Response::json(array( 'data' => 'Could not create dictionary: no token provided', 'error' => true, ), 400); } case 'change-dictionary': { if ($token !== false && isset($request['dictionary'])) { $user = new User(); $new_token = $user->changeCurrentDictionary($token, $request['dictionary']); if ($new_token !== false) { return Response::json(array( 'data' => $new_token, 'error' => false, ), 200); } return Response::json(array( 'data' => 'Could not create dictionary: incorrect data', 'error' => true, ), 401); } return Response::json(array( 'data' => 'Could not create dictionary: no token provided', 'error' => true, ), 400); } case 'get-current-dictionary': { if ($token !== false) { $user = new User(); $dictionary_data = $user->getCurrentDictionary($token); if ($dictionary_data !== false) { return Response::json(array( 'data' => $dictionary_data, 'error' => false, ), 200); } return Response::json(array( 'data' => 'Could not get dictionary: invalid token', 'error' => true, ), 401); } return Response::json(array( 'data' => 'Could not get dictionary: no token provided', 'error' => true, ), 400); } default: { return Response::html('Hi!'); } }