public function save()
 {
     $Access = new Access($this->data->Access);
     $Access->save();
     $go = '>auth/Access/formObject/' . $Access->getId();
     $this->renderPrompt('information', 'OK', $go);
 }
Beispiel #2
0
 public function addAdmin($entity)
 {
     if (\Auth::check()) {
         if (is_object($entity)) {
             $acl = new \Access();
             $acl->user_id = \Auth::user()->id;
             $acl->entity_name = get_class($entity);
             $acl->entity_id = $entity->id;
             $acl->save();
             return;
         }
     }
     return;
 }
Beispiel #3
0
 function privilegeAction()
 {
     $model = new User();
     $model->allFIelds = true;
     $id = AF::get($this->params, 'id', 0);
     if (!$id) {
         throw new AFHttpException(0, 'no_id');
     }
     if (!$model->setByID($id)) {
         throw new AFHttpException(0, 'incorrect_id');
     }
     $access = new Access();
     $access->fillFromUser($model);
     $userAccess = $access->getUserUpdateAccess();
     ksort($userAccess);
     if (isset($_POST['ajax'])) {
         $newAcces = AF::get($_POST, 'array');
         if ($newAcces) {
             $access->setUserAccess($newAcces);
             // hack to get the uesrs_access table to update instead of insert
             $msql = SafeMySQL::getInstance();
             $sql = "SELECT * FROM ?n WHERE user_id = ?i";
             $result = $msql->getRow($sql, $access->tableName(), $access->user_id);
             if (!empty($result)) {
                 $access->setIsNewRecord(0);
             }
             if ($access->save()) {
                 $model->user_id_updated = $this->user->user_id;
                 $model->updated = 'NOW():sql';
                 $model->IsNewRecord = false;
                 $model->save();
                 Message::echoJsonSuccess(__('user_access_updated'));
             } else {
                 Message::echoJsonError(__('user_access_not_updated'));
             }
         } else {
             Message::echoJsonError(__('user_access_not_updated'));
         }
     }
     Assets::js('jquery.form');
     $this->addToPageTitle('User privilege');
     $this->render('privilege', array('userAccess' => $userAccess, 'model' => $model));
 }
Beispiel #4
0
 public function actionCreate()
 {
     $assetsUrl = Yii::app()->getAssetManager()->publish(dirname(__FILE__) . '/../assets/');
     Yii::app()->getClientScript()->registerScriptFile($assetsUrl . '/accessForm.js');
     $model = new Access();
     if (isset($_POST['Access'])) {
         $model->setAttributes($_POST['Access']);
         if (isset($_POST['Access']['roles'])) {
             $model->roles = $_POST['Access']['roles'];
         }
         try {
             if ($model->save()) {
                 if (isset($_GET['returnUrl'])) {
                     $this->redirect($_GET['returnUrl']);
                 } else {
                     $this->redirect(array('/role/access'));
                 }
             }
         } catch (Exception $e) {
             $model->addError('', $e->getMessage());
         }
     } elseif (isset($_GET['Access'])) {
         $model->attributes = $_GET['Access'];
     }
     $model->module = isset($_GET['module']) ? $_GET['module'] : '';
     //if controller is selected from dropdown set it to model
     if (isset($_GET['controller'])) {
         $model->controller = $_GET['controller'];
     } else {
         //find the first one
         $controllers = Awecms::getControllers($model->module);
         if (count($controllers)) {
             $model->controller = reset($controllers);
         }
     }
     $this->render('create', array('model' => $model));
 }
Beispiel #5
0
 public function afterSave()
 {
     parent::afterSave();
     $accessModel = new Access();
     $accessModel->user_id = $this->user_id;
     $accessModel->save();
 }
 $u = User::where('username', $usuario)->get();
 if (count($u) > 0) {
     if (helpers::getParam('senha', $senha)) {
         $us = User::where('username', $usuario)->where('password', md5(md5($senha)))->get();
         if (count($us) > 0) {
             foreach ($us as $r) {
                 try {
                     $keyAcesso = md5($r->username . date(DATE_ATOM));
                     $keyAcesso = $keyAcesso . md5($r->password . date(DATE_ATOM));
                     if (count($acesso = Access::where('id_user', $r->id)->get()) > 0) {
                         Access::where('id_user', $r->id)->update(['accesskey' => $keyAcesso]);
                     } else {
                         $acesso = new Access();
                         $acesso->accesskey = $keyAcesso;
                         $acesso->id_user = $r->id;
                         $acesso->save();
                     }
                     $x = User::where('users.id', $r->id)->join('accesses AS a', 'a.id_user', '=', 'users.id')->select('users.*', 'a.accesskey')->get();
                     helpers::send(false, '', $x);
                 } catch (Exception $e) {
                     helpers::send(true, 'Ocorreu um erro ao gerar a key' . $e->getMessage(), '');
                 }
             }
         } else {
             helpers::send(true, 'Senha inválida', '');
         }
     } else {
         helpers::send(true, 'Senha em branco', '');
     }
 } else {
     helpers::send(true, 'Usuário inválido', '');