public function testInvalidPassword()
 {
     $invalidTest = array('user_id' => 1, 'username' => 'mwatney', 'password' => 'in`v4l1dP@ssW0rd!');
     $invalidUser = new User($invalidTest);
     $this->assertEquals(1, $invalidUser->getErrorCount(), 'The User object should have exactly 1 error');
     $this->assertTrue(!empty($invalidUser->getError('password')), 'The User should have a password error');
 }
Example #2
0
 public function actionIndex()
 {
     if (Yii::app()->user->isGuest) {
         if (Yii::app()->request->isPostRequest && isset($_POST["login"])) {
             $user = new User("login");
             $user->setAttributes($_POST["login"]);
             $user->remember = true;
             if ($user->login()) {
                 $this->redirect("/");
             } else {
                 Yii::app()->user->setFlash("error", $user->getError("pass"));
             }
         }
         if (p()['registerType'] == "INVITE") {
             $this->layout = "empty";
             $this->render("index_guest");
             return;
         }
     }
     $this->layout = "column1";
     $hot_key = sprintf("hot.%d.%d.%d", Yii::app()->user->ini["hot.s_lang"], Yii::app()->user->ini["hot.t_lang"], Yii::app()->user->ini["hot.img"]);
     if (!($hot = Yii::app()->cache->get($hot_key))) {
         $C = new CDbCriteria(array("condition" => "t.ac_read = 'a'", "order" => "t.last_tr DESC NULLS LAST"));
         $C->limit = Yii::app()->user->ini["hot.img"] ? 12 : 36;
         if (Yii::app()->user->ini["hot.s_lang"]) {
             $C->addCondition("t.s_lang = " . Yii::app()->user->ini["hot.s_lang"]);
         }
         if (Yii::app()->user->ini["hot.t_lang"]) {
             $C->addCondition("t.t_lang = " . Yii::app()->user->ini["hot.t_lang"]);
         }
         $hot = Book::model()->findAll($C);
         Yii::app()->cache->set($hot_key, $hot, 60);
     }
     if (!($announces = Yii::app()->cache->get("announces"))) {
         $announces = Announce::model()->with("book.cat", "book.owner", "seen")->findAll(array("condition" => "t.topics BETWEEN 80 AND 89 AND book.ac_read = 'a'", "order" => "t.cdate desc", "limit" => 5));
         Yii::app()->cache->set("announces", $announces, 90);
     }
     if (!($blog = Yii::app()->cache->get("blog"))) {
         $blog = BlogPost::model()->common()->findAll(["limit" => 10]);
         Yii::app()->cache->set("blog", $blog, 105);
     }
     $this->render('index', array("hot" => $hot, "searchTop" => $this->getSearchTop(), "announces" => $announces, "blog" => $blog));
 }
