Пример #1
0
 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
0
 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
0
 /**
  * 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
0
 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
0
 public function testDelete()
 {
     $userMapper = new UserMapper();
     $userMapper->setId(2);
     $userMapper->deleteUser();
     $this->assertEquals(new User(), $userMapper->selectUser());
 }
Пример #6
0
 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
0
 /**
  * 
  * @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
0
 /**
  * 
  * @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
0
 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
0
 /**
  * Returns an singleton instance of this class
  * @return
  */
 public static function getInstance()
 {
     if (self::$instance == null) {
         self::$instance = new UserMapper();
     }
     return self::$instance;
 }
Пример #11
0
 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
0
 /**
  * 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
0
 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 = "******";
     } else {
         foreach ($result as $value) {
             if ($value['login'] != NULL) {
                 $login = $value['login'];
             } else {
                 $login = "******";
             }
         }
     }
     return $login;
 }
Пример #14
0
 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
0
 public function mostrarJuradoPop()
 {
     if (!isset($this->currentUser)) {
         throw new Exception("user is mandatory");
     }
     $login = $this->currentUser->getLogin();
     $jurado = $this->userMapper->buscarJuradoPopular($login);
     $this->view->setVariable("jurado", $jurado);
     $this->view->render("users", "perfilJuradoPop");
 }
Пример #16
0
 /**
  * 
  * @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;
     }
 }
	/**
	 * Draws this datatype as a HTML widget directly into the output stream
	 */
	function drawWidget()
	{	
		$userMapper = new UserMapper();
		$userArray = $userMapper->getAll();
		
		?>
		<select name="<?php echo $this->getName()?>" id="<?php echo $this->getName()?>">
			<option value=""></option>
			<?php foreach($userArray as $user) 
			{ 
				/* @var $user User */
				$selected = "";
				if ($user->getId() == $this->getValue()) $selected = "selected=\"selected\"";
			?>			
			<option <?php echo $selected?> value="<?php echo $user->getId()?>"><?php echo $user->getName()?></option>
			<?php }?>
		</select>
		<?
	}
 public function findById($id)
 {
     $row = $this->query('SELECT * FROM users_tb WHERE id = ' . (int) $id)->fetch();
     if (!$row) {
         return null;
     }
     $user = new User();
     UserMapper::map($user, $row);
     return $user;
 }
Пример #19
0
 /**
  * Initializes DB mappers
  *
  * @param object $config
  * @param object $args
  * @return
  */
 function __construct($config, $args)
 {
     $this->mapper = UserMapper::getInstance();
     $this->companyMapper = CompanyMapper::getInstance();
     $this->serviceCompanyMapper = ServiceCompanyMapper::getInstance();
     $this->serviceCompanyManager = ServiceCompanyManager::getInstance($config, $args);
     $this->adminMapper = AdminMapper::getInstance();
     $this->config = $config;
     $this->args = $args;
 }
Пример #20
0
 public function read()
 {
     $result = array();
     $sql = 'SELECT * FROM user_tb';
     foreach ($this->query($sql) as $row) {
         $user = new User();
         UserMapper::map($user, $row);
         $result[$user->getId()] = $user;
     }
     return $result;
 }
Пример #21
0
 public function find($status = null)
 {
     $result = array();
     $sql = 'SELECT id, first_name, user_password , status FROM user_tb WHERE ' . 'status = "' . $status . '";';
     foreach ($this->query($sql) as $row) {
         $user = new User();
         UserMapper::map($user, $row);
         $result[$user->getId()] = $user;
     }
     return $result;
 }
Пример #22
0
 public function findUserByEmail(User $user)
 {
     $result = array();
     $email = $user->getEmail();
     $sql = 'SELECT id FROM users_tb WHERE ' . 'email = "' . $email . '";';
     foreach ($this->query($sql) as $row) {
         $user = new User();
         UserMapper::map($user, $row);
     }
     return $user->getId();
 }
 /**
   find user's detail by sql
 */
 public function find($status = null)
 {
     $result = array();
     $sql = 'SELECT user_id, first_name, last_name, email, phone_number FROM products;';
     //product_name
     foreach ($this->query($sql) as $row) {
         $user = new User();
         UserMapper::map($user, $row);
         $result[$user->getUserId()] = $user;
     }
     return $result;
 }
