/**
  * Allows users to edit another users' data
  * (should be reserved for administrators)
  *
  * @access public
  * @return void
  */
 public function editAction()
 {
     $this->title = 'Edit this user';
     $form = new UserForm();
     $userModel = new BackofficeUser();
     if ($this->getRequest()->isPost()) {
         if ($form->isValid($this->getRequest()->getPost())) {
             $userModel->save($form->getValues());
             $this->_helper->FlashMessenger(array('msg-success' => 'The user was successfully updated'));
             App_FlagFlippers_Manager::save();
             $this->_redirect('/users/');
         }
     } else {
         $id = $this->_getParam('id');
         if (!is_numeric($id)) {
             $this->_helper->FlashMessenger(array('msg-error' => 'The user id you provided is invalid'));
             $this->_redirect('/users/');
         }
         if ($id == 1) {
             $this->_helper->FlashMessenger(array('msg-error' => 'It is forbidden to mess with the admin account in this release.'));
             $this->_redirect('/users/');
         }
         $row = $userModel->findById($id);
         if (empty($row)) {
             $this->_helper->FlashMessenger(array('msg-error' => 'The requested user could not be found'));
             $this->_redirect('/users/');
         }
         $data = $row->toArray();
         $data['groups'] = $row->groupIds;
         $form->populate($data);
         $this->view->item = $row;
     }
     $this->view->form = $form;
 }
Example #2
0
 public function run()
 {
     $model = new UserForm();
     if (($post = $this->request->getPost('UserForm', false)) !== false) {
         $model->attributes = $post;
         if ($model->save()) {
             $this->response(200, '更新用户成功');
         } else {
             $this->response(500, '更新用户失败');
         }
         $this->app->end();
     } else {
         if (($id = $this->request->getQuery('id', 0)) != false) {
             if (($user = User::model()->findByPk($id)) != false) {
                 $model->attributes = ['id' => $user->id, 'username' => $user->username, 'realname' => $user->realname, 'nickname' => $user->nickname, 'email' => $user->email, 'state' => $user->state];
                 $auth = $this->app->getAuthManager();
                 $roles = $auth->getRoleByUserId($id);
                 $role = [];
                 foreach ($roles as $item) {
                     $role[] = $item->getId();
                 }
                 $groups = $auth->getGroupByUserId($id);
                 $group = [];
                 foreach ($groups as $item) {
                     $group[] = $item->getId();
                 }
                 $this->render('edit', ['model' => $model, 'role' => $role, 'group' => $group, 'roleList' => Role::model()->findAll(), 'groupList' => Group::model()->findAll()]);
                 $this->app->end();
             }
         }
     }
     $this->response(404, '参数错误');
 }
Example #3
0
 public function actionUser()
 {
     $model = new UserForm();
     if ($model->load(Yii::$app->request->post()) && $model->valideate()) {
     } else {
         return $this->render('userForm', ['model' => $model]);
     }
 }
Example #4
0
 /**
  * 用户注册服务
  * 
  *@param UserForm $userInfo
  *@return boolean
  */
 public function register($userInfo)
 {
     $db = $this->_getConnecion();
     $stmt = $db->createStatement('SELECT * FROM user WHERE username=:username');
     if ($stmt->getOne(array(':username' => $userInfo->getUsername()))) {
         $this->showMessage('该用户已经注册.');
     }
     return $db->execute("INSERT INTO user SET " . $db->sqlSingle(array('username' => $userInfo->getUsername(), 'password' => $userInfo->getPassword())));
 }
Example #5
0
 public function actionUserForm()
 {
     $model = new UserForm();
     if ($model->load(yii::$app->request->post()) && $model->validate()) {
         // alguma coisa
     } else {
         return $this->render('userForm', array('model' => $model));
     }
 }