Example #3
0
 public function save()
 {
     if ($this->lid) {
         $model = User::model()->find('lid=:id', array(':id' => $this->lid));
     } else {
         $model = new User();
         $se = new Sequence("user");
         $model->lid = $se->nextval();
         $model->create_at = date('Y-m-d H:i:s', time());
         $model->delete_flag = '0';
         //$model->lid = $this->getPkValue();
     }
     $model->username = $this->username;
     $model->mobile = $this->mobile;
     $model->staff_no = $this->staff_no;
     $model->email = $this->email;
     $model->role = $this->role;
     $model->dpid = $this->dpid;
     $model->status = 1;
     if ($this->password_old != $this->password) {
         $model->password_hash = $this->password;
     }
     if ($model->validate()) {
         if ($this->password_old != $this->password) {
             $model->password_hash = Helper::genPassword($this->password);
         }
         //var_dump($model);exit;
         $model->save();
         return true;
     } else {
         $this->addErrors($model->getErrors());
         if ($passwordError = $model->getError('password_hash')) {
             $this->addError('password', $passwordError);
         }
         return false;
     }
 }
 public function do_login()
 {
     $ip = Loader::helper('validation/ip');
     $vs = Loader::helper('validation/strings');
     $loginData['success'] = 0;
     try {
         if (!$ip->check()) {
             throw new Exception($ip->getErrorMessage());
         }
         if (OpenIDAuth::isEnabled() && $vs->notempty($this->post('uOpenID'))) {
             $oa = new OpenIDAuth();
             $oa->setReturnURL($this->openIDReturnTo);
             $return = $oa->request($this->post('uOpenID'));
             $resp = $oa->getResponse();
             if ($resp->code == OpenIDAuth::E_INVALID_OPENID) {
                 throw new Exception(t('Invalid OpenID.'));
             }
         }
         if (!$vs->notempty($this->post('uName')) || !$vs->notempty($this->post('uPassword'))) {
             if (USER_REGISTRATION_WITH_EMAIL_ADDRESS) {
                 throw new Exception(t('An email address and password are required.'));
             } else {
                 throw new Exception(t('A username and password are required.'));
             }
         }
         $u = new User($this->post('uName'), $this->post('uPassword'));
         if ($u->isError()) {
             switch ($u->getError()) {
                 case USER_NON_VALIDATED:
                     throw new Exception(t('This account has not yet been validated. Please check the email associated with this account and follow the link it contains.'));
                     break;
                 case USER_INVALID:
                     if (USER_REGISTRATION_WITH_EMAIL_ADDRESS) {
                         throw new Exception(t('Invalid email address or password.'));
                     } else {
                         throw new Exception(t('Invalid username or password.'));
                     }
                     break;
                 case USER_INACTIVE:
                     throw new Exception(t('This user is inactive. Please contact us regarding this account.'));
                     break;
             }
         } else {
             if (OpenIDAuth::isEnabled() && $_SESSION['uOpenIDExistingUser'] > 0) {
                 $oa = new OpenIDAuth();
                 if ($_SESSION['uOpenIDExistingUser'] == $u->getUserID()) {
                     // the account we logged in with is the same as the existing user from the open id. that means
                     // we link the account to open id and keep the user logged in.
                     $oa->linkUser($_SESSION['uOpenIDRequested'], $u);
                 } else {
                     // The user HAS logged in. But the account they logged into is NOT the same as the one
                     // that links to their OpenID. So we log them out and tell them so.
                     $u->logout();
                     throw new Exception(t('This account does not match the email address provided.'));
                 }
             }
             $loginData['success'] = 1;
             $loginData['msg'] = t('Login Successful');
             $loginData['uID'] = intval($u->getUserID());
         }
         $loginData = $this->finishLogin($loginData);
     } catch (Exception $e) {
         $ip->logSignupRequest();
         if ($ip->signupRequestThreshholdReached()) {
             $ip->createIPBan();
         }
         $this->error->add($e);
         $loginData['error'] = $e->getMessage();
     }
     if ($_REQUEST['format'] == 'JSON') {
         $jsonHelper = Loader::helper('json');
         echo $jsonHelper->encode($loginData);
         die;
     }
 }
Example #5
0
<h2>It should create a valid User object when all input is provided</h2>
<?php 
$validTest = array("userName" => "krobbins", "password" => "123");
$s1 = new User($validTest);
echo "The object is: {$s1}<br>";
$test1 = is_object($s1) ? '' : 'Failed:It should create a valid object when valid input is provided<br>';
echo $test1;
$test2 = empty($s1->getErrors()) ? '' : 'Failed:It not have errors when valid input is provided<br>';
echo $test2;
?>

<h2>It should extract the parameters that went in</h2>
<?php 
$props = $s1->getParameters();
print_r($props);
?>

<h2>It should have an error when the user name contains invalid characters</h2>
<?php 
$invalidTest = array("userName" => "krobbins\$");
$s1 = new User($invalidTest);
$test2 = empty($s1->getErrors()) ? '' : 'Failed:It should have errors when invalid input is provided<br>';
echo $test2;
echo "The error for userName is: " . $s1->getError('userName') . "<br>";
echo "The error for password is: " . $s1->getError('password') . "<br>";
echo "The object is: {$s1}<br>";
?>
</body>
</html>
Example #6
0
<?php 
include_once "../models/User.class.php";
?>

