if (empty($_REQUEST['action'])) { die(json_encode(array('error' => 'wrong action'))); } // array of required arguments for each action (when needed) $requiredArgs = array('get_periods_list' => array('page', 'rows')); if (array_key_exists($_REQUEST['action'], $requiredArgs)) { foreach ($requiredArgs[$_REQUEST['action']] as $arg) { if (!isset($_REQUEST[$arg])) { echo json_encode(array('error' => 'args')); return; } } } $periods = new Periods($user->getId()); $campaign = new Campaign($user->getId(), $periods); $campaign->setUserEmail($user->getUsername()); switch ($_REQUEST['action']) { case 'get_periods_list': $page = $_REQUEST['page']; // get the requested page $limit = $_REQUEST['rows']; // get how many rows we want to have into the grid $sidx = $_REQUEST['sidx']; // get index row - i.e. user click to sort $sord = $_REQUEST['sord']; // get the direction $displayAllMy = $_REQUEST['displayAllMy']; if (!$sidx) { $sidx = 1; } // connect to the database
if (empty($_REQUEST['action'])) { die(json_encode(array('error' => 'wrong action'))); } // array of required arguments for each action (when needed) $requiredArgs = array('get_userlist' => array('period_id'), 'user_info' => array('user_id', 'period_id'), 'user_love' => array('period_id'), 'mark_favorite' => array('love_id', 'status'), 'favorite_why' => array('love_id', 'why'), 'update_love' => array('love_id', 'love_status', 'period_id'), 'update_wizard' => array('user_review_id', 'wizard_step'), 'peer_review_status' => array('user_review_id', 'user_review_peer_status'), 'get_periods_list' => array('page', 'rows'), 'review_completed' => array('user_review_id'), 'review_started' => array('user_review_id'), 'reset_user_review' => array('user_id')); if (array_key_exists($_REQUEST['action'], $requiredArgs)) { foreach ($requiredArgs[$_REQUEST['action']] as $arg) { if (!isset($_REQUEST[$arg])) { echo json_encode(array('error' => 'args')); return; } } } $periods = new Periods($user->getId()); $review = new Review($user->getId(), $periods); $review->setUserEmail($user->getUsername()); switch ($_REQUEST['action']) { // gets info about requested period with period stats (done/not done) case 'get_period': $totalCount = $periods->getPeriodCount(); $position = !empty($_REQUEST['position']) ? intval($_REQUEST['position']) : $periods->getCurrentPeriodCount(); $period_info = $periods->getPeriodByPosition($position); if ($period_info !== null) { $period_info = $review->getPeriodById($period_info['id']); } $period_stats = $review->getPeriodStats($period_info['id']); $time_percentage = 0; if ($period_info['status'] == 0) { $time_percentage = getTimePercentage($period_info['start_date'], $period_info['end_date']); } echo json_encode(array('info' => $period_info, 'stats' => $period_stats, 'count' => $totalCount, 'position' => $position, 'time_percentage' => $time_percentage));
public function notifyOfLogin($calling_app, $user_id, $session_id) { global $regApps; $user = new LoveUser(); $user->loadById($user_id); // push notification of logged in user to each of registered apps // except of calling app foreach ($regApps as $app => $info) { if (is_array($info) && !empty($info['endpoint']) && !empty($info['key']) && $calling_app != $app && !empty($info['listenLogin'])) { // setting request variables $vars = array('action' => 'login', 'user_id' => $user_id, 'session_id' => $session_id, 'username' => $user->getUsername(), 'nickname' => $user->getNickname(), 'admin' => $user->getAdmin(), 'api_key' => $info['key']); ob_start(); // send the request CURLHandler::Post($info['endpoint'], $vars); $result = ob_get_contents(); ob_end_clean(); } } return true; }
/** * Create controller function * * This function creates a new user. * * The function validates the passed data * and return error and description of error * if the data is invalid. When the data is valid * a new user is created. * * @return json|xml true on success false on error */ public function create() { if ($this->isRequestValid("create")) { // Create a new user object, and fill it with the given data. $user = new LoveUser(); $username = isset($_REQUEST['username']) ? trim($_REQUEST['username']) : ''; $password = isset($_REQUEST['password']) ? $_REQUEST['password'] : ''; $nickname = isset($_REQUEST['nickname']) ? trim($_REQUEST['nickname']) : ''; $token = isset($_REQUEST['confirm_string']) ? trim($_REQUEST['confirm_string']) : uniqid(); // TODO: Disable nickname collision checks, and enable soft failing. if (!$user->loadByUsername($username)) { if (!$user->loadByNickname($nickname)) { $data = array("Username" => $username, "Password" => $password, "Nickname" => $nickname, "Active" => 1, "Confirmed" => 1, "Removed" => 0, "Admin" => 0, "Token" => $token, "DateAdded" => 0, "DateModified" => 0); $user->loadData($data); $id = $user->save(); // Push user created to the applications if (!$this->getResponse()->pushUser($this->AppAuth->getAppName(), $id, 'pushCreateUser')) { $this->setError("User could not be pushed to the registred applications."); } $this->response->addParams(array("id" => $user->getId(), "username" => $user->getUsername(), "nickname" => $user->getNickname(), "confirm_string" => $token, "token" => $_REQUEST["token"])); } else { $this->setError("Nickname already registered!"); } } else { $this->setError("Username already registered!"); } } $this->completeResponse(); }
public function testSetUserData() { $failureAffects = "Login will no longer allow admins to update users data"; // admin ID $aid = 6; // user ID $uid = 9; $dbConfig = array(); $dbConfig['adapter'] = 'mysqli'; $dbConfig['host'] = 'mysql.dev.sendlove.us'; $dbConfig['dbname'] = 'LM_logintest'; $dbConfig['username'] = '******'; $dbConfig['password'] = '******'; $u = new LoveUser($dbConfig); $u->loadById($uid); // current user info $username = $u->getUsername(); $nickname = $u->getNickname(); $password = $u->getPassword(); $confirmed = $u->getConfirmed(); $active = $u->getActive(); $token = $u->getToken(); $admin = $u->getAdmin(); $removed = $u->getRemoved(); // updated user info $user_data = array("userid" => $uid, "username" => $username . $uid, "nickname" => $nickname . $uid, "password" => $password . $uid, "confirmed" => 0, "active" => 0, "admin" => 1, "removed" => 1, "token" => uniqid()); // update user $this->assertEquals(true, $this->aHandler->setuserdata($this->controller, $user_data, $aid), $failureAffects); // verify that no error is returned $this->assertEquals(false, $this->controller->getErrorFlag(), $failureAffects); // restore previous user info $user_data["username"] = $username; $user_data["nickname"] = $nickname; $user_data["password"] = $password; $user_data["confirmed"] = 1; $user_data["active"] = 1; $user_data["admin"] = 0; $user_data["removed"] = 0; $user_data["token"] = $token; $this->assertEquals(true, $this->aHandler->setuserdata($this->controller, $user_data, $aid), $failureAffects); }