diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..14bc68c
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+/nbproject/private/
\ No newline at end of file
diff --git a/README.md b/README.md
index 4fa2526..7d54592 100644
--- a/README.md
+++ b/README.md
@@ -8,8 +8,11 @@ Download or checkout (SVN/Git) from http://yii-user.2mx.org and unpack files in
Git clone
---------
-
+original clone:
clone git git@github.com:mishamx/yii-user.git
+
+modified clone(command):
+ git clone https://github.com/prawee/yii-user.git
Configure
---------
@@ -37,7 +40,7 @@ Change your config main:
'sendActivationMail' => true,
# allow access for non-activated users
- 'loginNotActiv' => false,
+ 'loginNotActive' => false,
# activate user on registration (only sendActivationMail = false)
'activeAfterRegister' => false,
diff --git a/UserModule.php b/UserModule.php
index cc624a9..b9f305f 100644
--- a/UserModule.php
+++ b/UserModule.php
@@ -38,7 +38,7 @@ class UserModule extends CWebModule
* @var boolean
* @desc allow auth for is not active user
*/
- public $loginNotActiv=false;
+ public $loginNotActive=false;
/**
* @var boolean
@@ -48,7 +48,7 @@ class UserModule extends CWebModule
/**
* @var boolean
- * @desc login after registration (need loginNotActiv or activeAfterRegister = true)
+ * @desc login after registration (need loginNotActive or activeAfterRegister = true)
*/
public $autoLogin=true;
diff --git a/components/UserIdentity.php b/components/UserIdentity.php
index 6f8986c..cea9192 100644
--- a/components/UserIdentity.php
+++ b/components/UserIdentity.php
@@ -34,7 +34,7 @@ public function authenticate()
}
else if(Yii::app()->getModule('user')->encrypting($this->password)!==$user->password)
$this->errorCode=self::ERROR_PASSWORD_INVALID;
- else if($user->status==0&&Yii::app()->getModule('user')->loginNotActiv==false)
+ else if($user->status==0&&Yii::app()->getModule('user')->loginNotActive==false)
$this->errorCode=self::ERROR_STATUS_NOTACTIV;
else if($user->status==-1)
$this->errorCode=self::ERROR_STATUS_BAN;
@@ -53,4 +53,4 @@ public function getId()
{
return $this->_id;
}
-}
\ No newline at end of file
+}
diff --git a/components/WebUser.php b/components/WebUser.php
index 4a664f6..676a506 100644
--- a/components/WebUser.php
+++ b/components/WebUser.php
@@ -48,15 +48,17 @@ protected function afterLogin($fromCookie)
public function updateSession() {
$user = Yii::app()->getModule('user')->user($this->id);
- $this->name = $user->username;
- $userAttributes = CMap::mergeArray(array(
- 'email'=>$user->email,
- 'username'=>$user->username,
- 'create_at'=>$user->create_at,
- 'lastvisit_at'=>$user->lastvisit_at,
- ),$user->profile->getAttributes());
- foreach ($userAttributes as $attrName=>$attrValue) {
- $this->setState($attrName,$attrValue);
+ if($user!==false){
+ $this->name = $user->username;
+ $userAttributes = CMap::mergeArray(array(
+ 'email'=>$user->email,
+ 'username'=>$user->username,
+ 'create_at'=>$user->create_at,
+ 'lastvisit'=>$user->lastvisit,
+ ),$user->profile->getAttributes());
+ foreach ($userAttributes as $attrName=>$attrValue) {
+ $this->setState($attrName,$attrValue);
+ }
}
}
@@ -80,4 +82,4 @@ public function isAdmin() {
return Yii::app()->getModule('user')->isAdmin();
}
-}
\ No newline at end of file
+}
diff --git a/controllers/LoginController.php b/controllers/LoginController.php
index db03de5..ecc5353 100644
--- a/controllers/LoginController.php
+++ b/controllers/LoginController.php
@@ -32,8 +32,8 @@ public function actionLogin()
private function lastViset() {
$lastVisit = User::model()->notsafe()->findByPk(Yii::app()->user->id);
- $lastVisit->lastvisit_at = date('Y-m-d H:i:s');
+ $lastVisit->lastvisit = new CDbExpression('NOW()');
$lastVisit->save();
}
-}
\ No newline at end of file
+}
diff --git a/controllers/RegistrationController.php b/controllers/RegistrationController.php
index 7890b65..3f885ce 100644
--- a/controllers/RegistrationController.php
+++ b/controllers/RegistrationController.php
@@ -54,7 +54,7 @@ public function actionRegistration() {
UserModule::sendMail($model->email,UserModule::t("You registered from {site_name}",array('{site_name}'=>Yii::app()->name)),UserModule::t("Please activate you account go to {activation_url}",array('{activation_url}'=>$activation_url)));
}
- if ((Yii::app()->controller->module->loginNotActiv||(Yii::app()->controller->module->activeAfterRegister&&Yii::app()->controller->module->sendActivationMail==false))&&Yii::app()->controller->module->autoLogin) {
+ if ((Yii::app()->controller->module->loginNotActive||(Yii::app()->controller->module->activeAfterRegister&&Yii::app()->controller->module->sendActivationMail==false))&&Yii::app()->controller->module->autoLogin) {
$identity=new UserIdentity($model->username,$soucePassword);
$identity->authenticate();
Yii::app()->user->login($identity,0);
@@ -64,7 +64,7 @@ public function actionRegistration() {
Yii::app()->user->setFlash('registration',UserModule::t("Thank you for your registration. Contact Admin to activate your account."));
} elseif(Yii::app()->controller->module->activeAfterRegister&&Yii::app()->controller->module->sendActivationMail==false) {
Yii::app()->user->setFlash('registration',UserModule::t("Thank you for your registration. Please {{login}}.",array('{{login}}'=>CHtml::link(UserModule::t('Login'),Yii::app()->controller->module->loginUrl))));
- } elseif(Yii::app()->controller->module->loginNotActiv) {
+ } elseif(Yii::app()->controller->module->loginNotActive) {
Yii::app()->user->setFlash('registration',UserModule::t("Thank you for your registration. Please check your email or login."));
} else {
Yii::app()->user->setFlash('registration',UserModule::t("Thank you for your registration. Please check your email."));
@@ -77,4 +77,4 @@ public function actionRegistration() {
$this->render('/user/registration',array('model'=>$model,'profile'=>$profile));
}
}
-}
\ No newline at end of file
+}
diff --git a/data/schema.mysql.sql b/data/schema.mysql.sql
index 607451d..ea35f8c 100644
--- a/data/schema.mysql.sql
+++ b/data/schema.mysql.sql
@@ -1,11 +1,11 @@
-CREATE TABLE `tbl_users` (
+CREATE TABLE `users` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`username` varchar(20) NOT NULL,
`password` varchar(128) NOT NULL,
`email` varchar(128) NOT NULL,
`activkey` varchar(128) NOT NULL DEFAULT '',
`create_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
- `lastvisit_at` TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00',
+ `lastvisit` TIMESTAMP NOT NULL DEFAULT '0000-00-00 00:00:00',
`superuser` int(1) NOT NULL DEFAULT '0',
`status` int(1) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
@@ -15,17 +15,17 @@ CREATE TABLE `tbl_users` (
KEY `superuser` (`superuser`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=3 ;
-CREATE TABLE `tbl_profiles` (
+CREATE TABLE `profiles` (
`user_id` int(11) NOT NULL AUTO_INCREMENT,
`lastname` varchar(50) NOT NULL DEFAULT '',
`firstname` varchar(50) NOT NULL DEFAULT '',
PRIMARY KEY (`user_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 ;
-ALTER TABLE `tbl_profiles`
- ADD CONSTRAINT `user_profile_id` FOREIGN KEY (`user_id`) REFERENCES `tbl_users` (`id`) ON DELETE CASCADE;
+ALTER TABLE `profiles`
+ ADD CONSTRAINT `profile_id` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`) ON DELETE CASCADE;
-CREATE TABLE `tbl_profiles_fields` (
+CREATE TABLE `profiles_fields` (
`id` int(10) NOT NULL AUTO_INCREMENT,
`varname` varchar(50) NOT NULL,
`title` varchar(255) NOT NULL,
@@ -47,14 +47,14 @@ CREATE TABLE `tbl_profiles_fields` (
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=3 ;
-INSERT INTO `tbl_users` (`id`, `username`, `password`, `email`, `activkey`, `superuser`, `status`) VALUES
+INSERT INTO `users` (`id`, `username`, `password`, `email`, `activkey`, `superuser`, `status`) VALUES
(1, 'admin', '21232f297a57a5a743894a0e4a801fc3', 'webmaster@example.com', '9a24eff8c15a6a141ece27eb6947da0f', 1, 1),
(2, 'demo', 'fe01ce2a7fbac8fafaed7c982a04e229', 'demo@example.com', '099f825543f7850cc038b90aaff39fac', 0, 1);
-INSERT INTO `tbl_profiles` (`user_id`, `lastname`, `firstname`) VALUES
+INSERT INTO `profiles` (`user_id`, `lastname`, `firstname`) VALUES
(1, 'Admin', 'Administrator'),
(2, 'Demo', 'Demo');
-INSERT INTO `tbl_profiles_fields` (`id`, `varname`, `title`, `field_type`, `field_size`, `field_size_min`, `required`, `match`, `range`, `error_message`, `other_validator`, `default`, `widget`, `widgetparams`, `position`, `visible`) VALUES
+INSERT INTO `profiles_fields` (`id`, `varname`, `title`, `field_type`, `field_size`, `field_size_min`, `required`, `match`, `range`, `error_message`, `other_validator`, `default`, `widget`, `widgetparams`, `position`, `visible`) VALUES
(1, 'lastname', 'Last Name', 'VARCHAR', 50, 3, 1, '', '', 'Incorrect Last Name (length between 3 and 50 characters).', '', '', '', '', 1, 3),
-(2, 'firstname', 'First Name', 'VARCHAR', 50, 3, 1, '', '', 'Incorrect First Name (length between 3 and 50 characters).', '', '', '', '', 0, 3);
\ No newline at end of file
+(2, 'firstname', 'First Name', 'VARCHAR', 50, 3, 1, '', '', 'Incorrect First Name (length between 3 and 50 characters).', '', '', '', '', 0, 3);
diff --git a/models/User.php b/models/User.php
index a245586..97dbb26 100644
--- a/models/User.php
+++ b/models/User.php
@@ -21,7 +21,7 @@ class User extends CActiveRecord
* @var integer $superuser
* @var integer $status
* @var timestamp $create_at
- * @var timestamp $lastvisit_at
+ * @var timestamp $lastvisit
*/
/**
@@ -57,11 +57,11 @@ public function rules()
array('username', 'match', 'pattern' => '/^[A-Za-z0-9_]+$/u','message' => UserModule::t("Incorrect symbols (A-z0-9).")),
array('status', 'in', 'range'=>array(self::STATUS_NOACTIVE,self::STATUS_ACTIVE,self::STATUS_BANNED)),
array('superuser', 'in', 'range'=>array(0,1)),
- array('create_at', 'default', 'value' => date('Y-m-d H:i:s'), 'setOnEmpty' => true, 'on' => 'insert'),
- array('lastvisit_at', 'default', 'value' => '0000-00-00 00:00:00', 'setOnEmpty' => true, 'on' => 'insert'),
+ array('create_at', 'default', 'value' => date('Y-m-d H:i:s'), 'setOnEmpty' => true, 'on' => 'insert'),
+ array('lastvisit', 'default', 'value' => '0000-00-00 00:00:00', 'setOnEmpty' => true, 'on' => 'insert'),
array('username, email, superuser, status', 'required'),
array('superuser, status', 'numerical', 'integerOnly'=>true),
- array('id, username, password, email, activkey, create_at, lastvisit_at, superuser, status', 'safe', 'on'=>'search'),
+ array('id, username, password, email, activkey, create_at, lastvisit, superuser, status', 'safe', 'on'=>'search'),
):((Yii::app()->user->id==$this->id)?array(
array('username, email', 'required'),
array('username', 'length', 'max'=>20, 'min' => 3,'message' => UserModule::t("Incorrect username (length between 3 and 20 characters).")),
@@ -99,7 +99,7 @@ public function attributeLabels()
'createtime' => UserModule::t("Registration date"),
'create_at' => UserModule::t("Registration date"),
- 'lastvisit_at' => UserModule::t("Last visit"),
+ 'lastvisit' => UserModule::t("Last visit"),
'superuser' => UserModule::t("Superuser"),
'status' => UserModule::t("Status"),
);
@@ -121,7 +121,7 @@ public function scopes()
'condition'=>'superuser=1',
),
'notsafe'=>array(
- 'select' => 'id, username, password, email, activkey, create_at, lastvisit_at, superuser, status',
+ 'select' => 'id, username, password, email, activkey, create_at, lastvisit, superuser, status',
),
);
}
@@ -130,7 +130,7 @@ public function defaultScope()
{
return CMap::mergeArray(Yii::app()->getModule('user')->defaultScope,array(
'alias'=>'user',
- 'select' => 'user.id, user.username, user.email, user.create_at, user.lastvisit_at, user.superuser, user.status',
+ 'select' => 'user.id, user.username, user.email, user.create_at, user.lastvisit, user.superuser, user.status',
));
}
@@ -169,7 +169,7 @@ public function search()
$criteria->compare('email',$this->email,true);
$criteria->compare('activkey',$this->activkey);
$criteria->compare('create_at',$this->create_at);
- $criteria->compare('lastvisit_at',$this->lastvisit_at);
+ $criteria->compare('lastvisit',$this->lastvisit);
$criteria->compare('superuser',$this->superuser);
$criteria->compare('status',$this->status);
@@ -190,17 +190,17 @@ public function setCreatetime($value) {
}
public function getLastvisit() {
- return strtotime($this->lastvisit_at);
+ return strtotime($this->lastvisit);
}
public function setLastvisit($value) {
- $this->lastvisit_at=date('Y-m-d H:i:s',$value);
+ $this->lastvisit=date('Y-m-d H:i:s',$value);
}
public function afterSave() {
- if (get_class(Yii::app())=='CWebApplication'&&Profile::$regMode==false) {
+ if (get_class(Yii::app())=='CWebApplication'&&Profile::$regMode==false && !Yii::app()->user->isGuest) {
Yii::app()->user->updateSession();
}
return parent::afterSave();
}
-}
\ No newline at end of file
+}
diff --git a/nbproject/project.properties b/nbproject/project.properties
new file mode 100644
index 0000000..94429c9
--- /dev/null
+++ b/nbproject/project.properties
@@ -0,0 +1,7 @@
+include.path=${php.global.include.path}
+php.version=PHP_53
+source.encoding=UTF-8
+src.dir=.
+tags.asp=false
+tags.short=true
+web.root=.
diff --git a/nbproject/project.xml b/nbproject/project.xml
new file mode 100644
index 0000000..6fddfda
--- /dev/null
+++ b/nbproject/project.xml
@@ -0,0 +1,9 @@
+
+