PATH:
home
/
letacommog
/
letaweb
/
admin
/
models
/
mainsite_models
/
forms
<?php class LoginForm extends CFormModel { public $email; public $password; public $remember_me; private $_identity; protected $tokens; public function rules() { return array( array('email,password', 'required'), array('email', 'email'), array('email', 'exist', 'className' => 'User','criteria' => array('condition' => 'is_deleted=0')), array('password', 'PasswordValidator', 'className' => 'User', 'idAttribute' => 'email', 'skipOnError' => true), array('email, password, remember_me', 'safe'), ); } public function login($invation_id = false, $invation_code = false) { if ($this->validate()) { $this->_identity = new UserIdentity($this->email, $this->password); $this->_identity->authenticate(); if ($this->_identity->errorCode == UserIdentity::ERROR_NONE) { if ($this->remember_me == true) { $duration = 3600 * 24 * 30; } // 30 days else { $duration = 0; } if ($invation_id && $invation_code) { $c = new BContributor(); $c->user_id = $this->_identity->getId(); $c->save(); } Yii::app()->user->login($this->_identity, $duration); $token = $this->generateLoginToken($this->email); $login_session = User_Session::model()->find("user_id=:user_id", array(":user_id" => $this->_identity->getId())); if (!isset($login_session)) { $login_session = new User_Session; } $login_session->user_id = $this->_identity->getId(); $login_session->token = $token; $login_session->save(); return true; } elseif ($this->_identity->errorCode == UserIdentity::ERROR_USER_INACTIVE) { $this->addError('email', Yii::t('login', 'This account has not been activated. Please check your email or <a href="{link}">Recent activate mail</a>', array('{link}' => Yii::app()->createUrl('/site/resent_active_mail')))); return false; } else { $this->addError('email', Yii::t('login', $this->_identity->errorMessage)); return false; } } return false; } public function getIdentity() { return $this->_identity; } public function generateLoginToken($email) { $password = ''; $desired_length = rand(8, 12); for ($length = 0; $length < $desired_length; ++$length) { $password .= chr(rand(32, 126)); } // $token = sha512($email.time().$password); $sm = new CSecurityManager; return $sm->generateRandomString(50).$password; } public function acceptInvitation() { $this->_identity = new UserIdentity($this->email, $this->password); $this->_identity->authenticate(true); if ($this->_identity->errorCode == UserIdentity::ERROR_NONE) { if ($this->remember_me == true) { $duration = 3600 * 24 * 30; } // 30 days else { $duration = 0; } $c = new BContributor(); $c->user_id = $this->_identity->getId(); $c->save(); Yii::app()->user->login($this->_identity, $duration); return true; } else { Yii::app()->user->setFlash('loginFailed', $this->_identity->errorMessage); return false; } } }
[+]
..
[-] PageCreationForm.php
[edit]
[-] InstallForm.php
[edit]
[-] ForgotPasswordForm.php
[edit]
[-] LoginForm.php
[edit]
[-] SignupForm.php
[edit]
[-] RecoverPasswordForm.php
[edit]
[-] ResentActiveMailForm.php
[edit]
[-] PageInstallationForm.php
[edit]