<h2>It should create an error when the last name is empty or has characters that are not alphanumeric or '-' and '_'</h2>
<?php 
$validTest = array("lastName" => "rroseman");
$s1 = new User($validTest);
echo "The object is: {$s1}<br>";
$test1 = empty($s1->getErrors()) ? '' : 'Failed:It should create a valid object when valid input is provided<br>';
echo $test1;
?>

<h2>It should extract the parameters that went in</h2>
<?php 
$props = $s1->getParameters();
print_r($props);
?>

<h2>It should have an error when the user name contains invalid characters</h2>
<?php 
$invalidTest = array("userName" => "krobbins\$");
$s1 = new User($invalidTest);
$test2 = empty($s1->getErrors()) ? '' : 'Failed:It should have errors when invalid input is provided<br>';
echo $test2;
echo "The error for userName is: " . $s1->getError('userName') . "<br>";
echo "The object is: {$s1}<br>";
?>
</body>
</html>
echo $test2;
?>

<h2>It should extract the parameters that went in</h2>
<?php 
$props = $s1->getParameters();
print_r($props);
?>

<h2>It should have an error when the email is invalid</h2>
<?php 
$invalidEmailTest = array("email" => "invalid@@email.com", "password" => "validpassword");
$s1 = new User($invalidEmailTest);
$test2 = empty($s1->getErrors()) ? '' : 'Failed:It should have errors when invalid input is provided<br>';
echo $test2;
echo "The error for email is: " . $s1->getError('email') . "<br>";
echo "The object is: {$s1}<br>";
?>

<h2>It should have an error when the password contains too few characters</h2>
<?php 
$shortPasswordTest = array("email" => "*****@*****.**", "password" => "fail");
$s1 = new User($shortPasswordTest);
$test2 = empty($s1->getErrors()) ? '' : 'Failed:It should have errors when invalid input is provided<br>';
echo $test2;
echo "The error for password is: " . $s1->getError('password') . "<br>";
echo "The object is: {$s1}<br>";
?>
</body>
</html>
Example #8
0
 /**
  * @covers EMongoUniqueValidator
  */
 function testUniqueValidator()
 {
     $c = new User();
     $c->setScenario('testUnqiue');
     $c->username = '******';
     $this->assertTrue($c->save());
     $c = new User();
     $c->setScenario('testUnqiue');
     $c->username = '******';
     $this->assertFalse($c->validate());
     $this->assertNotEmpty($c->getError('username'));
 }
Example #9
0
$test2 = empty($userTest1->getErrors()) ? '' : 'Failed: It should not have errors when valid input is provided<br>';
echo $test2;
?>

<h2>It should extract the parameters that went in</h2>
<?php 
$props = $userTest1->getParameters();
print_r($props);
?>

<h2>It should have an error when the first name contains invalid characters</h2>
<?php 
$invalidUser = array("userName" => "Thugnifi(en7", "password" => "12345678");
$userTest2 = new User($invalidUser);
$test2 = empty($userTest2->getErrors()) ? '' : 'Failed:It should have errors when invalid input is provided<br>';
echo $test2;
echo "The error for username is: " . $userTest2->getError('userName') . "<br>";
echo "The object is: {$userTest2}<br>";
?>

<h2>It should have an error when the password is less than 8 characters</h2>
<?php 
$invalidUser = array("userName" => "Thugnificent", "password" => "12345");
$userTest3 = new User($invalidUser);
$test2 = empty($userTest3->getErrors()) ? '' : 'Failed:It should have errors when invalid input is provided<br>';
echo $test2;
echo "The error for password is: " . $userTest3->getError('password') . "<br>";
echo "The object is: {$userTest3}<br>";
?>
</body>
</html>
 public function testInvalidPassword()
 {
     $invalidTest = array("email" => "*****@*****.**", "password" => "nope");
     $s1 = new User($invalidTest);
     $this->assertTrue(!empty($s1->getError('password')), 'It should have a password error if the password is invalid');
 }