Example #6
0
 public function signupAction()
 {
     $account = new Account();
     $accountForm = new AccountForm($account);
     $this->view->accountForm = $accountForm;
     $user = new User();
     $userForm = new UserForm($user);
     $this->view->userForm = $userForm;
     $this->view->setVar("tab", 0);
     if ($this->request->isPost()) {
         try {
             $this->db->begin();
             $accountForm->bind($this->request->getPost(), $account);
             $userForm->bind($this->request->getPost(), $user);
             $idAccountplan = $accountForm->getValue('idAccountplan');
             $idAccounttype = $accountForm->getValue('idAccounttype');
             $city = $accountForm->getValue('city');
             $pass1 = $userForm->getValue('pass1');
             $pass2 = $userForm->getValue('pass2');
             $email = $this->request->getPost('email');
             $this->validateEqualsPassword($pass1, $pass2);
             $this->validateFields(array($idAccounttype, $idAccountplan, $city), array("Debes seleccionar un tipo de cuenta", "Debes seleccionar un plan de pago, recuerda que tenemos algunos gratuitos", "Debes seleccionar una ciudad"));
             if ($this->saveAccount($account, $accountForm, $userForm)) {
                 if ($this->saveUser($user, $account)) {
                     $file = $_FILES['avatar'];
                     $ext = explode("/", $file['type']);
                     $file['newName'] = "{$user->idUser}.{$ext[1]}";
                     $dir = $this->uploader->user_avatar_dir . "/" . $user->idUser . "/images/avatar/";
                     $uploader = new \Sayvot\Misc\Uploader();
                     $uploader->setExtensionsAllowed(array("png", "jpg", "jpeg"));
                     $uploader->setFile($file);
                     $uploader->setMaxSizeSupported($this->uploader->images_max_size);
                     $uploader->setDir($dir);
                     $uploader->validate();
                     $uploader->upload();
                     if ($this->saveCredential($user, $email, $pass1)) {
                         $this->db->commit();
                         $pe = new \Sayvot\Misc\ParametersEncoder();
                         $link = $pe->encodeLink("account/verify", array($account->idAccount, $user->idUser));
                         $this->flashSession->warning($link);
                         return $this->response->redirect("session/login");
                     }
                 }
             }
         } catch (InvalidArgumentException $ex) {
             $this->flashSession->error($ex->getMessage());
             $this->db->rollback();
         } catch (Exception $ex) {
             $this->db->rollback();
             $this->flashSession->error("Ha ocurrido un error, por favor contacta al administrador");
             $this->logger->log("Exception while creating account: " . $ex->getMessage());
             $this->logger->log($ex->getTraceAsString());
         }
     }
 }
 public function actionDatagrid()
 {
     $a = Yii::$app;
     $b = $a->params;
     Yii::$app->params['status'];
     $UserForm = new UserForm();
     $UserForm->scenario = 'search';
     $query = $UserForm->search(Yii::$app->request->queryParams);
     $pages = new Pagination(['pageParam' => 'pageCurrent', 'pageSizeParam' => 'pageSize', 'totalCount' => $query->count(), 'defaultPageSize' => 10]);
     $models = $query->offset($pages->offset)->limit($pages->limit)->all();
     return $this->render('datagrid', ['models' => $models, 'pages' => $pages]);
 }
Example #8
0
 public function actionAccount()
 {
     $model = new UserForm();
     if (($post = $this->request->getPost('UserForm', false)) != false) {
         $model->attributes = $post;
         if ($model->save()) {
             $this->user->logout();
             $this->redirect($this->createUrl('index'));
         }
     }
     $this->render('account', ['model' => $model, 'service' => Service::model()->findByPk($this->user->getId())]);
 }
 /**
  * 添加用户
  */
 public function actionAdd()
 {
     $userForm = new UserForm('add');
     if (Yii::app()->request->getIsPostRequest()) {
         $post = Yii::app()->request->getPost('UserForm');
         $userForm->setAttributes($post, false);
         if ($userForm->validate() && UserModel::instance()->insert($post)) {
             $this->redirect(array('/user'));
         }
     }
     $this->setTitle('添加用户');
     $this->render('add', array('userForm' => $userForm));
 }
 public function addAction()
 {
     $form = new UserForm();
     if ($form->isPosted()) {
         if ($form->isValidForAdd()) {
             $id = User::create(["email" => Input::get("email"), "password" => Hash::make(Input::get("password"))])->id;
             $this->defaultGroup($id, 2);
             return Redirect::route("user/profile");
         }
         return Redirect::route("user/add")->withInput(["email" => Input::get("email"), "errors" => $form->getErrors()]);
     }
     return View::make("user/add", ["form" => $form, "HeaderTitle" => "ADD USER"]);
 }
