نمایش نتایج 1 تا 14 از 14

نام تاپیک: مشکل کار با webuser (حل شد)

  1. #1

    مشکل کار با webuser (حل شد)

    سلام به همه دوستان
    من یک کلاس webuser تعریف کرده ام و آن رو از کلاس cwebuser مشتق گرفتم و این کلاس را در پوشه کامپوننت قرار دادم و تنظیمات مربوط به main.php را هم انجام داده ام ولی موقع لاگین شدن خطا میب ده
    شرحال برنامه ام :
    من دو جدول به نام userو role (براي گروه بندي كاربران از قبيل كاربران معمولي و مديران).
    فيلدهاي جدول user :
    Username كليد اصلي , passrole, state
    فيلدهاي جدول role :
    Id (كليد اصلي) name , و state
    کد صفحه main.php

    <?php
    return array(
    'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR. '..',
    'name'=>'My Web Application',
    'theme'=>'',
    // preloading 'log' component
    'preload'=>array('log'),

    // autoloading model and component classes
    'import'=>array(
    'application.models.*',
    'application.components.*',
    'application.modules.cms.CmsModule',
    ),

    'modules'=>array('cms',
    // uncomment the following to enable the Gii tool

    'gii'=>array(
    'class'=>'system.gii.GiiModule',
    'password'=>'gii',
    // If removed, Gii defaults to localhost only. Edit carefully to taste.
    'ipFilters'=>array('127.0.0.1','::1'),

    ),

    ),

    // application components
    'components'=>array(
    'user'=>array(
    // enable cookie-based authentication
    'class' => 'WebUser',
    'loginUrl' => '/site/login',
    'allowAutoLogin'=>true

    ),
    'cms'=>array(
    'class'=>'cms.components.Cms'
    ),
    // uncomment the following to enable URLs in path-format

    'urlManager'=>array(
    'urlFormat'=>'path',
    'rules'=>array(
    '<controller:\w+>/<id:\d+>'=>'<controller>/view',
    '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
    '<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
    //'page/<name>-<id:\d+>.html'=>'cms/node/page', // clean URLs for pages
    ),
    ),


    'db'=>array(
    'connectionString' => 'sqlite:'.dirname(__FILE__).'/../data/testdrive.db',
    ),
    // uncomment the following to use a MySQL database

    'db'=>array(
    'connectionString' => 'mysql:host=localhost;dbname=baseportal',
    'emulatePrepare' => true,
    'username' => 'root',
    'password' => '',
    'charset' => 'utf8',
    ),

    'errorHandler'=>array(
    // use 'site/error' action to display errors
    'errorAction'=>'site/error',
    ),
    'log'=>array(
    'class'=>'CLogRouter',
    'routes'=>array(
    array(
    'class'=>'CFileLogRoute',
    'levels'=>'error, warning',
    ),
    // uncomment the following to show log messages on web pages
    /*
    array(
    'class'=>'CWebLogRoute',
    ),
    */
    ),
    ),
    ),

    // application-level parameters that can be accessed
    // using Yii::app()->params['paramName']
    'params'=>array(
    // this is used in contact page
    'adminEmail'=>'webmaster@example.com',
    ),

    );

    ?>

    کد کلاس webuser


    <?php
    // this file must be stored in:
    // protected/components/WebUser.php
    class WebUser extends CWebUser {

    // Store model to not repeat query.
    private $_model;

    // Return first name.
    // access it by Yii::app()->user->first_name
    public function getDisplayName(){
    $user = $this->loadUser(Yii::app()->user->id);
    if($user)
    {
    $profile = Yii::app()->db->createCommand()
    ->select('*')
    ->from('profile')
    ->where('username=:id ,state=:state' , array('id'=>$user->id , 'state'=>1))
    ->queryRow();
    return $profile->lastname;
    }
    }

    public function getGroupId(){
    $user = $this->loadUser(Yii::app()->user->id);
    return $user->role;
    }

    // This is a function that checks the field 'role'
    // in the User model to be equal to 1, that means it's admin
    // access it by Yii::app()->user->isAdmin()
    public function isAdmin(){
    $user = $this->loadUser(Yii::app()->user->id);

    $role = Yii::app()->db->createCommand()
    ->select('*')
    ->from('profile')
    ->where('Id=:id ,state=:state' , array('$user->role'=>1 , 'state'=>1))
    ->queryRow();
    return intval($user->role) == 1;
    }

    public function isMember(){
    $user = $this->loadUser(Yii::app()->user->id);

    return intval($user->role) == 2;
    }

    public function isGroupAAS(){
    $user = $this->loadUser(Yii::app()->user->id);
    return intval($user->role) == 1001;
    }


    // Load user model.
    protected function loadUser($id=null)
    {
    if($this->_model===null)
    {
    if($id!==null)
    $this->_model=User::model()->findByPk($id);
    }
    return $this->_model;
    }
    // كاراينتابعهمدرصورت امكان بيان كنيد و چگونه كار مي كند
    */
    protected function afterLogin($fromCookie){
    $user = $this->loadUser($this->id);
    $user->last_login_ip = Yii::app()->request->userHostAddress;
    $user->last_login_time = new CDbExpression('NOW()');
    $user->save();
    }
    */

    }
    ?>

    کد کلاس identity


    class UserIdentity extends CUserIdentity
    {

    public function authenticate()
    {
    // $pass = sha1($this->password);

    $user=user::model()->find('username=:user',array('user'=>$this->username));
    if(!$user)
    $this->errorCode=self::ERROR_USERNAME_INVALID;
    elseif($user->pass!==$this->password)
    $this->errorCode=self::ERROR_PASSWORD_INVALID;
    else
    $role=role::model()->find('Id=:Id',array('Id'=>$user->role));
    if ($role)
    {
    if ($role->Id==1)
    {
    $this->setState('username', $user->username);
    $this->setState('role', $role->name);
    // $this->setState('ip') = $_SERVER['REMOTE_ADDR'];
    //$this->setState('agent') = $_SERVER['HTTP_USER_AGENT'];
    $this->errorCode=self::ERROR_NONE;
    return !$this->errorCode;
    }
    elseif($role->Id==2)
    {
    $this->setState('username', $user->username);
    $this->setState('role', $role->name);
    //$duration=$this->rememberMe ? 3600*24*30 : 0; // 30 days
    //Yii::app()->user->login($this->_identity,$duration);
    // $this->setState('ip') = $_SERVER['REMOTE_ADDR'];
    // $this->setState('agent') = $_SERVER['HTTP_USER_AGENT'];
    $this->errorCode=self::ERROR_NONE;
    return !$this->errorCode;
    }
    }
    }
    }
    ?>

    كد خطا بعد از لاگين شدن برنامه :


    C:\xampp\htdocs\yii\framework\web\CHttpSession.php (181)
    169 {
    170 session_id($value);
    171 }
    172
    173 /**
    174 * Updates the current session id with a newly generated one .
    175 * Please refer to {@link http://php.net/session_regenerate_id} for more details.
    176 * @param boolean $deleteOldSession Whether to delete the old associated session file or not.
    177 * @since 1.1.8
    178 */
    179 public function regenerateID($deleteOldSession=false)
    180 {
    181 session_regenerate_id($deleteOldSession);
    182 }
    183
    184 /**
    185 * @return string the current session name
    186 */
    187 public function getSessionName()
    188 {
    189 return session_name();
    190 }
    191
    192 /**
    193 * @param string $value the session name for the current session, must be an alphanumeric string, defaults to PHPSESSID
    Stack Trace
    #0
    +
    C:\xampp\htdocs\yii\framework\web\CHttpSession.php (181): session_regenerate_id(true)
    #1
    +
    C:\xampp\htdocs\yii\framework\web\auth\CWebUser.ph p(715): CHttpSession->regenerateID(true)
    #2
    +
    C:\xampp\htdocs\yii\framework\web\auth\CWebUser.ph p(233): CWebUser->changeIdentity("admin", "admin", array("username" => "admin", "role" => "admin"))
    #3

    C:\xampp\htdocs\project1\protected\models\LoginFor m.php(73): CWebUser->login(UserIdentity, 0)
    68 $this->_identity->authenticate();
    69 }
    70 if($this->_identity->errorCode===UserIdentity::ERROR_NONE)
    71 {
    72 $duration=$this->rememberMe ? 3600*24*30 : 0; // 30 days
    73 Yii::app()->user->login($this->_identity,$duration);
    74 return true;
    75 }
    76 else
    77 return false;
    78 }
    #4

    C:\xampp\htdocs\project1\protected\controllers\Sit eController.php(117): LoginForm->login()
    112 // collect user input data
    113 if(isset($_POST['LoginForm']))
    114 {
    115 $model->attributes=$_POST['LoginForm'];
    116 // validate user input and redirect to the previous page if valid
    117 if($model->validate() && $model->login())
    118 $this->redirect(Yii::app()->user->returnUrl);
    119 }
    120 // display the login form
    121 $this->render('login',array('model'=>$model));
    122 }
    #5
    +
    C:\xampp\htdocs\yii\framework\web\actions\CInlineA ction.php(49): SiteController->actionLogin()
    #6
    +
    C:\xampp\htdocs\yii\framework\web\CController.php( 308): CInlineAction->runWithParams(array())
    #7
    +
    C:\xampp\htdocs\yii\framework\web\CController.php( 286): CController->runAction(CInlineAction)
    #8
    +
    C:\xampp\htdocs\yii\framework\web\CController.php( 265): CController->runActionWithFilters(CInlineAction, array())
    #9
    +
    C:\xampp\htdocs\yii\framework\web\CWebApplication. php(282): CController->run("login")
    #10
    +
    C:\xampp\htdocs\yii\framework\web\CWebApplication. php(141): CWebApplication->runController("site/login")
    #11
    +
    C:\xampp\htdocs\yii\framework\base\CApplication.ph p(180): CWebApplication->processRequest()
    #12

    C:\xampp\htdocs\project1\index.php(13): CApplication->run()
    08 defined('YII_DEBUG') or define('YII_DEBUG',true);
    09 // specify how many levels of call stack should be shown in each log message
    10 defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL',3);
    11
    12 require_once($yii);
    13 Yii::createWebApplication($config)->run();

    يك سوال ديگه هم دارم و اون در مورد Remember me next time است . وقتي اين تيك رو انتخاب مي كنم در موقع لاگين شدن خطاي زيرا مي دهد :

    C:\xampp\htdocs\yii\framework\base\CSecurityManage r.php(373)
    361 */
    362 public function generateRandomBytes($length,$cryptographicallyStro ng=true)
    363 {
    364 $bytes='';
    365 if(function_exists('openssl_random_pseudo_bytes'))
    366 {
    367 $bytes=openssl_random_pseudo_bytes($length,$strong );
    368 if($this->strlen($bytes)>=$length && ($strong || !$cryptographicallyStrong))
    369 return $this->substr($bytes,0,$length);
    370 }
    371
    372 if(function_exists('mcrypt_create_iv') &&
    373 ($bytes=mcrypt_create_iv($length, MCRYPT_DEV_URANDOM))!==false &&
    374 $this->strlen($bytes)>=$length)
    375 {
    376 return $this->substr($bytes,0,$length);
    377 }
    378
    379 if(($file=@fopen('/dev/urandom','rb'))!==false &&
    380 ($bytes=@fread($file,$length))!==false &&
    381 (fclose($file) || true) &&
    382 $this->strlen($bytes)>=$length)
    383 {
    384 return $this->substr($bytes,0,$length);
    385 }
    Stack Trace
    #0
    +
    C:\xampp\htdocs\yii\framework\base\CSecurityManage r.php(373): mcrypt_create_iv(34, 1)
    #1
    +
    C:\xampp\htdocs\yii\framework\base\CSecurityManage r.php(340): CSecurityManager->generateRandomBytes(34, true)
    #2
    +
    C:\xampp\htdocs\yii\framework\base\CSecurityManage r.php(106): CSecurityManager->generateRandomString(32, true)
    #3
    +
    C:\xampp\htdocs\yii\framework\base\CSecurityManage r.php(301): CSecurityManager->getValidationKey()
    #4
    +
    C:\xampp\htdocs\yii\framework\base\CSecurityManage r.php(261): CSecurityManager->computeHMAC("a:4:{i:0;s:5:"admin";i:1;s:5:"admin" ;i:2;i:2592000;i:3;a:2:{s:8:...", null)
    #5
    +
    C:\xampp\htdocs\yii\framework\web\auth\CWebUser.ph p(519): CSecurityManager->hashData("a:4:{i:0;s:5:"admin";i:1;s:5:"admin";i: 2;i:2592000;i:3;a:2:{s:8:...")
    #6
    +
    C:\xampp\htdocs\yii\framework\web\auth\CWebUser.ph p(238): CWebUser->saveToCookie(2592000)
    #7

    C:\xampp\htdocs\project1\protected\models\LoginFor m.php(73): CWebUser->login(UserIdentity, 2592000)
    68 $this->_identity->authenticate();
    69 }
    70 if($this->_identity->errorCode===UserIdentity::ERROR_NONE)
    71 {
    72 $duration=$this->rememberMe ? 3600*24*30 : 0; // 30 days
    73 Yii::app()->user->login($this->_identity,$duration);
    74 return true;
    75 }
    76 else
    77 return false;
    78 }
    #8

    C:\xampp\htdocs\project1\protected\controllers\Sit eController.php(117): LoginForm->login()
    112 // collect user input data
    113 if(isset($_POST['LoginForm']))
    114 {
    115 $model->attributes=$_POST['LoginForm'];
    116 // validate user input and redirect to the previous page if valid
    117 if($model->validate() && $model->login())
    118 $this->redirect(Yii::app()->user->returnUrl);
    119 }
    120 // display the login form
    121 $this->render('login',array('model'=>$model));
    122 }
    #9
    +
    C:\xampp\htdocs\yii\framework\web\actions\CInlineA ction.php(49): SiteController->actionLogin()
    #10
    +
    C:\xampp\htdocs\yii\framework\web\CController.php( 308): CInlineAction->runWithParams(array())
    #11
    +
    C:\xampp\htdocs\yii\framework\web\CController.php( 286): CController->runAction(CInlineAction)
    #12
    +
    C:\xampp\htdocs\yii\framework\web\CController.php( 265): CController->runActionWithFilters(CInlineAction, array())
    #13
    +
    C:\xampp\htdocs\yii\framework\web\CWebApplication. php(282): CController->run("login")
    #14
    +
    C:\xampp\htdocs\yii\framework\web\CWebApplication. php(141): CWebApplication->runController("site/login")
    #15
    +
    C:\xampp\htdocs\yii\framework\base\CApplication.ph p(180): CWebApplication->processRequest()
    #16

    C:\xampp\htdocs\project1\index.php(13): CApplication->run()
    08 defined('YII_DEBUG') or define('YII_DEBUG',true);
    09 // specify how many levels of call stack should be shown in each log message
    10 defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL',3);
    11
    12 require_once($yii);
    13 Yii::createWebApplication($config)->run();

    آخرین ویرایش به وسیله MMSHFE : یک شنبه 11 اسفند 1392 در 16:54 عصر دلیل: استفاده از تگهای مناسب برای نمایش صحیح کد

  2. #2

    نقل قول: مشکل کار با webuser

    والا این کدهایی که گذاشتین نیاز نبود. الآن شما اون مورد اصلی که لازم بوده رو نگذاشتین (متن خطا) و فقط Stack Trace رو گذاشتین. خطایی که توی کادر خاکستری رنگ مینویسه رو بگذارین.

  3. #3

    نقل قول: مشکل کار با webuser

    کد خطا این است
    session_regenerate_id($deleteOldSession);

  4. #4

    نقل قول: مشکل کار با webuser

    همین؟ باید یه چیزایی بیشتر گفته باشه. میتونید از صفحه خطا عکس بگیرین و اینجا بگذارین؟

  5. #5

    نقل قول: مشکل کار با webuser

    عکس کد خطا رو گذاشم :

  6. #6

    نقل قول: مشکل کار با webuser

    کجاست؟ من که عکسی نمیبینم.

  7. #7

    نقل قول: مشکل کار با webuser

    http://www.axopic.com/do.php?filename=1393937888841.rar
    آدرس عکس کد خطا.
    چرا اتج نمی شه؟

  8. #8

    نقل قول: مشکل کار با webuser

    مشکل همونی بود که حدس میزدم - مشکل معروف Cannot Modify Headers
    چک کنید همه فایلهاتون با کدگذاری UTF-8 without BOM ذخیره شده باشن. از Notepad ویندوز برای ویرایش ابداً استفاده نکنید.

  9. #9

    نقل قول: مشکل کار با webuser

    سلام
    من این کار رو با php disgner انجام دادم به این صورت :
    فعال کردن UTF-8
    و غیر فعال کردن with bom
    ولی هنوز همون خطای قبلی رو می ده

  10. #10

    نقل قول: مشکل کار با webuser

    کسی نیست جواب بده؟

  11. #11

    نقل قول: مشکل کار با webuser

    شما از unit test دارید استفاده میکنید؟
    ob_start رو بگذار ابتدای فایلی تست اتون اگرم استفاده نمیکنید بگذارید ابتدای فایلی که خطا میگیره.

  12. #12

    نقل قول: مشکل کار با webuser

    باید برای تمام فایلها انجام بدین. پیشنهاد میکنم از ++Notepad استفاده کنید و همه فایلهای اسکریپتتون رو باز کنید و از منوی Encoding گزینه Encode in UTF-8 without BOM رو انتخاب کرده و بعد Save کنید. کلاً بهتره از IDEهای خوب مثل Zend Studio و NetBeans و Aptana و امثال اونها استفاده کنید که بطور خودکار BOM رو اضافه نمیکنن.

  13. #13

    نقل قول: مشکل کار با webuser

    باید چطور از ob_start اسفاده کنم؟

  14. #14

    نقل قول: مشکل کار با webuser

    توی همه فایلهای اسکریپتتون با Ctrl+Home به اولین کارکتر رفته و کد زیر رو اضافه کنید:
    <?php ob_start(); ?>

    و با Ctrl+End به آخرین کارکتر رفته و کد زیر رو درج کنید:
    <?php ob_end_flush(); ?>

تاپیک های مشابه

  1. مشکل کار با webuser
    نوشته شده توسط MMSHFE در بخش Yii Framework
    پاسخ: 0
    آخرین پست: پنج شنبه 08 اسفند 1392, 18:55 عصر
  2. مشکل کار با منوهای فارسی که حل نشد
    نوشته شده توسط kamkam در بخش VB.NET
    پاسخ: 15
    آخرین پست: سه شنبه 07 مهر 1383, 15:23 عصر
  3. مشکل کار با پایگاه داده Access در شبکه با استفاده از ADO ؟؟؟
    نوشته شده توسط hghodsi در بخش برنامه نویسی در Delphi
    پاسخ: 2
    آخرین پست: چهارشنبه 28 مرداد 1383, 22:51 عصر

قوانین ایجاد تاپیک در تالار

  • شما نمی توانید تاپیک جدید ایجاد کنید
  • شما نمی توانید به تاپیک ها پاسخ دهید
  • شما نمی توانید ضمیمه ارسال کنید
  • شما نمی توانید پاسخ هایتان را ویرایش کنید
  •