data/0000777000076400007640000000000011220252626011661 5ustar sakuraisakuraidata/test.db0000666000076400007640000000600011220252626013143 0ustar sakuraisakuraiSQLite format 3@  P++Ytablesqlite_sequencesqlite_sequenceCREATE TABLE sqlite_sequence(name,seq)k9tableUserUserCREATE TABLE User ( id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, username VARCHAR(128) NOT NULL, password VARCHAR(128) NOT NULL, email VARCHAR(128) NOT NULL, profile TEXT )  Userdata/sql0000664000076400007640000000052111220123767012402 0ustar sakuraisakuraiBEGIN TRANSACTION; DROP TABLE User; DELETE FROM sqlite_sequence; INSERT INTO "sqlite_sequence" VALUES('User',0); CREATE TABLE User ( id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, username VARCHAR(128) NOT NULL, password VARCHAR(128) NOT NULL, email VARCHAR(128) NOT NULL, profile TEXT ); COMMIT; modules/0000775000076400007640000000000011220252512012410 5ustar sakuraisakuraimodules/simpleLogin/0000775000076400007640000000000011220252333014673 5ustar sakuraisakuraimodules/simpleLogin/models/0000775000076400007640000000000011220252333016156 5ustar sakuraisakuraimodules/simpleLogin/models/MLoginForm.php0000664000076400007640000000355411220252333020707 0ustar sakuraisakurai'login, register'), array('passwordRepeat, email, profile', 'required', 'on'=>'register'), // password needs to be authenticated array('password', 'authenticate', 'on'=>'login'), array('passwordRepeat', 'compare', 'compareAttribute'=>'password', 'on'=>'register'), array('email', 'email'), ); } /** * Declares attribute labels. */ public function attributeLabels() { return array( 'rememberMe'=>'Remember me next time', ); } /** * 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 MUserIdentity($this->username,$this->password); $identity->authenticate(); switch($this->errorCode = $identity->errorCode) { case MUserIdentity::ERROR_NONE: $duration=$this->rememberMe ? 3600*24*30 : 0; // 30 days Yii::app()->user->login($identity,$duration); break; case MUserIdentity::USER_TO_BE_REGISTERED: break; default: // UserIdentity::ERROR_PASSWORD_INVALID $this->addError('password','Password is incorrect.'); break; } } } } modules/simpleLogin/models/MUser.php0000664000076400007640000000153311220252333017724 0ustar sakuraisakurai128), array('password','length','max'=>128), array('email','length','max'=>128), array('username, password, email', 'required'), ); } }modules/simpleLogin/views/0000775000076400007640000000000011220252333016030 5ustar sakuraisakuraimodules/simpleLogin/views/default/0000775000076400007640000000000011220252512017453 5ustar sakuraisakuraimodules/simpleLogin/views/default/login.php0000664000076400007640000000246311220252200021273 0ustar sakuraisakuraipageTitle=Yii::app()->name . ' - Login'; ?>

Login

Register

You will be registered if you have not been registered yet.

10, 'cols'=>30)); ?>

modules/simpleLogin/views/default/index.php0000664000076400007640000000043211220252333021273 0ustar sakuraisakurai

This is the view content for action "action->id; ?>". The action belongs to the controller "" in the "module->id; ?>" module.

You may customize this page by editing

modules/simpleLogin/views/layouts/0000775000076400007640000000000011220252333017530 5ustar sakuraisakuraimodules/simpleLogin/views/layouts/.yii0000664000076400007640000000000011220252333020311 0ustar sakuraisakuraimodules/simpleLogin/components/0000775000076400007640000000000011220252333017060 5ustar sakuraisakuraimodules/simpleLogin/components/MUserIdentity.php0000664000076400007640000000213611220252333022340 0ustar sakuraisakuraifind('LOWER(username)=?',array(strtolower($this->username))); if($user===null) { // not exist in db $this->errorCode=self::USER_TO_BE_REGISTERED; } else if(md5($this->password)!==$user->password) { // password check $this->errorCode=self::ERROR_PASSWORD_INVALID; } else { // no error $this->_id=$user->id; $this->username=$user->username; $this->errorCode=self::ERROR_NONE; } return !$this->errorCode; } /** * @return integer the ID of the user record */ public function getId() { return $this->_id; } }modules/simpleLogin/SimpleLoginModule.php0000664000076400007640000000121411220252333020772 0ustar sakuraisakuraisetImport(array( 'simpleLogin.models.*', 'simpleLogin.components.*', )); } public function beforeControllerAction($controller, $action) { if(parent::beforeControllerAction($controller, $action)) { // this method is called before any module controller action is performed // you may place customized code here return true; } else return false; } } modules/simpleLogin/controllers/0000775000076400007640000000000011220252333017241 5ustar sakuraisakuraimodules/simpleLogin/controllers/DefaultController.php0000664000076400007640000000333211220252333023403 0ustar sakuraisakuraiarray( 'class'=>'CCaptchaAction', 'backColor'=>0xEBF4FB, ), ); } /** * Displays the login page */ public function actionIndex() { $form=new MLoginForm; // collect user input data if(isset($_POST['MLoginForm'])) { $form->attributes=$_POST['MLoginForm']; if (!isset($_POST['MLoginForm']['passwordRepeat'])) { // login mode if($form->validate('login') && !$form->errorCode) { $this->redirect(Yii::app()->homeUrl); } else if ($form->errorCode == MUserIdentity::USER_TO_BE_REGISTERED) { $this->state = self::REGISTRATION_STATE; } } else { // register mode if ($form->validate('register')) { $duration=$form->rememberMe ? 3600*24*30 : 0; // 30 days $user = new MUser; $user->attributes = $form->attributes; $user->password = md5($user->password); $user->save(); $identity = new MUserIdentity($form->username,$form->password); $identity->authenticate(); Yii::app()->user->login($identity, $duration); $this->redirect(Yii::app()->homeUrl); } else { $this->state = self::REGISTRATION_STATE; } } } // display the login form $this->render('login', array('form'=>$form, 'state'=>$this->state)); } /** * Logout the current user and redirect to homepage. */ public function actionLogout() { Yii::app()->user->logout(); $this->redirect(Yii::app()->homeUrl); } }