Example #11
0
 public static function getInstance($id = NULL)
 {
     $form = new UserForm();
     if ($id) {
         $user = User::model()->findByPk($id);
         if ($user) {
             $form->attributes = $user->attributes;
             $form->unsetAttributes(array('password'));
             $form->_userModel = $user;
         }
     }
     return $form;
 }
Example #12
0
 public function actionLogin()
 {
     $model = new UserForm('login');
     if (!empty($_POST['UserForm'])) {
         $model->attributes = $_POST['UserForm'];
         if ($model->validate() && $model->login()) {
             $this->redirect(['cabinet/']);
         }
     }
     if (Yii::app()->request->isAjaxRequest) {
         $this->renderPartial('login', ['model' => $model]);
     } else {
         $this->render('login', ['model' => $model]);
     }
 }
Example #13
0
 public function newUserAction()
 {
     $request = $this->get('request');
     $user = new User();
     $userForm = new UserForm($user);
     if ($request->getMethod() === 'POST') {
         $userForm->bind($request);
         if ($userForm->validate()) {
             $user->save();
             return $this->redirect($this->generateUrl('login'));
         }
     }
     $context = array('form' => $userForm);
     return $this->render('', $context);
 }
 /**
  * Update user's roles.
  * @param $args array
  * @param $request PKPRequest
  */
 function execute($args, $request)
 {
     parent::execute($request);
     // Role management handled by parent form, just return user.
     $userDao = DAORegistry::getDAO('UserDAO');
     return $userDao->getById($this->userId);
 }