Пример #24
0
 public function loginAction()
 {
     // On récupère la valeur du login et du mot de passe saisi dans le formulaire
     // Sécurité contre la saisie de code html ou javascript
     // On convertit tous les caractères éligibles en entités HTML pour empêcher leur interprétation.
     $S_login = htmlentities($_POST['login'], ENT_QUOTES);
     $S_password = htmlentities($_POST['password'], ENT_QUOTES);
     // on stocke le login dans la session :
     Session::setSession('login', $S_login);
     // si on a pas un identifiant et un mot de passe on renvoit sur la page de login.
     if (null == $S_login || null == $S_password) {
         // on stocke le message d'erreur dans la clef error
         Session::setSession('error', 'Un identifiant et un mot de passe doivent être saisis');
         die(header('Location:/login'));
     }
     try {
         // on fait appelle au modèle UserMapper pour vérifier dans la base si le login existe
         $O_userMapper = new UserMapper();
         // on utilise la méthode recherche par login
         $O_user = $O_userMapper->findByLogin($S_login);
     } catch (Exception $e) {
         Session::setSession('error', $e->getMessage());
         die(header('Location:/login'));
     }
     // on vérifie le mot de passe :
     if ($O_user->getPassword() === sha1($S_password)) {
         session_regenerate_id();
         $O_user->setPassword(null);
         Session::setSession('user', $O_user);
         Session::setSession('error', null);
         die(header('Location:/'));
     } else {
         Session::setSession('error', 'Le mot de passe incorrect');
         die(header('Location:/login'));
     }
 }
Пример #25
0
 public function update()
 {
     $userid = $_REQUEST["usuario"];
     $user = $this->userMapper->findById($userid);
     $errors = array();
     $pass = md5($_POST["passActual"]);
     if ($this->userMapper->isValidUser($_POST["usuario"], $pass)) {
         if (isset($_POST["usuario"])) {
             $user->setNombre($_POST["nombre"]);
             $user->setApellidos($_POST["apellidos"]);
             $user->setCorreo($_POST["correo"]);
             if (isset($_FILES['img'])) {
                 $img = $_FILES['img']['name'];
                 $ext = strrchr($img, '.');
                 $ruta = 'imagenes/user_' . $user->getId() . $ext;
                 if (move_uploaded_file($_FILES['img']['tmp_name'], $ruta)) {
                     $user->setImagen($user->getId() . $ext);
                 }
             }
             if (!(strlen(trim($_POST["passNew"])) == 0)) {
                 if ($_POST["passNew"] == $_POST["passNueva"]) {
                     $passNew = md5($_POST["passNew"]);
                     $user->setPassword($passNew);
                 } else {
                     $errors["pass"] = i18n("Passwords must be equal");
                     $this->view->setVariable("errors", $errors);
                     $this->view->setVariable("user", $user);
                     $this->view->render("users", "modificar");
                     return false;
                 }
             }
             try {
                 $this->userMapper->update($user);
                 $this->view->setFlash(i18n("Modified user correctly"));
                 $this->view->redirect("users", "perfil");
             } catch (ValidationException $ex) {
                 $errors = $ex->getErrors();
                 $this->view->setVariable("errors", $errors);
             }
         }
     } else {
         $errors["passActual"] = i18n("Incorrect password");
         $this->view->setVariable("errors", $errors);
         $this->view->setVariable("user", $user);
         $this->view->render("users", "modificar");
     }
 }
