示例#1
0
 public function indexAction()
 {
     $_request = new Request();
     $title = MetaHelper::setPageTitle('Главная(admin)');
     $login_form = new LoginForm($_request);
     $errors = array();
     if ($_request->isPost()) {
         if ($login_form->validate()) {
             $user = new UserModel();
             $login = $_request->post('login');
             $hash_password = new Password($_request->post('password'));
             $res = $user->getUser($login, $hash_password);
             if (!$res) {
                 $msg = "No such user";
             } else {
                 Session::set('user', $res);
                 $msg = "You have successfully logged in!";
             }
             Session::setFlash($msg);
         } else {
             $errors = $login_form->showErrors();
         }
     }
     $model = new WeatherModel();
     $data = $model->getSourcelist();
     $args = ['errors' => $errors, 'data' => $data, 'page_title' => $title];
     return $this->render('index.phtml', $args, 'admin');
 }
 public function authenticate(\model\UserModel $user)
 {
     $this->user = $user;
     if ($user->getUsername() === self::$username && $user->getPassword() == self::$password) {
         return true;
     } else {
         return false;
     }
 }
示例#3
0
 public function save(UserModel $user)
 {
     try {
         $sql = "INSERT INTO {$this->dbTable} (" . self::$usernameColumn . "," . self::$passwordColumn . ") VALUE (?,?)";
         $params = array($user->getUsername(), sha1($user->getPassword()));
         $query = $this->database->prepare($sql);
         $query->execute($params);
     } catch (\PDOException $e) {
         return false;
     }
 }
示例#4
0
文件: Controller.php 项目: jankal/mvc
 /**
  * @todo return the value of the given attribute of the logged in user using Session and the UserModel
  * @param string $attr
  * @return mixed
  * @todo core: necessary?
  */
 public function user($attr = NULL)
 {
     var_dump(debug_backtrace());
     if ($this->loggedIn()) {
         $udat = \Session::get('user');
         if ($attr == NULL) {
             return $this->UserModel->sync($udat);
         } else {
             return $this->UserModel->sync($udat)[$attr];
         }
     } else {
         return false;
     }
 }
示例#5
0
 public function change_pwd()
 {
     $UserModel = new UserModel();
     if (!$UserModel->create(I('post.'), 5)) {
         $this->ajaxReturn($UserModel->getError());
     } else {
         $data['password'] = md5(I('post.newpassword'));
         //$this->ajaxReturn($UserModel->change_pwd($data));
         if ($UserModel->change_pwd($data) > 0) {
             $this->ajaxReturn(['msg' => 1, 'ts' => '密码修改成功']);
         } else {
             $this->ajaxReturn(['msg' => 0, 'ts' => '密码修改失败']);
         }
     }
 }
示例#6
0
文件: JoinTest.php 项目: meniam/model
 /**
  * @group Model
  * @group itrun
  */
 public function testJoin()
 {
     /**
      * @var TagModel
      */
     $productModel = ProductModel::getInstance();
     $this->assertInstanceOf('Model\\ProductModel', $productModel);
     $this->assertInstanceOf('Model\\Cond\\ProductCond', $productModel->getCond());
     /**
      * @var UserModel
      */
     $userModel = UserModel::getInstance();
     $this->assertInstanceOf('Model\\UserModel', $userModel);
     $this->assertInstanceOf('Model\\Cond\\UserCond', $userModel->getCond());
     $cond = $userModel->getCond()->where(array('email' => '*****@*****.**'));
     $userModel->delete($cond);
     /** @var UserEntity $data */
     $data = $userModel->getByEmail('*****@*****.**');
     $this->assertInstanceOf('Model\\Entity\\UserEntity', $data);
     $this->assertFalse($data->exists());
     $user = array('email' => '*****@*****.**', '_user_info' => array('about' => 'just a test'));
     $userModel->import($user);
     $data = $userModel->getByEmail('*****@*****.**');
     $this->assertInstanceOf('Model\\Entity\\UserEntity', $data);
     $this->assertTrue($data->exists());
     $cond = $userModel->getCond()->where(array('email' => '*****@*****.**'))->with(UserCond::WITH_USER_INFO);
     $user = $userModel->get($cond);
     $this->assertInstanceOf('Model\\Entity\\UserInfoEntity', $user->getUserInfo());
 }
示例#7
0
文件: UserDAO.php 项目: Shooter75/www
 /**
  * @param $model, User Model
  * @return UserModel, JsonSerialise
  */
 public function read($model)
 {
     $id = $model->getId();
     $sql = "SELECT *\n                    FROM `tbluser`\n                    WHERE `id` = '{$id}'";
     $response = $this->dao->connection->query($sql);
     $response = mysqli_fetch_row($response);
     $readId = $response[0];
     $readFirstName = $response[1];
     $readLastName = $response[2];
     $readLogin = $response[3];
     $readPassword = $response[4];
     $readUser = new UserModel();
     $readUser->setId($readId);
     $readUser->setFirstName($readFirstName);
     $readUser->setLastName($readLastName);
     $readUser->setLogin($readLogin);
     $readUser->setPassword($readPassword);
     return $readUser;
 }
示例#8
0
 public function getIdByLogin($login)
 {
     $model = new UserModel();
     $model->setLogin($login);
     if ($this->validateModel($model)) {
         return $this->dao->getIdByLogin($model);
     }
     return null;
 }
 public function get()
 {
     $blog = new UserModel();
     $rs = $blog->search("1");
     print_r($rs);
 }