Example #15
0
 static function saveUsers($sql, $filename, $how = 'csv')
 {
     $exclude = array('name', 'email');
     $form = UserForm::getUserForm();
     $fields = $form->getExportableFields($exclude);
     // Field selection callback
     $fname = function ($f) {
         return 'cdata.`' . $f->getSelectName() . '` AS __field_' . $f->get('id');
     };
     $sql = substr_replace($sql, ',' . implode(',', array_map($fname, $fields)) . ' ', strpos($sql, 'FROM '), 0);
     $sql = substr_replace($sql, 'LEFT JOIN (' . $form->getCrossTabQuery($form->type, 'user_id', $exclude) . ') cdata
                 ON (cdata.user_id = user.id) ', strpos($sql, 'WHERE '), 0);
     $cdata = array_combine(array_keys($fields), array_values(array_map(function ($f) {
         return $f->get('label');
     }, $fields)));
     ob_start();
     echo self::dumpQuery($sql, array('name' => 'Name', 'organization' => 'Organization', 'email' => 'Email') + $cdata, $how, array('modify' => function (&$record, $keys) use($fields) {
         foreach ($fields as $k => $f) {
             if ($f && ($i = array_search($k, $keys)) !== false) {
                 $record[$i] = $f->export($f->to_php($record[$i]));
             }
         }
         return $record;
     }));
     $stuff = ob_get_contents();
     ob_end_clean();
     if ($stuff) {
         Http::download($filename, "text/{$how}", $stuff);
     }
     return false;
 }
Example #16
0
 public function validationForm($table, $value)
 {
     $message = "";
     switch ($table) {
         case 'poste':
             # code...
             $message = PostForm::validation($value);
             break;
         case 'guard':
             # code...
             $message = GuardForm::validation($value);
             break;
         case 'guardtours':
             # code...
             $message = GuardToursForm::validation($value);
             break;
         case 'admin':
             # code...
             $message = UserForm::validation($value);
             break;
         case 'tours':
             # code...
             $message = array('error' => 0);
             break;
         default:
             # code...
             break;
     }
     return $message;
 }
Example #17
0
 function getRequestStructure($format, $data = null)
 {
     $supported = array("alert", "autorespond", "source", "topicId", "attachments" => array("*" => array("name", "type", "data", "encoding", "size")), "message", "ip", "priorityId");
     # Fetch dynamic form field names for the given help topic and add
     # the names to the supported request structure
     if (isset($data['topicId']) && ($topic = Topic::lookup($data['topicId'])) && ($form = $topic->getForm())) {
         foreach ($form->getDynamicFields() as $field) {
             $supported[] = $field->get('name');
         }
     }
     # Ticket form fields
     # TODO: Support userId for existing user
     if ($form = TicketForm::getInstance()) {
         foreach ($form->getFields() as $field) {
             $supported[] = $field->get('name');
         }
     }
     # User form fields
     if ($form = UserForm::getInstance()) {
         foreach ($form->getFields() as $field) {
             $supported[] = $field->get('name');
         }
     }
     if (!strcasecmp($format, 'email')) {
         $supported = array_merge($supported, array('header', 'mid', 'emailId', 'to-email-id', 'ticketId', 'reply-to', 'reply-to-name', 'in-reply-to', 'references', 'thread-type', 'flags' => array('bounce', 'auto-reply', 'spam', 'viral'), 'recipients' => array('*' => array('name', 'email', 'source'))));
         $supported['attachments']['*'][] = 'cid';
     }
     return $supported;
 }
Example #18
0
 public function actionForget()
 {
     $model = new UserForm('foget');
     $msg = '';
     if (!empty($_POST['UserForm'])) {
         $model->attributes = $_POST['UserForm'];
         if ($model->validate()) {
             $user = new UserModel();
             $user->password = UserModel::model()->cryptPass($pass = UserModel::model()->genPassword());
             $user->save();
             Yii::app()->email->send($model->email, 'Новый пароль', 'Ваш новый пароль:' . $pass);
             $msg = 'Новый пароль отправлен Вам на почту.';
         }
     }
     $this->render('forget', ['model' => $model, 'msg' => $msg]);
 }
Example #19
0
 public function registerAction()
 {
     $user = new User();
     $form = new UserForm($user);
     $form->setFieldsMap(array('PlainPassword' => array(new Limit(null, 255), new NotBlank(), new Password())));
     if ($this->request->isPostMethod()) {
         $form->handleRequest($this->request);
         if ($form->isValid()) {
             $plainPassword = $user->getPlainPassword();
             DB::create($user, $errors);
             if ($this->registry->auth->login($user->Email, $plainPassword)) {
                 FormMessage::sendMessage(FormMessage::SUCCESS, 'Your account is successfully registered.');
                 $this->redirectUrl(BASE_URL . '/profile');
             }
         }
     }
     return array('title' => 'Create Account', 'form' => $form);
 }
 public function allowAccess()
 {
     parent::allowAccess();
     if (Openbiz::$app->getUserProfile("Id")) {
         return 1;
     } else {
         return 0;
     }
 }
 public function processValues($values)
 {
     if ($values['userpic'] instanceof sfValidatedFile) {
         // file was uploaded
         $path = $this->getObject()->checkDir($values['userpic']->getPath(), $this->getObject()->getId());
         $values['userpic'] = $this->processPicture($values['userpic'], $path, 100, 100);
     }
     unset($values['userpic']);
     return parent::processValues($values);
 }
Example #22
0
 public function bind(array $taintedValues = null, array $taintedFiles = null)
 {
     // remove the embedded new form if the name field was not provided
     if (is_null($taintedValues['new_samba_account']['hostname']) || strlen($taintedValues['new_samba_account']['hostname']) === 0) {
         unset($this->embeddedForms['new_samba_account'], $taintedValues['new_samba_account']);
         $this->validatorSchema['new_samba_account'] = new sfValidatorPass();
     }
     // call parent bind method
     parent::bind($taintedValues, $taintedFiles);
 }
Example #23
0
 public function rerender()
 {
     // clean active record to force query again
     $this->m_ActiveRecord = null;
     // set fix search rule
     if (!$this->_userId) {
         return BizSystem::clientProxy()->redirectView(ACCESS_DENIED_VIEW);
     }
     $this->m_FixSearchRule = "[Id]=" . $this->_userId;
     return parent::rerender();
 }
 public function rerender()
 {
     // clean active record to force query again
     $this->activeRecord = null;
     // set fix search rule
     if (!$this->_userId) {
         return Openbiz::$app->getClientProxy()->redirectView(OPENBIZ_ACCESS_DENIED_VIEW);
     }
     $this->fixSearchRule = "[Id]=" . $this->_userId;
     return parent::rerender();
 }
Example #25
0
 public function allowAccess()
 {
     parent::allowAccess();
     $token = $_GET['token'];
     if ($user_id = $this->ValidateToken($token)) {
         $this->m_FixSearchRule = "[Id] = {$user_id}";
         return 1;
     } else {
         return 0;
     }
 }
Example #26
0
 public function editProfileAction()
 {
     if (!($user = $this->getUser())) {
         exit;
     }
     $form = new UserForm($user);
     if ($this->request->isPostMethod()) {
         $form->handleRequest($this->request);
         if ($form->isValid()) {
             // update record
             DB::update($user);
             FormMessage::sendMessage(FormMessage::SUCCESS, 'Your profile is successfully updated.');
             if ($this->request->getValue('SaveAndExit')) {
                 $this->redirectUrl(BASE_URL . '/profile');
             }
         } else {
             FormMessage::sendMessage(FormMessage::ERROR, 'Sorry, saving went wrong... Try again.');
         }
     }
     return array('title' => 'Edit profile', 'form' => $form);
 }
Example #27
0
    function customHead() {
        $user = __get('user');

        if(isset($user['pk_i_id'])) {
            UserForm::js_validation_edit();
        } else {
            UserForm::js_validation();
        }?>
        <?php UserForm::location_javascript("admin"); ?>

        <?php
    }
 public function editAction()
 {
     $id = (int) $this->params()->fromRoute('id', 0);
     if (!$id) {
         return $this->redirect()->toRoute('users', ['action' => 'add']);
     }
     try {
         $user = $this->getUsersTable()->getUser($id);
     } catch (\Exception $ex) {
         return $this->redirect()->toRoute('users', ['action' => 'index']);
     }
     $form = new UserForm();
     $form->bind($user);
     $form->get('submit')->setAttribute('value', 'Edit');
     $request = $this->getRequest();
     if ($request->isPost()) {
         $form->setInputFilter($user->getInputFilter());
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $this->getUsersTable()->saveUser($user);
             return $this->redirect()->toRoute('users');
         }
     }
     return ['id' => $id, 'form' => $form];
 }
