/**
  * URI like - .../user/login?email=simple@mail.com&password=qwerty
  * 
  * @param type $user
  * @param type $password 
  */
 public function actionLogin($user, $password, $isFirst = false, $forceRedirectURL = false)
 {
     $userApi = sharedkeyApi::create('usersAPI');
     $user = trim($user);
     $password = trim($password);
     $userApi->addParams(array('email' => $user, 'password' => $password, 'format' => 'json'));
     $auth = $userApi->auth('get');
     $auth = json_decode($auth);
     if ($auth->auth == true) {
         $identity = new UserIdentity($user, $password);
         $userControl = new userControl();
         $userControl->setData((array) $auth->user);
         $identity->authenticate();
         $duration = Yii::app()->params['sessionTimeout'];
         //set Duration
         $sessionTimeout = !$duration ? 1440 : $duration;
         $absoluteSessionTimeout = !Yii::app()->params['absoluteSessionTimeout'] ? 6912000 : Yii::app()->params['absoluteSessionTimeout'];
         Yii::app()->user->login($identity, $duration);
         Yii::app()->user->setState('sessionTimeout', time() + $sessionTimeout);
         Yii::app()->user->setState('absoluteSessionTimeout', time() + $absoluteSessionTimeout);
         $user = User::model()->find('email=:email', array(':email' => $identity->username));
         $user->loginDate = date('Y-m-d h:i:s');
         $user->numoflogins = $user->numoflogins + 1;
         $user->update();
         $redirectPath = $isFirst ? '/welcome' : 'app/gallery';
         if (YII::app()->user->getState("redirect_url")) {
             $redirectPath = YII::app()->user->getState("redirect_url");
         }
         if (isset($_GET['url'])) {
             $redirectPath = $_GET['url'];
         }
         if ($forceRedirectURL) {
             $redirectPath = $forceRedirectURL;
         }
         $redirectPath = basePath($redirectPath);
         if (Yii::app()->request->isAjaxRequest) {
             echo json_encode(array('status' => 1, 'url' => $redirectPath));
             die;
         }
         $this->redirect($redirectPath);
     } else {
         if (Yii::app()->request->isAjaxRequest) {
             echo json_encode(array('status' => 0, 'message' => 'Error! Login is incorrect.'));
             die;
         }
         YII::app()->user->setFlash('login_error', true);
         if (YII::app()->user->getState("redirect_url")) {
             $this->redirect(basePath('?url=' . YII::app()->user->getState("redirect_url")));
         } else {
             $this->redirect(basePath(''));
         }
     }
 }
Exemple #2
0
 /**
  *
  * @param type $property_id
  * @return boolean 
  */
 public static function changeActiveProperty($property_id)
 {
     $userId = Yii::app()->user->getState('id');
     $userModel = new \User();
     $isValidProperty = UserAccessTable::checkUser2PropertyAccess($userId, $property_id, UserAccessTable::GUEST);
     if (!$isValidProperty) {
         return false;
     } else {
         $result = $userModel->updateByPk($userId, array('property_id' => $property_id));
         $userControl = new userControl();
         $userControl->update();
         return true;
     }
 }
Exemple #3
0
					<option>Select</option>
					<option>1</option>
					<option>2</option>
				</select>
			</div>						
		
			<div class="form-group">
				<label for="exampleInputFile">Browse Profile Picture</label>
				<input type="file" id="exampleInputFile">
				<p class="help-block">Example block-level help text here.</p>
			</div>
			
		  </div>
		  <div class="modal-footer">
			<button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
			<button type="button" class="btn btn-success" name="btnadd">Add New</button>
		  </div>
<?php 
if (isset($_POST["btnadd"])) {
    include_once 'controller/userControl.php';
    $array = array("userID" => "null", "userName" => $_POST["txtusername"], "userPassword" => $_POST["txtpassword"], "userFirstName" => $_POST["txtfname"], "userLastName" => $_POST["txtlname"], "userContactNum" => $_POST["txtcontact"], "userAddress" => $_POST["txtaddress"], "userEmail" => $_POST["txtemail"], "userStatus" => 1, "userTypeID" => $_POST["cbousertype"]);
    echo $array;
    $obj = new userControl();
    $obj->create($array);
}
?>
		  
	  </form>
    </div>
  </div>
</div>
 protected function backTutorial($tutorial)
 {
     $api = sharedkeyApi::create('usersAPI');
     $api->addParams(array($tutorial => '1', 'id' => Yii::app()->user->getState('id')));
     $result = $api->tutorial('update');
     $user = new userControl();
     $user->update();
     return $result;
 }
 public function actionChangeactiveproperty($id)
 {
     if (isset($_GET['token'])) {
         //login user and redirect back to complete the action
         $this->redirect(basePath('activeuser?token=' . $_GET['token'] . '&url=app/changeactiveproperty/' . $id));
     }
     $userId = Yii::app()->user->getState('id');
     $userModel = new \User();
     $isValidProperty = UserAccessTable::checkUser2PropertyAccess($userId, $id, UserAccessTable::GUEST);
     if (!$isValidProperty) {
         Yii::app()->request->redirect(basePath('app/gallery'));
     } else {
         /* https://www.pivotaltracker.com/story/show/80061356
            ADMIN
                1. Owner/Admin deletes his LAST property.
                2. Keep his email so that he can reactivate and being taken to billings page upon logging in.
                3. Email is only kept for 30 days. Therefore he can only reactivare within 30 days.
                4. After 30 days, he will have re-sign up like a new user.
            */
         if ($this->_isAllUserPropertiesDeactivated($userId) && $this->_daysSinceLastPropertyEditDate($id) >= 30) {
             $this->removeUser($userId);
             return;
         }
         $result = $userModel->updateByPk($userId, array('property_id' => $id));
         $userControl = new userControl();
         $userControl->update();
         Yii::app()->request->redirect(basePath('app/gallery'));
     }
 }