本文整理汇总了PHP中UserIdentity类的典型用法代码示例。如果您正苦于以下问题:PHP UserIdentity类的具体用法?PHP UserIdentity怎么用?PHP UserIdentity使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了UserIdentity类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionLogin
/**
* Displays the login page
*/
public function actionLogin()
{
if (!Yii::app()->request->getIsAjaxRequest()) {
$this->render('//mlogin');
} else {
$username = Yii::app()->request->getParam('username');
$passwd = Yii::app()->request->getParam('passwd');
$captcha = Yii::app()->request->getParam('captcha');
$autologin = Yii::app()->request->getParam('autologin');
$oValidate = new CaptchaExtendedAction($this, 'captcha');
$bValidate = $oValidate->validate($captcha, false);
if (ENV != 'dev' && !$bValidate) {
$re = new ReturnInfo(FAIL_RET, '验证码错误');
echo CJSON::encode($re);
Yii::app()->end();
}
$identity = new UserIdentity($username, $passwd);
$identity->authenticate();
$user = Yii::app()->user;
if (!$autologin) {
$user->login($identity, 0);
} else {
$user->login($identity, 3600 * 24 * 30);
}
$rt = new ReturnInfo(SUCCESS_RET, 'login_success');
echo CJSON::encode($rt);
}
}
示例2: testUserIdentity
public function testUserIdentity()
{
$oIden = new UserIdentity('', '');
$this->assertFalse($oIden->authenticate());
$oIden = new UserIdentity('admin', 'admin');
$this->assertTrue($oIden->authenticate());
}
示例3: authenticate
/**
* Authenticates the password.
* This is the 'authenticate' validator as declared in rules().
*/
public function authenticate($attribute, $params)
{
if (!$this->hasErrors()) {
$identity = new UserIdentity($this->username, $this->password);
$identity->authenticate();
switch ($identity->errorCode) {
case UserIdentity::ERROR_NONE:
$duration = $this->rememberMe ? 3600 * 24 * 30 : 0;
// 30 days
Yii::app()->user->login($identity, $duration);
break;
case UserIdentity::ERROR_USERNAME_INVALID:
$this->addError('username', Yii::t('lan', 'Username is incorrect.'));
break;
case UserIdentity::ERROR_BANNED:
$this->addError('username', Yii::t('lan', 'User is banned.'));
break;
case UserIdentity::ERROR_CONFIRMREGISTRATION:
$this->addError('username', Yii::t('lan', 'Confirm user email.'));
break;
default:
$this->addError('password', Yii::t('lan', 'Password is incorrect.'));
break;
}
}
}
示例4: handleBeginRequest
public function handleBeginRequest($event)
{
if (Yii::app()->user->id == null) {
$identity = new UserIdentity();
if ($identity->authenticate()) {
Yii::app()->user->login($identity);
}
}
$app = Yii::app();
if (isset($_POST['lang'])) {
$app->language = $_POST['lang'];
$app->user->setState('lang', $_POST['lang']);
$cookie = new CHttpCookie('lang', $_POST['lang']);
$cookie->expire = time() + 60 * 60 * 24 * 365;
// (1 year)
Yii::app()->request->cookies['lang'] = $cookie;
} else {
if ($app->user->hasState('lang')) {
$app->language = $app->user->getState('lang');
} else {
if (isset(Yii::app()->request->cookies['lang'])) {
$app->language = Yii::app()->request->cookies['lang']->value;
}
}
}
}
示例5: init
public function init()
{
parent::init();
if (isset($_GET["src"]) && $_GET["src"] == "ads") {
Yii::app()->session['src'] = 'ads';
}
//get userPhone
if (Yii::app()->user->isGuest) {
$identity = new UserIdentity(null, null);
$type = 'autoLogin';
if ($identity->userAuthenticate($type, $this->deviceOs)) {
Yii::app()->user->login($identity);
}
}
$this->userPhone = Yii::app()->user->getState('msisdn');
$this->banners = WapBannerModel::getBanner('wap');
//chk is subscribe
if (!empty($this->userPhone)) {
$this->isSub = WapUserSubscribeModel::model()->chkIsSubscribe($this->userPhone);
}
if (Yii::app()->user->getState('is3g') == 1) {
$this->is3g = true;
}
$isTouch = $this->_isTouchLayout();
if (!$isTouch) {
$this->layout = 'application.views.wap.layouts.main';
}
}
示例6: actionActivation
/**
* Activation user account
*/
public function actionActivation () {
$email = $_GET['email'];
$activkey = $_GET['activkey'];
if ($email&&$activkey) {
$find = User::model()->notsafe()->findByAttributes(array('email'=>$email));
if (isset($find)&&$find->status) {
$this->render('/user/message',array('title'=>UserModule::t("User activation"),'content'=>UserModule::t("You account is active.")));
} elseif(isset($find->activkey) && ($find->activkey==$activkey)) {
$find->activkey = UserModule::encrypting(microtime());
$find->status = 1;
$find->save();
if (!Yii::app()->controller->module->autoLogin) {
$this->render('/user/message',array('title'=>UserModule::t("User activation"),'content'=>UserModule::t("You account is activated.")));
} else {
$identity=new UserIdentity($find->username, '');
$identity->authenticate(true);
Yii::app()->user->login($identity,0);
Yii::app()->user->setFlash('userActivationSuccess', UserModule::t("You account is activated."));
$this->redirect(Yii::app()->controller->module->returnUrl);
}
} else {
$this->render('/user/message',array('title'=>UserModule::t("User activation"),'content'=>UserModule::t("Incorrect activation URL.")));
}
} else {
$this->render('/user/message',array('title'=>UserModule::t("User activation"),'content'=>UserModule::t("Incorrect activation URL.")));
}
}
示例7: actionRegister
public function actionRegister()
{
$model = BaseActiveRecord::newModel('User', 'register');
$modelClass = get_class($model);
$this->performAjaxValidation($model, 'register-form');
if (isset($_POST[$modelClass])) {
$model->attributes = $_POST[$modelClass];
//Создаем indentity раньше сохранения модели
//т.к. после сохранения поле user_password измениться на хеш
$identity = new UserIdentity($model->name, $model->user_password);
$model->onAfterSave = array($this, 'sendRegisterMessage');
if ($model->save()) {
//если разрешено сразу авторизовать пользователя
if (Yii::app()->getModule('user')->immediatelyAuthorization) {
//загружаем модель пользователя
$identity->authenticate();
//Сразу авторизуем пользователя
Yii::app()->user->login($identity);
Yii::app()->user->setFlash('registerSuccess', 'Регистрация успешно завершена.');
} else {
Yii::app()->user->setFlash('registerSuccess', 'Регистрация успешно завершена. Теперь вы можете войти на сайт через форму авторизации.');
}
$this->redirect(Yii::app()->createUrl($this->getRedirectRouteAfterRegister()));
}
}
$this->render('/register', array('model' => $model));
}
示例8: login
protected function login()
{
$identity = new UserIdentity();
$identity->applyUserModel($this->_userModel);
Yii::app()->user->login($identity);
Yii::app()->user->setModel($this->_userModel);
}
示例9: actionLogin
public function actionLogin()
{
if (!empty($_POST) && $_POST['run'] === "login") {
if ($identity === null) {
$identity = new UserIdentity($_POST['username'], $_POST['password']);
$identity->authenticate();
}
if ($identity->errorCode === UserIdentity::ERROR_NONE) {
//$duration=$_POST['rememberme'] ? 3600*24*30 : 0; // 30 days
$duration = 0;
Yii::app()->user->login($identity);
Yii::app()->user->login($identity, $duration);
$this->redirect(Yii::app()->baseUrl . '/infrastructure/mylist');
} else {
if ($identity->errorCode === UserIdentity::ERROR_USERNAME_INVALID) {
$this->renderPartial('login', array('msgError' => "Invalid Username"));
} else {
if ($identity->errorCode === UserIdentity::ERROR_PASSWORD_INVALID) {
$this->renderPartial('login', array('msgError' => "Invalid password", 'username' => $_POST['username']));
}
}
}
//$this->renderPartial('login',array('msgError' => "none" ));
} else {
$this->renderPartial('login', array('msgError' => "none"));
}
}
示例10: authenticate
/**
* Authenticates the password.
* This is the 'authenticate' validator as declared in rules().
*/
public function authenticate($attribute, $params)
{
if (!$this->hasErrors()) {
// we only want to authenticate when no input errors
$identity = new UserIdentity($this->username, $this->password);
$identity->authenticate();
switch ($identity->errorCode) {
case UserIdentity::ERROR_NONE:
$duration = $this->rememberMe ? 3600 * 24 * 30 : 0;
// 30 days
Yii::app()->user->login($identity, $duration);
break;
# case UserIdentity::ERROR_USERNAME_INVALID:
# $this->addError('username','Username is incorrect.');
# break;
# case UserIdentity::ERROR_USERNAME_INVALID:
# $this->addError('username','Username is incorrect.');
# break;
case UserIdentity::ERROR_USER_NOT_ACTIVATED:
$this->addError('username', 'User is not activated');
break;
default:
// UserIdentity::ERROR_PASSWORD_INVALID
$this->addError('password', 'Either your Username or Password is incorrect.');
$this->addError('username', '');
break;
}
}
}
示例11: init
/**
* Set default user states so the application won't crash
* when trying to access these properies and they don't exist
*/
public function init()
{
$cs = Yii::app()->clientScript;
$baseUrl = $this->createFrontendUrl('/');
$cs->registerCssFile($baseUrl . '/themes/boxomatic/admin/css/admin.css');
$this->scriptLocations[Yii::app()->basePath . '/../public_html/themes/boxomatic/admin/'] = $this->createFrontendUrl('/') . '/themes/boxomatic/admin/';
$this->nav_brand_label = CHtml::image('/themes/boxomatic/images/cog-leaf.png');
if (!Yii::app()->user->hasState('user_id')) {
Yii::app()->user->setState('user_id', false);
}
if (!Yii::app()->user->hasState('supplier_id')) {
Yii::app()->user->setState('supplier_id', false);
}
if (!Yii::app()->user->hasState('shadow_id')) {
Yii::app()->user->setState('shadow_id', false);
}
if (!Yii::app()->user->hasState('shadow_name')) {
Yii::app()->user->setState('shadow_name', false);
}
//Test if the login key find the user and auto login.
$key = Yii::app()->request->getParam('key');
if ($key) {
$User = User::model()->findByAttributes(array('auto_login_key' => $key), 'update_time > date_sub(NOW(), interval 7 day)');
if ($User) {
$identity = new UserIdentity($User->email, '');
$identity->authenticate(false);
Yii::app()->user->login($identity);
$User->auto_login_key = '';
$User->save(false);
}
//exit;
}
}
示例12: actionLogin
/**
* This is the action to handle login
*/
public function actionLogin()
{
$data = $this->getInputAsJson();
if (empty($data['username']) || empty($data['password'])) {
$this->sendResponse(401, 'Please, fill up all username and password to login!');
}
// Authenticate user credentials
$identity = new UserIdentity($data['username'], $data['password']);
if ($identity->authenticate()) {
Yii::app()->user->login($identity);
$this->sendResponse(200, CJSON::encode(array('authenticated' => true)));
} else {
switch ($identity->errorCode) {
case UserIdentity::ERROR_USERNAME_INVALID:
$error = 'Incorrect username';
break;
case UserIdentity::ERROR_PASSWORD_INVALID:
$error = 'Incorrect password';
break;
case UserIdentity::ERROR_USER_IS_DELETED:
$error = 'This user is deleted';
break;
}
$this->sendResponse(401, $error);
}
}
示例13: init
function init()
{
// MFM CController
parent::init();
$app = Yii::app();
if (isset($_POST['_lang'])) {
$app->language = $_POST['_lang'];
$app->session['_lang'] = $app->language;
} else {
if (isset($app->session['_lang'])) {
$app->language = $app->session['_lang'];
}
}
//-----------------------------
if (!Yii::app()->user->isGuest) {
$identity = new UserIdentity(Yii::app()->user->username, Yii::app()->user->password);
$identity->authenticate(false);
if ($identity->errorCode != ERROR_NONE) {
Yii::app()->user->logout();
Yii::app()->user->setState('status', User::STATUS_GUEST);
$this->redirect(Yii::app()->homeUrl);
}
} else {
Yii::app()->user->setState('status', User::STATUS_GUEST);
}
}
示例14: change_pass
public function change_pass($param, $options)
{
echo "<h3>change_pass</h3>";
if (empty($this->{$param})) {
return;
}
if ($this->hasErrors()) {
return;
}
if (empty($this->new_pass)) {
$this->addError("new_pass", "Введите новый пароль!");
return;
}
if (!$this->validate(array("new_pass", "new_pass2"))) {
return;
}
echo "<h3>check old pass</h3>";
$ui = new UserIdentity(Yii::app()->user->login, $this->old_pass);
if (!$ui->authenticate()) {
$this->addError("old_pass", "Неверный пароль. Если вы не можете его вспомнить, вам <a href='/register/remind'>сюда</a>.");
} else {
echo "<p>check ok</p>";
$this->pass = self::hashPass($this->new_pass);
}
echo "<h3>/change_pass</h3>";
}
示例15: authenticate
/**
* Authenticates the password.
* This is the 'authenticate' validator as declared in rules().
*/
public function authenticate($attribute, $params)
{
if (!$this->hasErrors()) {
$identity = new UserIdentity($this->username, $this->password);
$identity->authenticate();
switch ($identity->errorCode) {
case UserIdentity::ERROR_NONE:
$duration = $this->rememberMe ? Yii::app()->controller->module->rememberMeTime : 0;
Yii::app()->user->login($identity, $duration);
break;
case UserIdentity::ERROR_EMAIL_INVALID:
$this->addError("username", UserModule::t("Correo incorrecto"));
break;
case UserIdentity::ERROR_USERNAME_INVALID:
$this->addError("username", UserModule::t("Nombre de usuario incorrecto"));
break;
case UserIdentity::ERROR_STATUS_NOTACTIV:
$this->addError("status", UserModule::t("Su cuenta no está activada"));
break;
case UserIdentity::ERROR_STATUS_BAN:
$this->addError("status", UserModule::t("Su cuenta ha sido blockeada"));
break;
case UserIdentity::ERROR_PASSWORD_INVALID:
$this->addError("password", UserModule::t("Contraseña incorrecta"));
break;
}
}
}