Код: Выделить всё
'session' => array(
'timeout' => 60,
),
Код: Выделить всё
'session' => array(
'timeout' => 60,
),
Код: Выделить всё
$duration = $this->rememberMe ? 3600 * 24 * 7 : 0; // 7 days
Yii::app()->user->login( $this->_identity, $duration );
Код: Выделить всё
class LoginForm extends CFormModel
{
public $email;
public $password;
public $rememberMe;
public $verifyCode;
private $_identity;
public function actions()
{
return array(
'captcha' => array(
'class' => 'CCaptchaAction',
'transparent' => true,
),
);
}
/**
* Declares the validation rules.
* The rules state that username and password are required,
* and password needs to be authenticated.
*/
public function rules()
{
return array(
// username and password are required
array( 'email, password', 'required' ),
// rememberMe needs to be a boolean
array( 'rememberMe', 'boolean' ),
// password needs to be authenticated
array( 'password', 'authenticate' ),
array( 'verifyCode', 'captcha' ),
);
}
/**
* Declares attribute labels.
*/
public function attributeLabels()
{
return array(
'rememberMe' => 'Remember me next time',
'verifyCode' => Yii::t( 'site', 'Verify code' ),
);
}
/**
* Authenticates the password.
* This is the 'authenticate' validator as declared in rules().
*/
public function authenticate( $attribute, $params )
{
if ( !$this->hasErrors() ) {
$this->_identity = new UserIdentity( $this->email, $this->password );
if ( !$this->_identity->authenticate() ) {
$this->addError( 'password', 'Incorrect username or password' );
$this->addError( 'email', ' ' );
}
}
}
/**
* Logs in the user using the given username and password in the model.
* @return boolean whether login is successful
*/
public function login()
{
if ( $this->_identity === null ) {
$this->_identity = new UserIdentity( $this->email, $this->password );
$this->_identity->authenticate();
}
if ( $this->_identity->errorCode === UserIdentity::ERROR_NONE ) {
$duration = $this->rememberMe ? 3600 * 24 * 7 : 0; // 7 days
Yii::app()->user->login( $this->_identity, $duration );
return true;
} else {
return false;
}
}
}
Код: Выделить всё
class UserIdentity extends CUserIdentity
{
public $_id;
public function authenticate()
{
$user = User::model()->find( 'LOWER(email)=?', array( $this->username ) );
if ( $user === null ) {
$this->errorCode = self::ERROR_USERNAME_INVALID;
} else if ( !$user->validatePassword( $this->password ) ) {
$this->errorCode = self::ERROR_PASSWORD_INVALID;
} else {
$this->_id = $user->userid;
$this->username = $user->email;
( $user->isAdmin ? $this->setState( 'isAdmin', true ) : $this->setState( 'isAdmin', false ) );
$this->errorCode = self::ERROR_NONE;
}
return !$this->errorCode;
}
public function getId()
{
return $this->_id;
}
}
Код: Выделить всё
return array(
'sourceLanguage' => 'en',
'language' => 'en',
'basePath' => dirname( __FILE__ ) . DIRECTORY_SEPARATOR . '..',
'name' => 'My Web Application',
// preloading 'log' component
'preload' => array( 'log' ),
// autoloading model and component classes
'import' => array(
'application.models.*',
'application.components.*',
'ext.shoppingCart.*',
),
'aliases' => array(
//assuming you extracted the files to the extensions folder
'xupload' => 'ext.xupload'
),
'modules' => array(
// uncomment the following to enable the Gii tool
'gii' => array(
'class' => 'system.gii.GiiModule',
'password' => 'vp3whbjvp8',
// If removed, Gii defaults to localhost only. Edit carefully to taste.
'ipFilters' => array( '127.0.0.1', '::1' ),
'generatorPaths' => array(
'application.gii' //nested set Model and Crud templates
),
),
'admin',
'pm' => array(
'userClass' => 'User', //Класс, представляющий модель пользователя
'getNameMethod' => 'getName', // имя метода для модели пользователя, возвращающего имя пользователя.
'getUserIdExpression' => 'Yii::app()->user->id', // выражение, возвращающее id текущего пользователя в приложении.
'tableName' => 'pm', // имя таблицы с персональными сообщениями
'reallyDelete' => true, // удалять сообщения из базы
'outgoingPageSize' => 10, // отправленных сообщений на страницу
'incomingPageSize' => 10, // принятых сообщений на страницу
'conversationMode' => false, // использовать беседы при переписке
'defaultController' => 'message', // назначаем базовый контроллер
)
),
// application components
'components' => array(
'email' => array(
'class' => 'application.extensions.email.Email',
'delivery' => 'php', //Will use the php mailing function.
//May also be set to 'debug' to instead dump the contents of the email into the view
),
'user' => array(
'loginUrl' => array( 'user/login' ),
// enable cookie-based authentication
'allowAutoLogin' => true,
),
'shoppingCart' => array(
'class' => 'ext.shoppingCart.EShoppingCart',
),
'simpleImage' => array(
'class' => 'ext.resizeImage.CSimpleImage'
),
// uncomment the following to enable URLs in path-format
'urlManager' => array(
'class' => 'application.extensions.urlManager.LangUrlManager',
'languages' => array( 'en', 'it', 'fr', 'es', 'de', 'ru' ),
'langParam' => 'lang',
'urlFormat' => 'path',
//'urlSuffix' => '.html',
'showScriptName' => false,
'rules' => array(
/* Specific rules */
'<lang:[a-z]{2}>/<alias:(about)>' => 'site/pages',
'<lang:[a-z]{2}>/contact' => 'site/contact',
'<lang:[a-z]{2}>/info' => 'site/info',
'<lang:[a-z]{2}>/catalog/*' => 'category/index',
'<lang:[a-z]{2}>/product/<id:\d+>/*' => 'products/view',
/* Index page */
'<lang:[a-z]{2}>' => 'site/index',
/* Basic rules */
'<lang:[a-z]{2}>/<_c>' => '<_c>',
'<lang:[a-z]{2}>/<_c>/<_a>/<id:\d+>/*' => '<_c>/<_a>',
'<lang:[a-z]{2}>/<_m>/<_c>' => '<_m>/<_c>',
'<lang:[a-z]{2}>/<_m>/<_c>/<_a>/*' => '<_m>/<_c>/<_a>',
'<lang:[a-z]{2}>/<_m>/<_a>' => '<_m>/<_a>',
),
),
/*'db' => array(
'connectionString' => 'sqlite:' . dirname( __FILE__ ) . '/../data/testdrive.db',
),*/
// uncomment the following to use a MySQL database
'db' => array(
'connectionString' => 'mysql:host=localhost;dbname=farmasite',
'emulatePrepare' => true,
'username' => 'root',
'password' => '',
'charset' => 'utf8',
// включаем профайлер
'enableProfiling' => true,
// показываем значения параметров
'enableParamLogging' => true,
),
'errorHandler' => array(
// use 'site/error' action to display errors
'errorAction' => 'site/error',
),
'log' => array(
'class' => 'CLogRouter',
'routes' => array(
array(
// направляем результаты профайлинга в ProfileLogRoute (отображается
// внизу страницы)
'class' => 'CProfileLogRoute',
'levels' => 'profile',
'enabled' => true,
),
// 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' => 'boiler0303@gmail.com',
),
);
Нет, кеширования страниц нет, все в принципе по дефолту.Sam Dark писал(а):И на основе чего он логинится, если куки нет и браузер переоткрыли? У вас случаем кеша постраничного нет?
Да, действительно, проблема в Google Chrome, в FireFox после закрытия браузера всё хорошо... Я так понимаю нужно реализовать свой механизм авторизации ? или может есть другие способы решения проблемы с помощью yii ?Sam Dark писал(а):Expires = Session на скрине. То есть обязано удалиться по закрытию браузера. Если этого не происходит, виноват браузер.
Код: Выделить всё
$duration = $this->rememberMe ? 3600 * 24 * 7 : 0; // 7 days
Yii::app()->user->login( $this->_identity, $duration );