本文整理汇总了PHP中UserMapper类的典型用法代码示例。如果您正苦于以下问题:PHP UserMapper类的具体用法?PHP UserMapper怎么用?PHP UserMapper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了UserMapper类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: passwordReset
public function passwordReset($request, $db)
{
$user_mapper = new UserMapper($db, $request);
$username = filter_var($request->getParameter("username"), FILTER_SANITIZE_STRING);
if (empty($username)) {
throw new Exception("A username must be supplied", 400);
} else {
$list = $user_mapper->getUserByUsername($username);
if (is_array($list['users']) && count($list['users'])) {
$user = $list['users'][0];
// neither user_id nor email are in the user resource returned by the mapper
$user_id = $user_mapper->getUserIdFromUsername($username);
$email = $user_mapper->getEmailByUserId($user_id);
$recipients = array($email);
// we need a token to send so we know it is a valid reset
$token = $user_mapper->generatePasswordResetTokenForUserId($user_id);
if (!$token) {
throw new Exception("Unable to generate a reset token", 400);
}
$emailService = new UserPasswordResetEmailService($this->config, $recipients, $user, $token);
$emailService->sendEmail();
header("Content-Length: 0", NULL, 202);
exit;
}
throw new Exception("Can't find that user", 400);
}
}
示例2: __construct
public function __construct()
{
$this->view = ViewManager::getInstance();
// get the current user and put it to the view
if (session_status() == PHP_SESSION_NONE) {
session_start();
}
if (isset($_SESSION["currentuser"])) {
$this->currentUser = new User(NULL, $_SESSION["currentuser"]);
//add current user to the view, since some views require it
$usermapper = new UserMapper();
$this->tipo = $usermapper->buscarPorLogin($_SESSION["currentuser"]);
/* print_r($this->tipo);
die();*/
$this->view->setVariable("tipo", $this->tipo);
$this->view->setVariable("currentusername", $this->currentUser->getLogin());
}
if (isset($_SESSION["currentcod1"]) && isset($_SESSION["currentcod2"]) && isset($_SESSION["currentcod3"])) {
$codigomapper1 = new CodigoMapper();
$this->currentCod1 = $codigomapper1->buscarPinchoPorCodigo($_SESSION["currentcod1"]);
$codigomapper2 = new CodigoMapper();
$this->currentCod2 = $codigomapper2->buscarPinchoPorCodigo($_SESSION["currentcod2"]);
$codigomapper3 = new CodigoMapper();
$this->currentCod3 = $codigomapper3->buscarPinchoPorCodigo($_SESSION["currentcod3"]);
}
}
示例3: login
/**
* Tries to log the user using the username and password received in the post.
*/
function login()
{
$text = $this->icfTemplating->getText();
$username = $_POST["username"];
$password = $_POST["password"];
// No data for login...
if ($username == "") {
$this->controllerData["loginfailed"] = $text["incorrectinput"];
$this->show_view();
return;
}
// Get the user
$userMapper = new UserMapper();
$user = $userMapper->findByName($username);
if ($user != null) {
// The user exists, validate the password
$login = $user->login($password);
if ($login) {
// User logged in !! register it in the session
$session = new Session($user);
// Redirect to home
$this->show_home_view();
return;
}
}
// The login has failed, send the error
$this->controllerData["loginfailed"] = $text["loginfailed"];
// .. and display the data that the user gave to us
$this->controllerData["username"] = $username;
$this->controllerData["password"] = $password;
$this->show_view();
}
示例4: findAction
public function findAction()
{
$request = new Request();
$request->initRequest();
$post = $request->getPost();
$roadMapper = new RoadMapper();
$roads = $roadMapper->getByStartFinish($post['departure_point'], $post['destination_point'], "opened");
$userMapper = new UserMapper();
$carMapper = new CarMapper();
$result = array();
if ($roads) {
foreach ($roads as $road) {
$user = $userMapper->getUserByEmail($road->driverid);
$car = $carMapper->getByAutoId($road->autoid);
$roadMapper->clear();
$getPoints = $roadMapper->getRoutPointsByRoad($road->id);
$routPoints = array();
foreach ($getPoints as $point) {
$routPoints[$point->pointqueue] = $point->point;
}
$result[] = array('startdate' => $road->startdate, 'start' => $road->start, 'start_adress' => $road->start_adress, 'finish' => $road->finish, 'finish_adress' => $road->finish_adress, 'freeseats' => $road->freeseats, 'price' => $road->price, 'terms' => $road->terms, 'rout_points' => $routPoints, 'username' => $user->username, 'surname' => $user->surname, 'rate' => $user->rate, 'photo' => $user->photo, 'age' => $user->getAge(), 'car_brand' => $car->brand, 'car_model' => $car->model);
$userMapper->clear();
$carMapper->clear();
$roadMapper->clear();
}
}
echo json_encode($result);
}
示例5: testDelete
public function testDelete()
{
$userMapper = new UserMapper();
$userMapper->setId(2);
$userMapper->deleteUser();
$this->assertEquals(new User(), $userMapper->selectUser());
}
示例6: getAction
public function getAction($request, $db)
{
$user_id = $this->getItemId($request);
// verbosity
$verbose = $this->getVerbosity($request);
// pagination settings
$start = $this->getStart($request);
$resultsperpage = $this->getResultsPerPage($request);
if (isset($request->url_elements[4])) {
switch ($request->url_elements[4]) {
case 'talks':
$talk_mapper = new TalkMapper($db, $request);
$list = $talk_mapper->getTalksBySpeaker($user_id, $resultsperpage, $start, $request, $verbose);
break;
case 'attended':
$event_mapper = new EventMapper($db, $request);
$list = $event_mapper->getEventsAttendedByUser($user_id, $resultsperpage, $start, $request, $verbose);
break;
default:
throw new InvalidArgumentException('Unknown Subrequest', 404);
break;
}
} else {
$mapper = new UserMapper($db, $request);
if ($user_id) {
$list = $mapper->getUserById($user_id, $verbose);
} else {
$list = $mapper->getUserList($resultsperpage, $start, $verbose);
}
}
return $list;
}
示例7: insertComment
/**
*
* @param Comment $comment_
* @param array $arrayFilter
* @throws InvalidArgumentException
*/
public function insertComment(Comment $comment_, array $arrayFilter = array())
{
try {
if (is_null($this->table)) {
throw new InvalidArgumentException('Attribute "table" can\'t be NULL !');
}
$userMapper = new UserMapper();
$announcementMapper = new AnnouncementMapper();
$userMapper->setId($comment_->getIdUser());
$user = $userMapper->selectUser();
$announcementMapper->setId($comment_->getIdAnnouncement());
$announcement = $announcementMapper->selectAnnouncement();
if (!is_null($user->getId()) && !is_null($announcement->getId())) {
return parent::insert($this->table, $comment_, $arrayFilter);
} elseif (is_null($user->getId())) {
throw new Exception('User is inexistant !');
} elseif (is_null($announcement->getId())) {
throw new Exception('Announcement is inexistant !');
}
} catch (InvalidArgumentException $e) {
print $e->getMessage();
exit;
} catch (Exception $e) {
print $e->getMessage();
exit;
}
}
示例8: insertMessage
/**
*
* @param Message $message_
* @param array $arrayFilter
* @throws InvalidArgumentException
*/
public function insertMessage(Message $message_, array $arrayFilter = array())
{
try {
if (is_null($this->table)) {
throw new InvalidArgumentException('Attribute "table" can\'t be NULL !');
}
$userMapper = new UserMapper();
$userMapper->setId($message_->getIdSender());
$user_sender = $userMapper->selectUser();
$userMapper->setId($message_->getIdReceiver());
$user_receiver = $userMapper->selectUser();
if (!is_null($user_sender->getId()) && !is_null($user_receiver->getId())) {
return parent::insert($this->table, $message_, $arrayFilter);
} elseif (is_null($user_sender->getId())) {
throw new Exception('User sender does not exist !');
} elseif (is_null($user_receiver->getId())) {
throw new Exception('User receiver does not exist !');
}
} catch (InvalidArgumentException $e) {
print $e->getMessage();
exit;
} catch (Exception $e) {
print $e->getMessage();
exit;
}
}
示例9: run
public function run()
{
$mapper = new UserMapper($this->adapter);
$user = new \Cactus\Entity(array('name' => 'Mr. Test', 'password' => "testingpassword", 'create_date' => date("Y-m-d H:i:s")));
list($id, $num) = $mapper->save($user);
// Dont do this for real, but I need to clean up for testing
$mapper->delete($user);
return $num === 1;
}
示例10: getInstance
/**
* Returns an singleton instance of this class
* @return
*/
public static function getInstance()
{
if (self::$instance == null) {
self::$instance = new UserMapper();
}
return self::$instance;
}
示例11: saveUser
private function saveUser()
{
$email = $this->email;
$login = $this->login;
$password = md5($this->password);
//hash
$cookie = new Cookie();
$cookieGet = $cookie->getCookie($this->app);
$user = new User();
$user->login = $login;
$user->password = $password;
$user->email = $email;
$user->cookie = $cookieGet;
$Usermapper = new UserMapper($this->db);
$Usermapper->save($user);
$this->app->redirect('/TwigBlog');
}
示例12: authenticateUser
/**
* Authenticates the current request. If the request does not contain
* auth credentials, it will generate a 401 response code and end PHP processing
* If the request contain credentials, it will be checked against the database.
* If the credentials are ok, it will return the User object just logged. If the
* credentials are invalid, it will generate a 401 code as well and end PHP
* processing.
*
* @return User the user just authenticated.
*/
public function authenticateUser()
{
if (!isset($_SERVER['PHP_AUTH_USER'])) {
header($_SERVER['SERVER_PROTOCOL'] . ' 401 Unauthorized');
header('WWW-Authenticate: Basic realm="Rest API of MVCBLOG"');
die('This operation requires authentication');
} else {
$userMapper = new UserMapper();
if ($userMapper->isValidUser($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'])) {
return new User($_SERVER['PHP_AUTH_USER']);
} else {
header($_SERVER['SERVER_PROTOCOL'] . ' 401 Unauthorized');
header('WWW-Authenticate: Basic realm="Rest API of MVCBLOG"');
die('The username/password is not valid');
}
}
}
示例13: getLogin
public function getLogin($user_id, $db)
{
$user = new User();
$user->id = $user_id;
$usermapper = new UserMapper($db);
$result = $usermapper->selectById($user);
if (empty($result)) {
$login = "Anonymous";
} else {
foreach ($result as $value) {
if ($value['login'] != NULL) {
$login = $value['login'];
} else {
$login = "Anonymous";
}
}
}
return $login;
}
示例14: find
public function find($type = null)
{
$result = array();
foreach ($this->query($this->getFindSql($type)) as $row) {
$user = new User();
UserMapper::map($user, $row);
$result[$user->getUserId()] = $user;
}
return result;
}
示例15: insertIncoming
/**
*
* @param Incoming $incoming_
* @param array $arrayFilter
* @throws InvalidArgumentException
*/
public function insertIncoming(Incoming $incoming_, array $arrayFilter = array())
{
try {
if (is_null($this->table)) {
throw new InvalidArgumentException('Attribute "table" can\'t be NULL !');
}
$userMapper = new UserMapper();
$userMapper->setId($incoming_->getIdUser());
$user = $userMapper->selectUser();
if (!is_null($user->getId())) {
return parent::insert($this->table, $incoming_, $arrayFilter);
} elseif (isset($user) && is_null($user->getId())) {
throw new Exception('User does not exist !');
}
} catch (Exception $e) {
print $e->getMessage();
exit;
}
}