Example #29
0
 public function actionEdit()
 {
     $model = new UserForm();
     if (($post = $this->request->getPost('UserForm', false)) !== false) {
         $post['state'] = -1;
         $model->attributes = $post;
         if ($model->save()) {
             $this->response(200, '更新用户成功');
         } else {
             $this->response(500, '更新用户失败');
         }
     } else {
         if (($id = $this->request->getQuery('id', 0)) != false) {
             if (($user = User::model()->findByPk($id)) != false) {
                 $model->attributes = ['id' => $user->id, 'username' => $user->username, 'realname' => $user->realname, 'nickname' => $user->nickname, 'email' => $user->email, 'state' => -1];
                 $this->render('edit', ['model' => $model]);
             }
         } else {
             $this->response(404, '参数错误');
         }
     }
 }
Example #30
0
 public function editAction($id)
 {
     $account = $this->user->account;
     $editUser = User::findFirst(array("conditions" => "idUser = ?1 AND idAccount = ?2", "bind" => array(1 => $id, 2 => $account->idAccount)));
     if (!$editUser) {
         $this->flashSession->error("El usuario que intenta editar no existe, por favor verifique la información");
         return $this->response->redirect("user/index");
     }
     $this->view->setVar("user", $editUser);
     $editUser->address_user = $editUser->address;
     $editUser->name_user = $editUser->name;
     $editUser->city_user = $editUser->city;
     $editUser->state_user = $editUser->state;
     $editUser->phone_user = $editUser->phone;
     $form = new UserForm($editUser, $this->user->role);
     if ($this->request->isPost()) {
         $form->bind($this->request->getPost(), $editUser);
         $editUser->updated = time();
         $email = strtolower($form->getValue('email'));
         $editUser->email = $email;
         $editUser->name = $this->request->getPost('name_user');
         $editUser->phone = $this->request->getPost('phone_user');
         $editUser->address = $this->request->getPost('address_user');
         $editUser->state = $this->request->getPost('state_user');
         $editUser->city = $this->request->getPost('city_user');
         if ($editUser->save()) {
             $this->flashSession->success('Se ha editado exitosamente el usuario <strong>' . $editUser->userName . '</strong>');
             $this->trace("success", "Se edito un usuario con ID: {$editUser->idUser}");
             return $this->response->redirect("user/index");
         } else {
             foreach ($editUser->getMessages() as $message) {
                 $this->flashSession->error($message);
             }
             $this->trace("fail", "No se edito el usuario con ID: {$editUser->idUser}");
         }
     }
     $this->view->setVar("user", $editUser);
     $this->view->UserForm = $form;
 }