public function registerAction() { $request = $_POST; //email, firstName, lastName, email, password, password2 $token = isset($request['TOKEN']) ? trim($request['TOKEN']) : null; if (!$token) { return ['STATUS_CODE' => STATUS_CODE_BAD_REQUEST, 'DATA' => buckys_api_get_error_result('Api token should not be blank')]; } if ($token != THENEWBOSTON_PUBLIC_API_KEY) { return ['STATUS_CODE' => STATUS_CODE_UNAUTHORIZED, 'DATA' => buckys_api_get_error_result('Api token is not valid.')]; } //Validate Input Data $newID = BuckysUser::createNewAccount($request); if (!$newID) { //Getting Error Message $error = buckys_get_pure_messages(); return ['STATUS_CODE' => STATUS_CODE_OK, 'DATA' => buckys_api_get_error_result($error)]; } else { return ['STATUS_CODE' => STATUS_CODE_OK, 'DATA' => ['STATUS' => 'SUCCESS', 'USERID' => $newID, 'MESSAGE' => MSG_NEW_ACCOUNT_CREATED]]; } }
public function unfriendAction() { $data = $_POST; $token = isset($data['TOKEN']) ? trim($data['TOKEN']) : null; $friendID = isset($data['friendID']) ? $data['friendID'] : null; if (!$token) { return ['STATUS_CODE' => STATUS_CODE_BAD_REQUEST, 'DATA' => buckys_api_get_error_result('Api token should not be blank')]; } if (!($userID = BuckysUsersToken::checkTokenValidity($token, "api"))) { return ['STATUS_CODE' => STATUS_CODE_UNAUTHORIZED, 'DATA' => buckys_api_get_error_result('Api token is not valid.')]; } if (!isset($friendID) || !BuckysUser::checkUserID($friendID)) { return ['STATUS_CODE' => STATUS_CODE_OK, 'DATA' => buckys_api_get_error_result(MSG_INVALID_REQUEST)]; } if (BuckysFriend::unfriend($userID, $friendID)) { return ['STATUS_CODE' => STATUS_CODE_OK, 'DATA' => ['STATUS' => "SUCCESS", "MESSAGE" => MSG_FRIEND_REQUEST_REMOVED]]; } else { ['STATUS_CODE' => STATUS_CODE_OK, 'DATA' => buckys_api_get_error_result(buckys_get_pure_messages())]; } }
public function likePostAction() { $data = $_POST; $token = isset($data['TOKEN']) ? trim($data['TOKEN']) : null; $postID = isset($data['postID']) ? $data['postID'] : null; $actionType = isset($data['actionType']) ? $data['actionType'] : null; if (!$token) { return ['STATUS_CODE' => STATUS_CODE_BAD_REQUEST, 'DATA' => buckys_api_get_error_result('Api token should not be blank')]; } if (!($userID = BuckysUsersToken::checkTokenValidity($token, "api"))) { return ['STATUS_CODE' => STATUS_CODE_UNAUTHORIZED, 'DATA' => buckys_api_get_error_result('Api token is not valid.')]; } if (!$postID || !$actionType) { return ['STATUS_CODE' => STATUS_CODE_BAD_REQUEST, 'DATA' => buckys_api_get_error_result(MSG_INVALID_REQUEST)]; } $post = BuckysPost::getPostById($postID); if (!$post || $post['post_status'] != 1) { return ['STATUS_CODE' => STATUS_CODE_OK, 'DATA' => buckys_api_get_error_result(MSG_INVALID_REQUEST)]; exit; } $r = BuckysPost::likePost($userID, $postID, $actionType, false); $message = buckys_get_pure_messages(); if (!$r) { return ['STATUS_CODE' => STATUS_CODE_OK, 'DATA' => buckys_api_get_error_result($message)]; exit; } else { $likes = BuckysPost::getPostLikesCount($postID); return ['STATUS_CODE' => STATUS_CODE_OK, 'DATA' => ['STATUS' => 'SUCCESS', 'MESSAGE' => $message, 'LIKES' => $likes, 'isLiked' => $actionType == 'likePost' ? 'yes' : 'no']]; } }