Ejemplo n.º 1
0
 /**
  * Creates new user record. You must set all required user fields before calling this method. If errors occur you can use the standard Table class error handling methods to figure out what went wrong.
  *
  * Required fields are user_name, password, fname and lname.
  *
  * @access public 
  * @return bool Returns true if no error, false if error occurred
  */
 public function insert($pa_options = null)
 {
     if (!caCheckEmailAddress($this->get('email'))) {
         $this->postError(922, _t("Invalid email address"), 'ca_users->insert()');
         return false;
     }
     # Confirmation key is an md5 hash than can be used as a confirmation token. The idea
     # is that you create a new user record with the 'active' field set to false. You then
     # send the confirmation key to the new user (usually via e-mail) and ask them to respond
     # with the key. If they do, you know that the e-mail address is valid.
     if (function_exists('mcrypt_create_iv')) {
         $vs_confirmation_key = md5(mcrypt_create_iv(24, MCRYPT_DEV_URANDOM));
     } else {
         $vs_confirmation_key = md5(uniqid(mt_rand(), true));
     }
     $this->set("confirmation_key", $vs_confirmation_key);
     try {
         $vs_backend_password = AuthenticationManager::createUserAndGetPassword($this->get('user_name'), $this->get('password'));
         $this->set('password', $vs_backend_password);
     } catch (AuthClassFeatureException $e) {
         // auth class does not implement creating users at all
         $this->postError(925, _t("Current authentication adapter does not support creating new users."), 'ca_users->insert()');
         return false;
     } catch (Exception $e) {
         // some other error in auth class, e.g. user couldn't be found in directory
         $this->postError(925, $e->getMessage(), 'ca_users->insert()');
         $this->opo_log->log(array('CODE' => 'SYS', 'SOURCE' => 'ca_users/insert', 'MESSAGE' => _t('Authentication adapter could not create user. Message was: %1', $e->getMessage())));
         return false;
     }
     # set user vars (the set() method automatically serializes the vars array)
     $this->set("vars", $this->opa_user_vars);
     $this->set("volatile_vars", $this->opa_volatile_user_vars);
     return parent::insert($pa_options);
 }