function getByPhoneNum() { if (!($phone = $_REQUEST['From'])) { Error::sms("The SMS sender's phone number was not detected."); } if (!($body = $_REQUEST['Body'])) { Error::sms("Missing email address."); } $sql = "SELECT user_id, email, wallet FROM users WHERE phone=?"; $row = DBquery::get($sql, array($phone)); if ($row) { if ($body != $row[0]['email']) { Error::sms("The email address does not match the one set for phone #{$phone}."); } else { $this->user_id = $row[0]['user_id']; Requester::$consumer_id = $row[0]['wallet']; return $this->setToken(); } } else { require_once "models/UserCollection.php"; $Users = new UserCollection(json_decode('{ "email": "' . $body . '", "name": "' . $body . '", "password": "******", "phone": "' . $phone . '", "login_provider": "phone", "wallet": 2 }')); $arr = $Users->add(); $this->user_id = $arr[0]->user_id; return $this->setToken(); } }
public function login() { $data = array(); $usersCollection = new UserCollection(); $errors = array(); if ($_SERVER['REQUEST_METHOD'] === 'POST') { if (isset($_POST['username'])) { if (isset($_POST['username']) && isset($_POST['password']) && strlen($_POST['username']) > 3 && strlen($_POST['password']) > 3) { $password = sha1($_POST['password']); $username = htmlspecialchars(trim($_POST['username'])); $where = array('username' => $username); $result = $usersCollection->getAll($where); if ($result != null && $result[0]->getPassword() == $password) { $_SESSION['user'] = $result[0]; $_SESSION['logged_in'] = 1; header('Location: index.php?c=dashboard'); } else { $errors['login'] = '******'; } } else { $errors['login'] = '******'; } } } $data['errors'] = $errors; $this->loadView('login', $data); }
function index() { static $menuaction = 'User Overview'; global $smarty; $users = new UserCollection(new User()); $users->load(); $smarty->assign('users', $users); }
/** * Enter description here... * * @param array $RecordSet * @return UserCollection */ private function doLoad($RecordSet) { $UserCollection = new UserCollection(); foreach ($RecordSet as $Row) { $UserCollection->add(new User($Row['i_Id'], $Row['s_Name'], $Row['s_Pass'], $Row['s_Email'], $Row['i_Login'], $Row['i_Refresh'], $Row['b_Looked'], $Row['d_RegisterDate'], $Row['b_Premium'], $Row['i_SpaceMax'], $Row['s_Folder'])); } return $UserCollection; }
/** * Test the location of users of a group by ID */ public function testFindUsersByGroupId() { $groupId = 1; $return = array(array('username' => 'testuser1', 'email' => '*****@*****.**'), array('username' => 'testuser2', 'email' => '*****@*****.**'), array('username' => 'testuser3', 'email' => '*****@*****.**')); $ds = $this->buildMock($return, 'fetch'); $users = new UserCollection($ds); $users->findByGroupId($groupId); $this->assertCount(3, $users); $this->assertEquals($users->toArray()[1]->username, 'testuser2'); }
function sendRegistrationCode($row) { if ($this->verType == 'register' and $row and $row['password']) { Error::http(403, "There is already a user with the email='{$this->email}'. If you typed your email correctly, recover your password instead of registering."); } $this->setAndMailVerCode(); require_once "models/UserCollection.php"; $Users = new UserCollection(json_decode('{ "email": "' . $this->email . '", "password": "******", "login_provider": "email", "ver_code": "' . $this->verCode . '", "ver_expires": "' . $this->verExpires . '" }')); $user = $Users->add()[0]; return array($user); }
function getByOauthID($info) { $tw_id = "" . $info['user_id']; $sql = "SELECT user_id FROM users WHERE tw_id=?"; $row = DBquery::get($sql, array($tw_id)); if ($row) { return $row[0]['user_id']; } require_once "models/UserCollection.php"; $Users = new UserCollection(json_decode('{ "name": "' . $info['screen_name'] . '", "password": "******", "tw_id": "' . $tw_id . '", "login_provider": "tw" }')); $arr = $Users->add(); return $arr[0]->user_id; }
function getByOauthID($user) { $fb_id = "" . $user->id; $sql = "SELECT user_id FROM users WHERE fb_id=?"; $row = DBquery::get($sql, array($fb_id)); if ($row) { return $row[0]['user_id']; } require_once "models/UserCollection.php"; $Users = new UserCollection(json_decode('{ "email": "' . $user->email . '", "name": "' . $user->first_name . " " . $user->last_name . '", "password": "******", "fb_id": "' . $fb_id . '", "login_provider": "fb" }')); $arr = $Users->add(); return $arr[0]->user_id; }
public function __construct($params) { $this->latitude = (double) $params['latitude']; $this->longitude = (double) $params['longitude']; $this->userId = (int) $_SESSION['user_id']; $this->cacheType = (int) $params['type']; $this->cacheId = (int) $params['cache_id']; $userrCollection = UserCollection::Instance(); $this->userArray = $userrCollection->getUserCollection(); $this->process(); }
public function index() { if (!$this->loggedIn()) { header('Location: index.php?c=login&m=login'); } $data = array(); //users $userCollection = new UserCollection(); $users = count($userCollection->getAll()); //customers $clientCollection = new ClientsCollection(); $client = count($clientCollection->getAll()); //tours $toursCollection = new ToursCollection(); $tours = count($toursCollection->getAll()); //blog posts $blogpostCollection = new BlogCollection(); $blogs = count($blogpostCollection->getAll()); $data['users'] = $users; $data['client'] = $client; $data['tours'] = $tours; $data['blogs'] = $blogs; $this->loadView('dashboard', $data); }
} public function age() { return $this->age; } } class UserCollection { protected $users; public function __construct(array $users) { $this->users = $users; } public function sortBy($column) { usort($this->users, function ($userOne, $userTwo) use($column) { return $userOne->{$column}() <=> $userTwo->{$column}(); }); } } $collection = new UserCollection([new User('Jeff', 30), new User('Taylor', 29), new User('Jane', 50), new User('Susie', 10)]); $collection->sortBy('age'); var_dump($collection); $games = ['Mass Effect', 'Super Mario Bros', 'Zelda', 'Fallout', 'Metal Gear']; // sort($games); // alphabat sort usort($games, function ($a, $b) { var_dump('a: ' . $a . ', b: ' . $b); // return $b <=> $a; // -1, 0, 1 return strlen($a) <=> strlen($b); }); var_dump($games);
public function findChildUsers() { $collection = new UserCollection(); $collection->addFilter(new Ajde_Filter_Join('user_node', 'user_node.user', 'user.id')); $collection->addFilter(new Ajde_Filter_Where('user_node.node', Ajde_Filter::FILTER_EQUALS, $this->getPK())); return $collection; }
<?php require_once __DIR__ . '/../common/autoload_cms.php'; require_once 'include/header.php'; $userCollection = new UserCollection(); $users = $userCollection->all(); ?> <div class="container"> <a href="user_add.php" class="btn btn-default">Add User</a> <br><br> <table class="table table-striped"> <tr> <th>Name</th> <th>Email</th> <th>Sex</th> <th>Age</th> <th>Action?</th> </tr> <?php foreach ($users as $user) { ?> <tr> <td><?php echo $user->getName(); ?> </td> <td><?php echo $user->getEmail(); ?>
public function handle(RegisterUser $command) { $user = User::registerWithData($command->userName(), Email::fromString($command->email())); $this->userCollection->add($user); }
<!-- start: Favicon --> <link rel="shortcut icon" href="img/favicon.ico"> <!-- end: Favicon --> <style type="text/css"> body { background: url(img/bg-login.jpg) !important; } </style> </head> <body> <?php $usersCollection = new UserCollection(); $errors = array(); if (isset($_POST['username'])) { if (isset($_POST['username']) && isset($_POST['password']) && strlen($_POST['username']) > 3 && strlen($_POST['password']) > 3) { $password = sha1($_POST['password']); $username = htmlspecialchars(trim($_POST['username'])); $where = array('username' => $username); $result = $usersCollection->getAll($where); if ($result != null && $result[0]->getPassword() == $password) { $_SESSION['user'] = $result[0]; $_SESSION['logged_in'] = 1; header('Location: index.php'); } else { $errors['login'] = '******'; } } else {
unset($_SESSION['flashMessage']); } ?> <a href="addUser.php" class="btn btn-large btn-success pull-right">Create new user</a> <table class="table table-striped"> <thead> <tr> <th>Username</th> <th>Email</th> <th>Description</th> </tr> </thead> <tbody> <?php $usersCollection = new UserCollection(); $page = isset($_GET['page']) ? (int) $_GET['page'] : 1; $perPage = 5; $offset = $page ? ($page - 1) * $perPage : 0; $rows = count($usersCollection->getAll()); $pagination = new Pagination(); $pagination->setPerPage($perPage); $pagination->setTotalRows($rows); $pagination->setBaseUrl("http://localhost/Lectures/Lek15/softacadTours/admin/users.php"); $users = $usersCollection->getAll(array(), $offset, $perPage); foreach ($users as $user) { ?> <tr> <td><?php echo $user->getUsername(); ?>
<?php require_once __DIR__ . '/../common/autoload_cms.php'; require_once 'include/header.php'; if ($_SERVER['REQUEST_METHOD'] === 'POST') { $entity = new User(); $entity->setEmail($_POST['email'])->setPassword(sha1($_POST['password']))->setName($_POST['name'])->setSex($_POST['sex'])->setAge($_POST['age']); $userCollection = new UserCollection(); $userCollection->save($entity); header('Location: user_list.php'); exit; } ?> <div class="container"> <form method="post" action="" enctype="multipart/form-data"> <div class="form-group"> <label for="email">Email:</label> <input type="text" name="email" id="email" class="form-control"> </div> <div class="form-group"> <label for="password">Password:</label> <input type="password" name="password" id="password" class="form-control"> </div> <div class="form-group"> <label for="name">Name:</label> <input type="text" name="name" id="name" class="form-control">
<?php require_once 'common/header.php'; if (!loggedIn()) { header('Location: login.php'); } if (!isset($_GET['id'])) { header('Location: users.php'); } $userCollection = new UserCollection(); $user = $userCollection->getOne($_GET['id']); if (is_null($user)) { header('Location: users.php'); } $insertInfo = array('username' => $user->getUsername(), 'password' => '', 'email' => $user->getEmail(), 'description' => $user->getDescription()); $errors = array(); if (isset($_POST['editUser'])) { $insertInfo = array('username' => isset($_POST['username']) ? $_POST['username'] : '', 'password' => isset($_POST['password']) ? $_POST['password'] : '', 'email' => isset($_POST['email']) ? $_POST['email'] : '', 'description' => isset($_POST['description']) ? $_POST['description'] : ''); $errors = validateUserInput($insertInfo); if (empty($errors)) { $entity = new UsersEntity(); $entity->setId($_GET['id']); $entity->setUsername($insertInfo['username']); $entity->setPassword($insertInfo['password']); $entity->setEmail($insertInfo['email']); $entity->setDescription($insertInfo['description']); $userCollection->save($entity); $_SESSION['flashMessage'] = 'You have 1 affected row'; header('Location: users.php'); } }
public function name() { return $this->name; } public function age() { return $this->age; } } class UserCollection { protected $users; public function __construct(array $users) { $this->users = $users; } public function users() { return $this->users; } public function sortBy($method) { usort($this->users, function ($userOne, $userTwo) use($method) { return $userOne->{$method}() <=> $userTwo->{$method}(); }); } } $collection = new UserCollection([new User('jabed', 126), new User('bangali', 36), new User('hasan', 46), new User('babu', 56), new User('md', 66)]); //$collection->sortBy('age'); $collection->sortBy('name'); var_dump($collection->users());
<?php require_once 'common/header.php'; if (!loggedIn()) { header('Location: login.php'); } if (!isset($_GET['id'])) { header('Location: users.php'); } $userCollection = new UserCollection(); $user = $userCollection->getOne($_GET['id']); if (is_null($user)) { header('Location: users.php'); } $userCollection->delete($user->getId()); header('Location: users.php'); ?>
public function delete() { if (!$this->loggedIn()) { header('Location: index.php?c=login&m=login'); } if (!isset($_GET['id'])) { header('Location: index.php?c=user&m=index'); } $userCollection = new UserCollection(); $user = $userCollection->getOne($_GET['id']); if (is_null($user)) { header('Location: index.php?c=user&m=index'); } $userCollection->delete($user->getId()); header('Location: index.php?c=user&m=index'); }
<?php require_once __DIR__ . '/../common/autoload_cms.php'; require_once 'include/header.php'; if (isset($_GET['id']) && isset($_GET['confirm'])) { $userCollection = new UserCollection(); $userCollection->remove(array('id' => $_GET['id'])); header('Location: user_list.php'); } ?> <div class="container"> <h1>Are you sure you want to delete this user?</h1> <a href="user_delete.php?id=<?php echo $_GET['id']; ?> &confirm=1" class="btn btn-danger">Yes</a> <a href="user_list.php" class="btn btn-default">No</a> </div> <?php require_once 'include/footer.php';