"Fossies" - the Fresh Open Source Software Archive

Member "Open-Web-Analytics-1.7.0/modules/base/usersAdd.php" (16 Sep 2020, 4404 Bytes) of package /linux/www/Open-Web-Analytics-1.7.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "usersAdd.php" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 1.6.9_vs_1.7.0.

    1 <?php
    2 
    3 //
    4 // Open Web Analytics - An Open Source Web Analytics Framework
    5 //
    6 // Copyright 2006 Peter Adams. All rights reserved.
    7 //
    8 // Licensed under GPL v2.0 http://www.gnu.org/copyleft/gpl.html
    9 //
   10 // Unless required by applicable law or agreed to in writing, software
   11 // distributed under the License is distributed on an "AS IS" BASIS,
   12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   13 // See the License for the specific language governing permissions and
   14 // limitations under the License.
   15 //
   16 // $Id$
   17 //
   18 
   19 require_once(OWA_BASE_DIR.'/owa_adminController.php');
   20 
   21 /**
   22  * Add User Controller
   23  * 
   24  * @author      Peter Adams <peter@openwebanalytics.com>
   25  * @copyright   Copyright &copy; 2006 Peter Adams <peter@openwebanalytics.com>
   26  * @license     http://www.gnu.org/copyleft/gpl.html GPL v2.0
   27  * @category    owa
   28  * @package     owa
   29  * @version        $Revision$
   30  * @since        owa 1.0.0
   31  */
   32 
   33 class owa_usersAddController extends owa_adminController {
   34 
   35     function __construct($params) {
   36 
   37         parent::__construct($params);
   38 
   39         $this->setRequiredCapability('edit_users');
   40         $this->setNonceRequired();
   41     }
   42 
   43     public function validate() {
   44         
   45         $this->addValidation('email_address', $this->getParam('email_address'), 'required', array('stopOnError' => true));
   46         $this->addValidation('user_id', $this->getParam('user_id'), 'required', array('stopOnError' => true));
   47         $this->addValidation('user_id', $this->getParam('user_id'), 'userName', array('stopOnError' => true));
   48         $this->addValidation('role', $this->getParam('role'), 'required', array('stopOnError'   => true));
   49         
   50         $roles = owa_coreAPI::getAllRoles();
   51         $this->addValidation('role', $this->getParam('role'), 'inArray', array('possible_values' => $roles, 'stopOnError' => true) );
   52         
   53         // Check for user with the same email address
   54         // this is needed or else the change password feature will not know which account
   55         // to chane the password for.
   56         $userEmailAddressEntityConf = [
   57             'entity'    => 'base.user',
   58             'column'    => 'email_address',
   59             'errorMsg'  => $this->getMsg(3009)
   60         ];
   61 
   62         $this->addValidation('email_address', trim($this->getParam('email_address')), 'entityDoesNotExist', $userEmailAddressEntityConf);
   63 
   64         // Check user name.
   65         $userEntityConf = [
   66             'entity'    => 'base.user',
   67             'column'    => 'user_id',
   68             'errorMsg'  => $this->getMsg(3001)
   69         ];
   70 
   71         $this->addValidation('user_id', $this->getParam('user_id'), 'entityDoesNotExist', $userEntityConf);
   72     }
   73 
   74     function action() {
   75 
   76         $userManager = owa_coreApi::supportClassFactory('base', 'userManager');
   77 
   78 
   79         $user_params = array( 'user_id'         => trim($this->params['user_id']),
   80                               'real_name'         => $this->params['real_name'],
   81                               'role'            => $this->params['role'],
   82                               'email_address'     => trim($this->params['email_address']));
   83 
   84         $u = $userManager->createNewUser($user_params);
   85         
   86         $u_properties = [];
   87         
   88         if ( $u ) {
   89 
   90             $u_properties = [
   91                 
   92                 'user_id'   => $u->get('user_id'),
   93                 'email_address' => $u->get( 'email_address'),
   94                 'real_name'     =>  $u->get( 'real_name' ),
   95                 'api_key'       =>  $u->get('api_key'),
   96                 'role'          =>  $u->get('role')
   97             ];  
   98         }
   99         
  100         // assign user to view for use by CLI and REST controllers that may
  101         // extend this
  102         $this->set('user', $u_properties );
  103         
  104         // add temp passkey for use in sending emails.
  105         $u_properties['temp_passkey'] = $u->get('temp_passkey');
  106         
  107         // post account creation event to event queue for
  108         // downstream email observers/handlers
  109         $ed = owa_coreAPI::getEventDispatch();
  110         $ed->log( $u_properties, 'base.new_user_account' );
  111     }
  112     
  113     function success() {
  114         
  115         unset($this->data['user']);
  116         $this->setRedirectAction('base.users');
  117         $this->set('status_code', 3000);
  118     }
  119 
  120     function errorAction() {
  121         $this->setView('base.options');
  122         $this->setSubview('base.usersProfile');
  123         $this->set('error_code', 3009);
  124         //assign original form data so the user does not have to re-enter the data
  125         $this->set('profile', $this->params);
  126     }
  127 }
  128 
  129 ?>