Пример #1
0
/**
 * User Registration
 * url - /user/register
 * method - POST
 * 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 {