public function view() { $dao = DAO::getDAO('UserDAO'); if (isset($this->params[0]) && trim($this->params[0]) == 'remove') { // ex: requesting: /user-list/delete/2 $id = trim(sanitizeString($this->params[1])); $dao->removeById($id); } else { if (isset($this->params[0]) && trim($this->params[0]) == 'add') { $randNum = mt_rand(0, 99999); $newUser = new User(array('firstName' => 'First', 'lastName' => 'LastName', 'username' => "test{$randNum}", 'email' => "test{$randNum}@example.com", 'createTime' => dbDateTime())); // #TODO: implement UserDao.create($newUser) instead. if ($dao->countAll() > 30) { // Demo mode: clean up if too many users $dao->execute("DELETE FROM user"); $dao->execute("vacuum"); } $dao->insertInto("firstName, lastName, username, email, createTime", $newUser->getFields()); } } $users = $dao->getAll(); $v = $this->smarty; $v->assign('title', 'User List'); $v->assign('inc_content', v('user_list.html')); $v->assign('users', $users); $v->assign('totalUsers', $dao->countAll()); $this->display($v, v('index.html')); }
function test_if_user_model_has_custom_fields() { $fields = User::getFields(); $this->assertCount(2, $fields); $this->assertArrayHasKey('title', $fields); $this->assertArrayHasKey('name', $fields); }
public function register() { try { $errors = array(); $success = false; $isPost = $this->request->isPost(); $user = new User(); try { $fb_active = API_Facebook::isActive(); if ($fb_active) { $fb_user = $user->getFacebookUser(ROOT_HTTP . 'register'); if (!empty($fb_user)) { $this->response->redirect(ROOT_HTTP); } } } catch (Exception $e) { $errors['authent'] = $e->getMessage(); } $confirm_email = $this->request->post('confirm_email', ''); $confirm_password = $this->request->post('confirm_password', ''); if ($isPost) { foreach ($user->getFields() as $key => $value) { try { $user->{$key} = $this->request->post($key, ''); } catch (Exception $e) { $errors[$key] = $e->getMessage(); } } if (empty($confirm_email) || strcmp($user->email, $confirm_email) !== 0) { $errors['confirm_email'] = Lang::_('You must confirm your email'); } if (empty($confirm_password) || strcmp($user->password, $confirm_password) !== 0) { $errors['confirm_password'] = Lang::_('You must confirm your password'); } if (empty($errors)) { $user_already_exists = $user->checkAlreadyExists(); if ($user_already_exists === true) { $errors['email'] = Lang::_('Email already in use'); } else { $user->password = password_hash($user->password, PASSWORD_BCRYPT); $user_id = $user->register(); if (!empty($user_id)) { $success = $user->login(); } else { $errors['authent'] = Lang::_('Register failed'); } } } } $form = $user->getRegisterForm('insert', ROOT_HTTP . $this->lang->getUserLang() . '/user/register', $this->request, $isPost, $errors); $vars = array('title' => Lang::_('Register'), 'isPost' => $isPost, 'form' => $form, 'errors' => $errors, 'success' => $success); } catch (Exception $e) { $vars['debug'] = $e->getMessage(); } return $this->render('authent', $vars); }
/** * Returns the raw user info blobs * * The userId format is uid. * * @param string[] $uids The social provider user ids * @param string $egoToken The auth token of user who init the query * @return array[string] The associated user blob array keyed with user id. * If a user can not be fetched, it will not show up in the results */ private function _getUsers($uids, $egoToken) { $batch = new FacebookBatchedRequests(); $userFields = User::getFields(); foreach ($uids as $uid) { $batch->addRequest('GET', "/{$uid}?fields=" . $userFields, NULL, $uid); } $batchResp = $batch->send($this->_graphUrl, $egoToken, $this->_maxBatch); $results = array(); foreach ($uids as $uid) { if (isset($batchResp[$uid])) { $results[$uid] = $batchResp[$uid]; } } return $results; }
public function processPost() { parent::processPost(); // #TODO: User submitted data. Save it to DB, email, etc. copyArray($_POST, $v, '*'); $dao = DAO::getDAO('UserDAO'); $newUser = new User(array('firstName' => 'First', 'lastName' => 'LastName', 'username' => $v['username'], 'email' => $v['email'], 'password' => $v['password'], 'createTime' => dbDateTime())); $ret = $dao->insertInto('firstName, lastName, username, email, password, createTime', $newUser->getFields()); if ($ret[0] != '00000') { $err = "<span class='msgErr'>ERROR: {$ret['2']}</span>"; } $v = $this->smarty; $v->assign('title', 'Thank you!'); $v->assign('content', '<h2>Thank you!</h2><p>Thanks for your registration.</p><p>' . $err . '<p/><p><a href="/user-list">Check User List</a><p/>'); $v->assign('inc_content', 'blank.html'); $this->display($v, v('index.html')); }
$userArray = User::getList($filter); foreach ($userArray as $user) { echo "<option value='" . htmlentities($user->id, ENT_QUOTES, "UTF-8") . "' title='" . htmlentities($user->email, ENT_QUOTES, "UTF-8") . "'"; if ($selected_user && intval($selected_user) === $user->id) { echo "selected"; } echo ">" . htmlentities($user->name, ENT_QUOTES, "UTF-8") . "</option>"; } $cnt_user = count($userArray); echo "</select>"; echo "</td>"; echo "</tr>"; } if (isset($selected_user) && $selected_user != 0) { $user = new User(intval($selected_user)); $data = $user->getFields(); if ($user->isValid()) { $name = $data["name"]; $password = $data["password"]; $owner_id = $data["owner"]; $description = $data["description"]; $login_count = $data["loginCount"]; $email = $data["email"]; $phone = $data["phone"]; $department = $data["department"]; $organization = $data["organization"]; $position = $data["position"]; $resolution = $data["resolution"]; // $uuid = $data["uuid"]; $firstname = $data["firstName"]; $lastname = $data["lastName"];