echoRespnse(401, $response); $app->stop(); } } else { $response['error'] = true; $response['msg'] = 'User not found.'; echoRespnse(401, $response); $app->stop(); } }); /** * Register a new user */ $app->post('/register', function () use($app) { // check for required params verify_required_params(array('name', 'email', 'email_confirm', 'password', 'password_confirm')); // reading post params $user = array('name' => $app->request()->post('name'), 'email' => $app->request()->post('email'), 'email_confirm' => $app->request()->post('email_confirm'), 'password' => $app->request()->post('password'), 'password_confirm' => $app->request()->post('password_confirm')); // prepare the answer $response = array('request' => 'register'); // Sanitize data $user['name'] = filter_var($user['name'], FILTER_SANITIZE_STRING); $user['email'] = filter_var($user['email'], FILTER_SANITIZE_EMAIL); $user['email_confirm'] = filter_var($user['email_confirm'], FILTER_SANITIZE_EMAIL); $user['password'] = filter_var($user['password'], FILTER_SANITIZE_STRING); $user['password_confirm'] = filter_var($user['password_confirm'], FILTER_SANITIZE_STRING); //Make sure the 2 emails are the same if ($user['email'] !== $user['email_confirm']) { $response['error'] = true; $response['msg'] = 'Email verification failed.'; echoRespnse(401, $response);
$user['name'] = filter_var($user['name'], FILTER_SANITIZE_STRING); $user['email'] = filter_var($user['email'], FILTER_SANITIZE_EMAIL); $db = new DbHandler(); $userUID = $app->getCookie('lq_user_id'); // Try to update the user details if ($db->updateUserProfile($userUID, $user['name'], $user['email'])) { $response['error'] = false; } else { $response['error'] = true; $response['msg'] = 'Impossible to update the user profile.'; echoRespnse(401, $response); $app->stop(); } // If the user sent a password, reset that as well if (isset($user['old_password']) || isset($user['password']) || isset($user['password_confirm'])) { verify_required_params(array('old_password', 'password', 'password_confirm')); $user['old_password'] = filter_var($user['old_password'], FILTER_SANITIZE_STRING); $user['password'] = filter_var($user['password'], FILTER_SANITIZE_STRING); $user['password_confirm'] = filter_var($user['password_confirm'], FILTER_SANITIZE_STRING); //Make sure the 2 passwords are the same if ($user['password'] !== $user['password_confirm']) { $response['error'] = true; $response['msg'] = 'Password verification failed.'; echoRespnse(401, $response); $app->stop(); } if ($db->updateUserPassword($userUID, $user['email'], $user['old_password'], $user['password'], $user['password_confirm'])) { $response['error'] = false; $response['msg'] = 'User information saved.'; echoRespnse(200, $response); $app->stop();