Example #1
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;
     }
 }
 public function actionEdit()
 {
     //echo "<pre>";var_dump($_REQUEST);exit;
     $usr = new User();
     $role = new Role();
     $usrInfo = array();
     $label = '';
     foreach ($_REQUEST as $k => $v) {
         $_REQUEST[$k] = trim($v);
     }
     // 获取role列表
     $roleInfos = $role->findAll(array('select' => 'rid,rname'));
     // 过滤超极管理员
     foreach ($roleInfos as $role) {
         if ($role['rname'] != 'superman') {
             $roles[] = $role;
         }
     }
     // var_dump($_REQUEST); exit;
     //
     if (isset($_REQUEST['id']) && $_REQUEST['id'] != '') {
         // 修改
         $usrInfo = $usr->getUserWithRole('uid=:uid', array(':uid' => $_REQUEST['id']));
         $usrInfo = $usrInfo[0];
         if (isset($_REQUEST['modify'])) {
             $usr->updateByPk($_REQUEST['id'], array('uname' => $_REQUEST['name'], 'email' => $_REQUEST['email'], 'pwd' => Login::pwdEncry($_REQUEST['pwd']), 'rid' => $_REQUEST['rid']));
             $this->redirect('/main/user/list');
         }
     } elseif (!empty($_REQUEST['name'])) {
         // 新增
         $usrInfo = $usr->getUserWithRole('uname=:name', array(':name' => $_REQUEST['name']));
         //var_dump($usrInfo);exit;
         if (!empty($usrInfo)) {
             $this->render('edit', array('roles' => $roles, 'entity' => $usrInfo[0], 'label' => 'has_usr'));
             exit;
         }
         if (isset($_REQUEST['modify'])) {
             $usr->uname = $_REQUEST['name'];
             $usr->email = $_REQUEST['email'];
             $usr->pwd = Login::pwdEncry($_REQUEST['pwd']);
             $usr->rid = $_REQUEST['rid'];
             $usr->save();
             $this->redirect('/main/user/list');
         }
     }
     $this->render('edit', array('entity' => $usrInfo, 'roles' => $roles, 'label' => $label));
 }
 public function actionEditpass()
 {
     $userModel = new User();
     $userInfo = $userModel->find('username=:name', array(':name' => Yii::app()->user->name));
     if (isset($_POST['User'])) {
         $userModel->attributes = $_POST['User'];
         //p($userModel->attributes);die;
         if ($userModel->validate()) {
             $newpass = md5($_POST['User']['newpassword']);
             if ($userModel->updateByPk($userInfo->id, array('password' => $newpass))) {
                 //Save Flash
                 Yii::app()->user->setFlash('success', '修改密码成功。:)');
             }
         }
     }
     $this->render("editpass", array('userModel' => $userModel));
 }
 /**
  * makeSupperUser 
  *
  * 创建超极管理员
  * 
  * @param mixed $uname 
  * @param mixed $pwd 
  * @return bool
  */
 public static function initSupperUser($uname, $pwd)
 {
     $user = new User();
     $userInfo = $user->getUserWithRole('uname=:name', array(':name' => $uname));
     if (empty($userInfo)) {
         // make user
         $user->uname = $uname;
         $user->email = '';
         $user->pwd = $pwd;
         $user->rid = 0;
         $user->save();
     }
     // make role
     $role = new Role();
     $rname = 'superman';
     $roleInfo = $role->find('rname=:name', array(':name' => $rname));
     if (empty($roleInfo)) {
         $params = array('name' => $rname, 'actions' => array());
         $action = new Action();
         $actionList = $action->findAll();
         foreach ($actionList as $k => $v) {
             $params['actions'][] = $v['aid'];
         }
         $role->saveRole($params);
         // save rid
         $userInfo = $user->getUserWithRole('uname=:name', array(':name' => $uname));
         $roleInfo = $role->find('rname=:name', array(':name' => $rname));
         $user->updateByPk($userInfo[0]['uid'], array('uname' => $uname, 'email' => '', 'pwd' => $pwd, 'rid' => $roleInfo['rid']));
     } else {
         $params = array('id' => $roleInfo['rid'], 'name' => $rname, 'actions' => array());
         $action = new Action();
         $actionList = $action->findAll();
         foreach ($actionList as $k => $v) {
             $params['actions'][] = $v['aid'];
         }
         $role->updateRole($params);
     }
     return true;
 }
Example #5
0
 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'));
     }
 }
 public function actionChangepassword()
 {
     $token = isset($_POST['token']) ? $_POST['token'] : '';
     $password = isset($_POST['password']) ? $_POST['password'] : '';
     $model = new Forgot();
     $userModel = new User();
     $isForgot = $model->findByAttributes(array('token' => $token));
     $userModel->updateByPk($isForgot->user_id, array('password' => $password));
     $isForgot->delete();
     $isFirst = false;
     if ($userModel->loginDate == null) {
         $isFirst = true;
     }
     $user = $userModel->findByPk($isForgot->user_id);
     $this->actionLogin($user->attributes['email'], $user->attributes['password'], $isFirst);
 }
Example #7
0
 /**
  * @covers EMongoDocument::updateByPk
  */
 function testUpdateByPk()
 {
     $c = new User();
     $c->username = '******';
     $this->assertTrue($c->save());
     $c->updateByPk($c->_id, array('$set' => array('username' => 'gfgfgf')));
     $r = User::model()->findOne(array('username' => 'gfgfgf'));
     $this->assertInstanceOf('EMongoDocument', $r);
     $this->assertEquals('gfgfgf', $r->username);
 }
Example #8
0
 public function SetLastVisit()
 {
     $lastVisit = new User();
     $lv = date('Y-m-d H:i:s');
     $lastVisit->updateByPk(Yii::app()->user->getId(), array('lastvisit_at' => $lv));
 }
Example #9
0
 protected function beforeAction($action)
 {
     $this->_controller = $action->getController()->getId();
     $this->_action = $action->getId();
     $this->returnurl = Fn::url_login_current();
     $token = FCookie::get("auth");
     $now = time();
     list($uid, $email, $timeout) = explode("\t", FHelper::auth_code($token, 'DECODE', FF_SALT));
     if ($uid) {
         $userInfo = $this->getUserinfo($uid);
         if ($userInfo['user']['id']) {
             if ($token == $userInfo['user']['token']) {
                 if ($now < $timeout) {
                     $this->userInfo = $userInfo['info'];
                     $this->user = $userInfo['user'];
                     if ($timeout - $now < 60 * 2) {
                         $timeout = time() + 60 * 15;
                         $token = FHelper::auth_code("{$uid}\t{$email}\t{$timeout}", 'ENCODE', FF_SALT);
                         FCookie::set('auth', $token, 60 * 15);
                         $attr = array('token' => $token);
                         $user_model = new User();
                         $user_model->updateByPk($uid, $attr);
                     }
                     //                        $timeout =  time()+60 *15;
                     //                        $token = FHelper::auth_code("$uid\t$email\t$timeout", 'ENCODE', FF_SALT);
                     //                        FCookie::set('auth', $token);
                 }
             }
         }
     }
     return true;
 }
Example #10
0
 public function actionActualizarStatus()
 {
     if ($_POST['id'] != 1) {
         $model = new User();
         if ($model->updateByPk($_POST['id'], array('status' => $_POST['status']))) {
             echo 'El usuario ahora está ' . $model->itemAlias("UserStatus", $_POST['status']);
         } else {
             echo 'Ha ocurrido un error';
         }
     } else {
         echo 'Usuario Administrador';
     }
 }