/** * Creating new user * @param String $name User full name * @param String $email User login email id * @param String $password User login password */ public function createUser(CustomParseUser $cpu) { $response = array(); // First check if user already existed in db if (!$this->isUserExists($cpu->getUserName(), $cpu->getEmail())) { // Generating API key $api_key = $this->generateApiKey($cpu->getEmail()); $user = new ParseUser(); $user->set("username", $cpu->getUsername()); $user->set("password", $cpu->getPassword()); $user->set("email", $cpu->getEmail()); $user->set("firstName", $cpu->getFirstName()); $user->set("lastName", $cpu->getLastName()); $user->set("birthday", $cpu->getBirthday()); $user->set("apiKey", $api_key); try { $user->signUp(); // Hooray! Let them use the app now. return 'USER_CREATED_SUCCESSFULLY'; } catch (Parse\ParseException $ex) { // Show the error message somewhere and let the user try again. echo "Error: " . $ex->getCode() . " " . $ex->getMessage(); return 'USER_CREATE_FAILED'; } } else { // User with same email already existed in the db return 'USER_ALREADY_EXISTED'; } return $response; }
* params - name, email, password */ $app->post('/user/register', function () use($app) { // check for required params verifyRequiredParams(array('firstName', 'lastName', 'username', 'email', 'password', 'birthday')); $response = array(); $newUser = new CustomParseUser(); // reading post params $newUser->setFirstName($app->request->post('firstName')); $newUser->setLastName($app->request->post('lastName')); $newUser->setUsername($app->request->post('username')); $newUser->setEmail($app->request->post('email')); $newUser->setPassword($app->request->post('password')); $newUser->setBirthday($app->request->post('birthday')); // validating email address validateEmail($newUser->getEmail()); // validating date validateDate($newUser->getBirthday()); $newUser->setBirthday(DateTime::createFromFormat('m/d/Y', $newUser->getBirthday())); $db = new DbHandlerParse(); $res = $db->createUser($newUser); if ($res == 'USER_CREATED_SUCCESSFULLY') { $response["result"] = 'success'; $response["message"] = "You are successfully registered"; echoRespnse(200, $response); } else { if ($res == 'USER_CREATE_FAILED') { $response["result"] = 'error'; $response["message"] = "Oops! An error occurred while registereing"; echoRespnse(200, $response); } else {