function get_user_profile($app) { $app->set('user', User::get_by_username($app->request('username'))); $app->set('is_current_user', $app->request('username') == User::current_user() ? true : false); $app->set('posts', Post::get_posts_by_user($app->request('username'), $app->request('skip') ? $app->request('skip') : 0)); $app->set('post_count', Post::get_post_count_by_user($app->request('username'))); }
public function testConfirmationProcess() { $this->confirm->create(); $user = new User(); $user->uid = 76; User::$current_user = $user; $this->confirm->process(true); $this->assertEqual($user->checkFriendsWith(1), true); }
public function create() { $bones = new Bones(); $this->_id = $bones->couch->generateIDs(1)->body->uuids[0]; $this->date_created = date('r'); $this->user = User::current_user(); try { $bones->couch->put($this->_id, $this->to_json()); } catch (SagCouchException $e) { $bones->error500($e); } }
function login($username, $password) { $session = mySession::getInstance(); if ($session->isLoggedIn()) { $user = User::current_user(); unset($user->password); // return 0; return $user; exit; } $username = val_string($username); $password = val_string($password); // $page = $_REQUEST['page']; $password = sha1($password); // Check if user has been found in database $found_user = User::authenticate($username, $password); if ($found_user) { // log them in $session->login($found_user); // return User::current_user(); // grab the account status $profile_status = $found_user->status; if ($profile_status != 'current') { return false; // their account isn't set up so log them out send them to the login page. $session->logout(); return false; exit; } else { unset($found_user->password); // return 1; return $found_user; exit; } } else { // If User Not Found return false; } exit; }
<?php include_once '../frame.php'; $user = User::current_user(); if (!$user) { alert("请您先登录!"); redirect('/login/'); exit; } $id = $user->id; $member = new table_class('eachbb_member.member'); $member->find($id); $db = get_db(); $avatars = $db->query("SELECT id,photo,status FROM eachbb_member.member_avatar where u_id=" . $user->id . ' order by create_at desc limit 3'); $avatar_count = $db->record_count; $name = $user->name; js_include_tag('baby_info'); ?> <div id="c_c" style="float:right"> <div id="cc_t" style="float:left"></div> <div id="cc_c" style="float:left"> <div id="cc_pg"> <div class=r_title id="r_log"><span><?php echo $member->true_name; ?> </span>的账户管理</div> <div id="r_log_hr"> <div>个人资料</div> </div> <div class="c_menu_pg_p" > </div> <form>
protected function update($user) { if ($user === null) { $user = User::current_user(); } $database = cbSQLConnect::connect('object'); if (isset($database)) { $fields = self::$db_fields; // $this->submitter = (int)$user->id; if (isset($user) && !isset($user->rights) || !($user->rights === 'super' || $user->rights === 'admin')) { $this->status = 'I'; $tempPerson = Person::getById($this->id); if ($tempPerson->status === 'A') { $message = "An old Individual has been updated and will require aproval to the changes:<br><br>"; $message .= "<a href='http://dev.familyhistorydatabase.org/#/individual?individual=" . $this->id . "&tab=default'>" . $this->displayName() . "</a><br><br>"; $message .= "by " . $user->username . " " . $user->email; $message .= "<br><br>Changes Include:<br>"; $message .= print_r(recursive_array_diff((array) $this, (array) $tempPerson), true); $subject = "Old Individual for approval"; sendOwnerUpdate($message, $subject); } } else { if (is_null($user)) { return false; } } foreach ($fields as $key) { $flag = $database->SQLUpdate("person", $key, $this->{$key}, "id", $this->id); if ($flag == "fail") { break; } } if ($flag == "fail") { return 'we failed on check2'; return false; } else { return $this->id; } } return 'this happened'; }
function handleIndividualAPI($args, $that) { $session = mySession::getInstance(); if ($that->method === 'GET') { if ($that->verb === '') { $id = intval(array_shift($args)); if ($id && is_numeric($id)) { $session = mySession::getInstance(); if ($id > -1) { $person = Person::getById($id); if ($person) { $person->appendNames(); $person->birth = Birth::getById($id); if ($person->birth) { $person->birth->birthPlace = Place::getById($person->birth->place); } $person->death = Death::getById($id); if ($person->death) { $person->death->deathPlace = Place::getById($person->death->place); } $person->burial = Burial::getById($id); if ($person->burial) { $person->burial->burialPlace = Place::getById($person->burial->place); } $person->parents = Parents::getParentsOf($id); $person->children = Parents::getChildrenOf($id); $person->spouse = Spouse::getById($id); $person->profilePicture = File::getById($person->profile_pic); return $person; } else { return false; } } else { return false; } } } else { if ($that->verb === 'submissions') { $user = User::current_user(); $submissions = Person::getSubmissions($user); return $submissions; } else { if ($that->verb === 'allSubmissions' && $session->isAdmin()) { $submissions = Person::getSubmissions(); return $submissions; } else { if ($that->verb === 'children') { if (count($args) > 2 || count($args) < 2) { return array(); } else { $id = intval(array_shift($args)); $spouseid = intval(array_shift($args)); if ($id && is_numeric($id) && $spouseid && is_numeric($spouseid)) { $children = Person::getChildrenByParents($id, $spouseid); $result = array(); if ($children && is_array($children) && count($children)) { foreach ($children as $child) { $person = Person::getById($child->child); $person->appendNames(); $person->profilePicture = File::getById($person->profile_pic); $result[] = $person; } } return $result; } else { return array(); } } } else { if ($that->verb === 'families') { if (!empty($args)) { $letter = array_shift($args); } else { $letter = 'a'; } $all = array_shift($args); $all = $all === "true" ? true : false; $names = array(); $families = Person::getLastNames($letter, $all); if ($families) { foreach ($families as $key) { $names[] = $key['lastName']; } } return $names; } else { if ($that->verb === 'family') { $id = intval(array_shift($args)); if ($id && is_numeric($id)) { $person = Person::getById($id); $person->appendNames(); $family = new stdClass(); $family->self = $person; $family->parents = array(); // $family->siblings = array(); $children = $person->getChildren(); $family->children = array(); foreach ($children as $child) { $temp = Person::getById($child->child); $temp->appendNames(); $family->children[] = $temp; } $spouses = $person->getSpouse(); $family->spouses = array(); foreach ($spouses as $spouse) { $temp = Person::getById($spouse->spouse); $temp->appendNames(); $family->spouses[] = $temp; } $siblings = array(); $tempsiblings = array(); $person->getParentsGen(4); $family->parents = $person->parents; // foreach ($parents as $key) { // $parent = Person::getById($key->parentId); // $parent->appendNames(); // $family->parents[] = $parent; // // $siblings[] = $parent->getChildren(); // } // foreach ($siblings as $sibling) { // foreach ($sibling as $key) { // $test = true; // foreach ($tempsiblings as $value) { // if ($key->child === $value->child) { // $test = false; // } // } // if ($test) { // $tempsiblings[] = $key; // } // } // } // foreach ($tempsiblings as $sibling) { // if ($sibling->child !== $person->id) { // $family->siblings[] = Person::getById($sibling->child); // } // } // foreach ($family->parents as $parent) { // $grandparents = $parent->getParents(); // foreach ($grandparents as $grandparent) { // $temp = Person::getById($grandparent->parentId); // $temp->child = $parent->id; // $temp->appendNames(); // $family->grandParents[] = $temp; // } // } // foreach ($family->grandParents as $parent) { // $grandparents = $parent->getParents(); // foreach ($grandparents as $grandparent) { // $temp = Person::getById($grandparent->parentId); // $temp->child = $parent->id; // $temp->appendNames(); // $family->greatGrandParents[] = $temp; // } // } // foreach ($family->greatGrandParents as $parent) { // $grandparents = $parent->getParents(); // foreach ($grandparents as $grandparent) { // $temp = Person::getById($grandparent->parentId); // $temp->child = $parent->id; // $temp->appendNames(); // $family->greatGreatGrandParents[] = $temp; // } // } return $family; } else { return new stdClass(); } } else { if ($that->verb === 'familyNames') { if (!empty($args)) { $lastName = array_shift($args); } else { $lastName = 'Law'; } $all = array_shift($args); $all = $all === "true" ? true : false; $names = array(); $user = User::current_user(); $familyNames = Person::getFirstNames($lastName, $all, $user); if ($familyNames) { foreach ($familyNames as $key) { $key = recast('Person', arrayToObject($key)); $key->appendNames(); $names[] = $key; } } return $names; } else { if ($that->verb === 'pictures') { $id = intval(array_shift($args)); if ($id && is_numeric($id)) { $session = mySession::getInstance(); if ($id > -1) { $person = Person::getById($id); if ($person) { return File::getByInd($person->id, 'image'); } } } else { return false; } } else { if ($that->verb === 'documents') { $id = intval(array_shift($args)); if ($id && is_numeric($id)) { $session = mySession::getInstance(); if ($id > -1) { $person = Person::getById($id); if ($person) { return File::getByInd($person->id, 'document'); } } } else { return false; } } } } } } } } } } // } else { // return false; // } } else { if ($that->method === 'DELETE' && $session->isLoggedIn() && $session->isAdmin()) { // } else if ($that->method === 'DELETE'){ $id = intval($args[0]); if (is_numeric($id)) { $person = Person::getById($id); if ($person) { $birth = Birth::getById($id); if ($birth) { $birth = recast('Birth', $birth); $birth->delete(); //delete } $death = Death::getById($id); if ($death) { $death = recast('Death', $death); $death->delete(); //delete } $burial = Burial::getById($id); if ($burial) { $burial = recast('Burial', $burial); $burial->delete(); //delete } $parents = Parents::getParentsOf($id); if ($parents) { foreach ($parents as $parent) { $parent = recast('Parents', $parent); $parent->delete(); //delete $parent } } $children = Parents::getChildrenOf($id); if ($children) { foreach ($children as $child) { $child = recast('Parents', $child); $child->delete(); //delete $child } } $mySpouse = Spouse::getById($id); if ($mySpouse) { foreach ($mySpouse as $spouse) { $spouse = recast('Spouse', $spouse); $theirSpouse = Spouse::getById($spouse->personId); if ($theirSpouse) { foreach ($theirSpouse as $otherSpouse) { $otherSpouse = recast('Spouse', $otherSpouse); $otherSpouse->delete(); //delete $otherSpouse } } $spouse->delete(); //delete $spouse } } $tags = Tag::getByIndId($id); if ($tags) { foreach ($tags as $tag) { $tag = recast('Tag', $tag); $tag->delete(); } } $person->delete(); return true; } else { return true; } } return false; } else { if (($that->method === 'POST' || $that->method === 'PUT') && $session->isLoggedIn()) { $user = User::current_user(); if (!$user->id) { return false; } $result = $that->file; if (empty($result) || empty($result->person) || empty($result->birth) || empty($result->death)) { return 'we failed on check1'; return false; } // return $result; $person = recast('Person', $result->person); if ($person->id) { $tempPerson = Person::getById($person->id); $person->submitter = $tempPerson->submitter; $person->status = $tempPerson->status; if ($person->submitter !== $user->id && !($user->rights === 'super' || $user->rights === 'admin')) { return 'we failed on check2'; return false; } } if (!empty($person)) { $personId = $person->save($user); } else { return false; } if (!!$personId) { $person->id = $personId; $birth = recast('Birth', $result->birth); $birth->personId = $personId; $birthId = $birth->save(); $birth->id = $birthId; $death = recast('Death', $result->death); $death->personId = $personId; $deathId = $death->save(); $death->id = $deathId; if ($result->burial) { $burial = recast('Burial', $result->burial); $burial->personId = $personId; $burialId = $burial->save(); $burial->id = $burialId; } else { $burial = false; } if (empty($personId) || empty($birthId) || empty($deathId)) { return 'test'; return false; } if ($result->birthPlace) { $birthPlace = recast('Place', $result->birthPlace); $birthPlace->ft_name = "birth"; $birthPlace->fkey = $birthId; $birth->place = $birthPlace->save(); $birth->save(); } else { $birth->place = null; $birth->save(); } if ($result->deathPlace) { $deathPlace = recast('Place', $result->deathPlace); $deathPlace->ft_name = "death"; $deathPlace->fkey = $deathId; $death->place = $deathPlace->save(); $death->save(); } else { $death->place = null; $death->save(); } if ($burial) { if ($result->burialPlace) { $burialPlace = recast('Place', $result->burialPlace); $burialPlace->ft_name = "burial"; $burialPlace->fkey = $burial->id; $burial->place = $burialPlace->save(); $burial->save(); } else { $burial->place = null; $burial->save(); } } else { $burial = Burial::getById($person->id); if ($burial && $burial->id) { $burial = recast('Burial', $burial); $burial->delete(); } } if ($result->parents) { if ($person->id) { $parents = Parents::getParentsOf($person->id); if ($parents) { $missing = array(); foreach ($parents as $parent) { if (!objectListContains($result->parents, 'id', $parent->parentId)) { $missing[] = $parent; } } foreach ($missing as $parent) { $parent = recast('Parents', $parent); $parent->delete(); } foreach ($result->parents as $key) { if (!objectListContains($parents, 'parentId', $key->id)) { $newPadre = new Parents(); $newPadre->child = $person->id; $newPadre->gender = $key->sex === 'male' ? 'father' : 'mother'; $newPadre->parentId = $key->id; $newPadre->save(); } } } else { foreach ($result->parents as $key) { $newPadre = new Parents(); $newPadre->child = $person->id; $newPadre->gender = $key->sex === 'male' ? 'father' : 'mother'; $newPadre->parentId = $key->id; $newPadre->save(); } } } else { return 'We have an error'; } } else { $parents = Parents::getParentsOf($person->id); if ($parents) { foreach ($parents as $parent) { $parent = recast('Parents', $parent); $parent->delete(); } } } if ($result->spouse) { $spouses = Spouse::getAllSpousesById($person->id); if ($spouses) { $missing = array(); foreach ($spouses as $spouse) { if (!objectListContains($result->spouse, 'id', $spouse->spouse)) { $missing[] = $spouse; } } foreach ($missing as $spouse) { $spouse = recast('Spouse', $spouse); $place = Place::getById($spouse->place); if ($place) { $place = recast('Place', $place); $place->delete(); } $otherSpouse = Spouse::getByPair($spouse->personId, $spouse->spouse); if ($otherSpouse) { $place = Place::getById($otherSpouse->place); if ($place) { $place = recast('Place', $place); $place->delete(); } $otherSpouse = recast('Spouse', $otherSpouse); $otherSpouse->delete(); } $spouse->delete(); } foreach ($result->spouse as $spouse) { if (!objectListContains($spouses, 'spouse', $spouse->id)) { Spouse::addSpouse($spouse, $person->id, $spouse->id); Spouse::addSpouse($spouse, $spouse->id, $person->id); } else { Spouse::updateSpouse($spouse, $spouse->id, $person->id); Spouse::updateSpouse($spouse, $person->id, $spouse->id); } } } else { foreach ($result->spouse as $spouse) { Spouse::addSpouse($spouse, $person->id, $spouse->id); Spouse::addSpouse($spouse, $spouse->id, $person->id); } } } else { $spouses = Spouse::getAllSpousesById($person->id); if ($spouses) { foreach ($spouses as $spouse) { $spouse = recast('Spouse', $spouse); $place = Place::getById($spouse->place); if ($place) { $place = recast('Place', $place); $place->delete(); } $otherSpouse = Spouse::getByPair($spouse->personId, $spouse->spouse); if ($otherSpouse) { $place = Place::getById($otherSpouse->place); if ($place) { $place = recast('Place', $place); $place->delete(); } $otherSpouse = recast('Spouse', $otherSpouse); $otherSpouse->delete(); } $spouse->delete(); } } } return $person; } return false; } else { return "Only accepts POST and GET requests"; } } } }
public function setUp() { User::$current_user = new User(); User::$current_user->uid = 1; }
function handleUserAPI($args, $that) { require_once APIROOT . 'controller/user.php'; if ($that->method === 'POST') { if ($that->verb === 'login') { $result = $that->file; $result = login(isset($result->username) ? $result->username : null, isset($result->password) ? $result->password : null); return User::current_user(); } else { if ($that->verb === 'logout') { return $session->logout(); } else { if ($that->verb === 'register') { $result = $that->file; $result->username = isset($result->username) ? $result->username : null; $result->password = isset($result->password) ? $result->password : null; $result->email = isset($result->email) ? $result->email : null; $result->first = isset($result->first) ? $result->first : null; $result->last = isset($result->last) ? $result->last : null; $result->gender = isset($result->gender) ? $result->gender : null; $result = register($result); return User::current_user(); } else { if ($that->verb === 'sendAdminMessage') { $user = User::current_user(); $that->file->name = $user->displayableName; $that->file->email = $user->email; return sendAdminMessage($that->file); } else { if ($that->verb === 'resetPassword') { $user = User::getByUsername($that->file->username); if ($user) { return $user->resetPassword(); } } } } } } } if ($that->method === 'GET') { if ($that->verb === '') { $session = mySession::getInstance(); $user_id = $session->getVar('user_id'); if ($user_id) { $user = User::getById($user_id); unset($user->password); return $user; } else { return false; } } if ($that->verb === 'validate') { $id = getRequest('id'); $value = getRequest('validate'); return validate($id, $value); } if ($that->verb === 'isLoggedIn') { return User::current_user(); } if ($that->verb === 'getUserInfo' && $session->isLoggedIn() && $session->isAdmin()) { $id = intval(array_shift($args)); if ($id && is_numeric($id)) { $user = User::getById($id); unset($user->password); return $user; } else { return User::getAllUsers(); } } $user = User::current_user(); unset($user->password); return $user; // return "that is a test"; } else { return "Only accepts GET AND POSTS requests"; } }
/** * Function is called to set-up the current user before all other calls. * For an authentic user, settings and details are updated. * * @return bool */ public function authenticateUser() { if (isset($_SESSION["userData"]) && $_SESSION["userData"]->uid) { User::$current_user = $_SESSION["userData"]; //User::$current_user->refreshDetails(); //User::$current_user->refreshSettings(); } else { $_SESSION["userData"] = User::cookieLogin(); User::$current_user = $_SESSION["userData"]; //User::$current_user->getFriends(); } User::$current_user->initialize(); return true; }
protected function deactivateIndividual($args) { $session = mySession::getInstance(); if (($this->method === 'POST' || $this->method === 'PUT') && $session->isLoggedIn() && $session->isAdmin()) { $id = intval(array_shift($args)); if ($id && is_numeric($id)) { $person = Person::getById($id); if (isset($person) && $person) { $user = User::current_user(); $person->deactivate($user); return $person; } else { return false; } } else { return false; } } else { return 'You may only POST/PUT to this endpoint and Admin is required'; } }
public function isAdmin() { $user = User::current_user(); if ($user) { $result = false; switch ($user->rights) { case "super": case "admin": $result = true; break; default: $result = false; } return $result; } else { return false; } }
function add_latest($type, $r_id, $content) { $user = User::current_user(); $db = get_db(); $sql = "insert into eachbb_member (resource_type,resource_id,content,created_at,u_id,u_name,u_avatar) values('{$type}',{$r_id},'{$content}',now(),{$user->id},'{$user->name}','{$user->avatar}')"; return $db->execute($sql); }
<a class="brand" href="<?php echo $this->make_route('/'); ?> ">Verge</a> <div class="nav-collapse"> <ul class="nav"> <li><a href="<?php echo $this->make_route('/'); ?> ">Home</a></li> <?php if (User::is_authenticated()) { ?> <li><a href="<?php echo $this->make_route('/user/' . User::current_user()); ?> "> My Profile </a></li> <li><a href="<?php echo $this->make_route('/logout'); ?> "> Logout </a></li> <?php } else { ?> <li><a href="<?php echo $this->make_route('/signup'); ?> "> Signup </a></li> <li><a href="<?php echo $this->make_route('/login');