Пример #26
0
 /**
  * @param int $id
  * @param string $key
  */
 public function activateUser($id, $key)
 {
     $this->userMapper->setSelectedRecordStatus(\Model\Common\RecordStatus::UNFINISHED);
     $user = $this->userMapper->findByPk($id);
     /** @var User $user */
     $this->userMapper->setSelectedRecordStatus(\Model\Common\RecordStatus::VALID);
     if (!is_null($user)) {
         $key = $this->actionKeyMapper->findByKey($key);
         if (!is_null($key)) {
             $user->setStatus(\Model\Common\RecordStatus::VALID);
             $this->saveUser($user);
             $key->setStatus(\Model\Common\RecordStatus::DELETED);
             $this->actionKeyMapper->save($key);
         } else {
             throw new \Nette\UnexpectedValueException("forms.register.errors.not-exists-key");
         }
     } else {
         throw new \Nette\UnexpectedValueException("forms.register.messages.already-activated");
     }
 }
Пример #27
0
 public function registerProfesional()
 {
     $jpop = new JuradoProfesional();
     $currentuser = $this->view->getVariable("currentusername");
     if (isset($_POST["usuario"])) {
         $jpop->setId($_POST["usuario"]);
         $jpop->setNombre($_POST["nombre"]);
         $jpop->setEmail($_POST["correo"]);
         $jpop->setProfesion($_POST["profesion"]);
         $jpop->setOrganizador($currentuser);
         $jpop->setTipo("juradoProfesional");
         if ($_POST["pass"] == $_POST["repass"]) {
             $jpop->setPassword($_POST["pass"]);
         } else {
             $errors["pass"] = "******";
             $this->view->setVariable("errors", $errors);
             $this->view->render("users", "registerProfesional");
             return false;
         }
         try {
             $jpop->checkIsValidForCreate();
             if (!$this->userMapper->usernameExists($_POST["usuario"])) {
                 $this->userMapper->save($jpop);
                 $this->view->setFlash("Usuario " . $jpop->getId() . " registrado.");
                 $this->view->redirect("concurso", "index");
             } else {
                 $errors = array();
                 $errors["usuario"] = "El usuario ya existe";
                 $this->view->setVariable("errors", $errors);
             }
         } catch (ValidationException $ex) {
             $errors = $ex->getErrors();
             $this->view->setVariable("errors", $errors);
         }
     }
     $this->view->setVariable("juradoProfesional", $jpop);
     $this->view->render("users", "registerProfesional");
 }
Пример #28
0
<?php

$rootPass = dirname(__FILE__) . '/../../';
require_once $rootPass . 'lib/db/dbfunctions.php';
require_once $rootPass . 'lib/db/Model/User.php';
require_once $rootPass . 'lib/db/Mapper/UserMapper.php';
$pdo = getPDO($argv[2]);
$umapper = new UserMapper($pdo);
$user = $umapper->findByName($argv[1]);
$userArray = (array) $user;
foreach ($userArray as $value) {
    // オブジェクトのネストを解消(だいぶ汚いので後で直す)
    $userArray = $value;
    break;
}
header("Content-Type: application/json; charset=utf-8");
echo json_encode((array) $userArray);
// echo json_encode($result);
Пример #29
0
require_once 'Horde/Autoloader.php';
@(include './conf.php');
if (empty($conf)) {
    die("No configuration found\n");
}
/**
 */
class User extends Horde_Rdo_Base
{
}
/**
 */
class UserMapper extends Horde_Rdo_Mapper
{
}
$um = new UserMapper($conf['adapter']);
// Count all users.
$userCount = $um->count();
echo "# users: {$userCount}\n";
// Get the number of new users in May 2005
//$userCount = $um->count('created > \'2005-05-01\' AND created <= \'2005-05-31\'');
//echo "# new: $userCount\n";
// Check if id 1 exists.
$exists = $um->exists(1);
echo "exists: " . ($exists ? 'yes' : 'no') . "\n";
// Look for Alice
$userTwo = $um->findOne(array('name' => 'Alice'));
if ($userTwo) {
    echo "Found Alice: id {$userTwo->id}\n";
} else {
    echo "No Alice found, creating:\n";
Пример #30
0
 public function eliminar_comentario($idpincho)
 {
     UserMapper::eliminar_comentario($idpincho, $this->idemail);
 }