Example #1
0
 function validate($values)
 {
     $return = true;
     $validate = new Validate();
     if (!$validate->string($values['navn'], array('min_length' => 1))) {
         $return = false;
     }
     if (!$validate->string($values['adresse'], array('min_length' => 1))) {
         $return = false;
     }
     if (!$validate->number($values['postnr'], array('min' => 100))) {
         $return = false;
     }
     if (!$validate->string($values['postby'], array('min_length' => 1))) {
         $return = false;
     }
     if (!empty($values['email']) and !$validate->email($values['email'])) {
         $return = false;
     }
     /*
     if (isset($values['langekurser']) != "" && $values['langekurser'] != "1") $return = false;
     if (isset($values['kortekurser']) != "" && $values['kortekurser'] != "1") $return = false;
     if (isset($values['efterskole']) != "" && $values['efterskole'] != "1") $return = false;
     if (isset($values['kursuscenter']) != "" && $values['kursuscenter'] != "1") $return = false;
     */
     return $return;
 }
Example #2
0
 /**
  * @return bool
  * @throws Exception
  */
 public function validate()
 {
     if ($this->id && !Validate::number($this->id)) {
         throw new Exception('Invalid Id!');
     }
     if ($this->name && !Validate::string($this->name)) {
         throw new Exception('Invalid Name');
     }
     if ($this->language && !Validate::string($this->language)) {
         throw new Exception('Invalid Language');
     }
     if ($this->genre && !Validate::string($this->genre)) {
         throw new Exception('Invalid Genre');
     }
     if ($this->author && !Validate::string($this->author)) {
         throw new Exception('Invalid Author');
     }
     if ($this->publish_date && !Validate::number($this->publish_date)) {
         if (!Validate::date($this->publish_date)) {
             throw new Exception('Invalid Publish Date');
         }
         $this->publish_date = strtotime($this->publish_date);
     }
     return true;
 }
Example #3
0
 protected function validate($var)
 {
     $return = true;
     $validate = new Validate();
     if (!$validate->string($var['navn'], array('min_length' => 1))) {
         $return = false;
     }
     return $return;
 }
Example #4
0
 /**
  * Valida un DNI Español (el dni tiene que ser de la forma 11111111X)
  *
  * @param string $dni El Documento Nacional de Indentidad a chequear
  * @return bool
  */
 function dni($dni)
 {
     $letra = substr($dni, -1);
     $number = substr($dni, 0, -1);
     if (!Validate::string($number, VALIDATE_NUM, 8, 8)) {
         return false;
     }
     if (!Validate::string($letra, VALIDATE_ALPHA)) {
         return false;
     }
     // El resto entero de la division del numero del dni/23 +1
     // es la posicion de la letra en la cadena $string
     $string = 'TRWAGMYFPDXBNJZSQVHLCKET';
     // ver la letra de un numero
     if ($letra == $string[$number % 23]) {
         return true;
     }
     return false;
 }
Example #5
0
 function update_profile($req, $consumer, $token)
 {
     $version = $req->get_parameter('omb_version');
     if ($version != OMB_VERSION_01) {
         $this->clientError(_('Unsupported OMB version'), 400);
         return false;
     }
     # First, check to see if listenee exists
     $listenee = $req->get_parameter('omb_listenee');
     $remote = Remote_profile::staticGet('uri', $listenee);
     if (!$remote) {
         $this->clientError(_('Profile unknown'), 404);
         return false;
     }
     # Second, check to see if they should be able to post updates!
     # We see if there are any subscriptions to that remote user with
     # the given token.
     $sub = new Subscription();
     $sub->subscribed = $remote->id;
     $sub->token = $token->key;
     if (!$sub->find(true)) {
         $this->clientError(_('You did not send us that profile'), 403);
         return false;
     }
     $profile = Profile::staticGet('id', $remote->id);
     if (!$profile) {
         # This one is our fault
         $this->serverError(_('Remote profile with no matching profile'), 500);
         return false;
     }
     $nickname = $req->get_parameter('omb_listenee_nickname');
     if ($nickname && !Validate::string($nickname, array('min_length' => 1, 'max_length' => 64, 'format' => VALIDATE_NUM . VALIDATE_ALPHA_LOWER))) {
         $this->clientError(_('Nickname must have only lowercase letters and numbers and no spaces.'));
         return false;
     }
     $license = $req->get_parameter('omb_listenee_license');
     if ($license && !common_valid_http_url($license)) {
         $this->clientError(sprintf(_("Invalid license URL '%s'"), $license));
         return false;
     }
     $profile_url = $req->get_parameter('omb_listenee_profile');
     if ($profile_url && !common_valid_http_url($profile_url)) {
         $this->clientError(sprintf(_("Invalid profile URL '%s'."), $profile_url));
         return false;
     }
     # optional stuff
     $fullname = $req->get_parameter('omb_listenee_fullname');
     if ($fullname && mb_strlen($fullname) > 255) {
         $this->clientError(_("Full name is too long (max 255 chars)."));
         return false;
     }
     $homepage = $req->get_parameter('omb_listenee_homepage');
     if ($homepage && (!common_valid_http_url($homepage) || mb_strlen($homepage) > 255)) {
         $this->clientError(sprintf(_("Invalid homepage '%s'"), $homepage));
         return false;
     }
     $bio = $req->get_parameter('omb_listenee_bio');
     if ($bio && mb_strlen($bio) > 140) {
         $this->clientError(_("Bio is too long (max 140 chars)."));
         return false;
     }
     $location = $req->get_parameter('omb_listenee_location');
     if ($location && mb_strlen($location) > 255) {
         $this->clientError(_("Location is too long (max 255 chars)."));
         return false;
     }
     $avatar = $req->get_parameter('omb_listenee_avatar');
     if ($avatar) {
         if (!common_valid_http_url($avatar) || strlen($avatar) > 255) {
             $this->clientError(sprintf(_("Invalid avatar URL '%s'"), $avatar));
             return false;
         }
         $size = @getimagesize($avatar);
         if (!$size) {
             $this->clientError(sprintf(_("Can't read avatar URL '%s'"), $avatar));
             return false;
         }
         if ($size[0] != AVATAR_PROFILE_SIZE || $size[1] != AVATAR_PROFILE_SIZE) {
             $this->clientError(sprintf(_("Wrong size image at '%s'"), $avatar));
             return false;
         }
         if (!in_array($size[2], array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG))) {
             $this->clientError(sprintf(_("Wrong image type for '%s'"), $avatar));
             return false;
         }
     }
     $orig_profile = clone $profile;
     /* Use values even if they are an empty string. Parsing an empty string in
        updateProfile is the specified way of clearing a parameter in OMB. */
     if (!is_null($nickname)) {
         $profile->nickname = $nickname;
     }
     if (!is_null($profile_url)) {
         $profile->profileurl = $profile_url;
     }
     if (!is_null($fullname)) {
         $profile->fullname = $fullname;
     }
     if (!is_null($homepage)) {
         $profile->homepage = $homepage;
     }
     if (!is_null($bio)) {
         $profile->bio = $bio;
     }
     if (!is_null($location)) {
         $profile->location = $location;
     }
     if (!$profile->update($orig_profile)) {
         $this->serverError(_('Could not save new profile info'), 500);
         return false;
     } else {
         if ($avatar) {
             $temp_filename = tempnam(sys_get_temp_dir(), 'listenee_avatar');
             copy($avatar, $temp_filename);
             $imagefile = new ImageFile($profile->id, $temp_filename);
             $filename = Avatar::filename($profile->id, image_type_to_extension($imagefile->type), null, common_timestamp());
             rename($temp_filename, Avatar::path($filename));
             if (!$profile->setOriginal($filename)) {
                 $this->serverError(_('Could not save avatar info'), 500);
                 return false;
             }
         }
         return true;
     }
 }
 function validateAliases()
 {
     $aliases = array_map('common_canonical_nickname', array_unique(preg_split('/[\\s,]+/', $this->aliasstring)));
     if (count($aliases) > common_config('group', 'maxaliases')) {
         // TRANS: API validation exception thrown when aliases do not validate.
         // TRANS: %d is the maximum number of aliases and used for plural.
         throw new ApiValidationException(sprintf(_m('Too many aliases! Maximum %d allowed.', 'Too many aliases! Maximum %d allowed.', common_config('group', 'maxaliases')), common_config('group', 'maxaliases')));
     }
     foreach ($aliases as $alias) {
         if (!Validate::string($alias, array('min_length' => 1, 'max_length' => 64, 'format' => NICKNAME_FMT))) {
             throw new ApiValidationException(sprintf(_('Invalid alias: "%s".'), $alias));
         }
         if ($this->nicknameExists($alias)) {
             throw new ApiValidationException(sprintf(_('Alias "%s" already in use. Try another one.'), $alias));
         }
         // XXX assumes alphanum nicknames
         if (strcmp($alias, $this->nickname) == 0) {
             throw new ApiValidationException(_('Alias cannot be the same as nickname.'));
         }
     }
     return $aliases;
 }
Example #7
0
 /**
  * Try to register a user
  *
  * Validates the input and tries to save a new user and profile
  * record. On success, shows an instructions page.
  *
  * @return void
  */
 function tryRegister()
 {
     if (Event::handle('StartRegistrationTry', array($this))) {
         $token = $this->trimmed('token');
         if (!$token || $token != common_session_token()) {
             $this->showForm(_('网页错误,请返回重试
                               '));
             return;
         }
         $nickname = $this->trimmed('nickname');
         $type = $this->trimmed('type');
         $email = $this->trimmed('email');
         $fullname = $this->trimmed('fullname');
         $homepage = $this->trimmed('homepage');
         $bio = $this->trimmed('bio');
         $location = $this->trimmed('location');
         // We don't trim these... whitespace is OK in a password!
         $password = $this->arg('password');
         $confirm = $this->arg('confirm');
         // invitation code, if any
         $code = $this->trimmed('code');
         if ($code) {
             $invite = Invitation::staticGet($code);
         }
         if (common_config('site', 'inviteonly') && !($code && $invite)) {
             $this->clientError(_('Sorry, only invited people can register.'));
             return;
         }
         // Input scrubbing
         $nickname = common_canonical_nickname($nickname);
         $email = common_canonical_email($email);
         if (!$this->boolean('license')) {
             $this->showForm(_('You can\'t register if you don\'t ' . 'agree to the license.'));
         } else {
             if ($email && !Validate::email($email, common_config('email', 'check_domain'))) {
                 $this->showForm(_('Not a valid email address.'));
             } else {
                 if (!Validate::string($nickname, array('min_length' => 1, 'max_length' => 64, 'format' => NICKNAME_FMT))) {
                     $this->showForm(_('Nickname must have only lowercase letters ' . 'and numbers and no spaces.'));
                 } else {
                     if ($this->nicknameExists($nickname)) {
                         $this->showForm(_('Nickname already in use. Try another one.'));
                     } else {
                         if (!User::allowed_nickname($nickname)) {
                             $this->showForm(_('Not a valid nickname.'));
                         } else {
                             if ($this->emailExists($email)) {
                                 $this->showForm(_('Email address already exists.'));
                             } else {
                                 if (!is_null($homepage) && strlen($homepage) > 0 && !Validate::uri($homepage, array('allowed_schemes' => array('http', 'https')))) {
                                     $this->showForm(_('Homepage is not a valid URL.'));
                                     return;
                                 } else {
                                     if (!is_null($fullname) && mb_strlen($fullname) > 255) {
                                         $this->showForm(_('Full name is too long (max 255 chars).'));
                                         return;
                                     } else {
                                         if (Profile::bioTooLong($bio)) {
                                             $this->showForm(sprintf(_('Bio is too long (max %d chars).'), Profile::maxBio()));
                                             return;
                                         } else {
                                             if (!is_null($location) && mb_strlen($location) > 255) {
                                                 $this->showForm(_('Location is too long (max 255 chars).'));
                                                 return;
                                             } else {
                                                 if (strlen($password) < 6) {
                                                     $this->showForm(_('Password must be 6 or more characters.'));
                                                     return;
                                                 } else {
                                                     if ($password != $confirm) {
                                                         $this->showForm(_('Passwords don\'t match.'));
                                                     } else {
                                                         if ($user = User::register(array('nickname' => $nickname, 'password' => $password, 'email' => $email, 'fullname' => $fullname, 'homepage' => $homepage, 'bio' => $bio, 'location' => $location, 'code' => $code, 'type' => $type))) {
                                                             if (!$user) {
                                                                 $this->showForm(_('Invalid username or password.'));
                                                                 return;
                                                             }
                                                             // success!
                                                             if (!common_set_user($user)) {
                                                                 $this->serverError(_('Error setting user.'));
                                                                 return;
                                                             }
                                                             // this is a real login
                                                             common_real_login(true);
                                                             if ($this->boolean('rememberme')) {
                                                                 common_debug('Adding rememberme cookie for ' . $nickname);
                                                                 common_rememberme($user);
                                                             }
                                                             Event::handle('EndRegistrationTry', array($this));
                                                             // Re-init language env in case it changed (not yet, but soon)
                                                             common_init_language();
                                                             $this->showSuccess();
                                                         } else {
                                                             $this->showForm(_('Invalid username or password.'));
                                                         }
                                                     }
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }
 public function setLocation($location)
 {
     if ($location === '') {
         $location = null;
     } elseif (!Validate::string($location, array('max_length' => 255))) {
         throw new OMB_InvalidParameterException($location, 'profile', 'fullname');
     }
     $this->location = $location;
     $this->param_array = false;
 }
 public function dodaj($arg = false)
 {
     echo "Dodajam..";
     //get user id
     Session::init();
     $userid = Session::get('userid');
     if ($userid == "") {
         $redirect = sprintf("location: %sprijava", STATIC_URL);
         header($redirect);
         exit;
     }
     //parse POST variables add validation here
     $kratek_opis = $_POST['kratek_opis'];
     $datum = $_POST['date'];
     $podrocje = $_POST['podrocje'];
     $opis = $_POST['opis'];
     $tel = $_POST['tel'];
     //echo $kratek_opis, $datum, $podrocje, $opis, $tel, $userid;
     //inicialize model
     require 'models/prijava_tezave.php';
     $model = new Prijava_Tezave_Model();
     //validate
     $validation = "succeded";
     $validate = new Validate();
     if ($validate->string($kratek_opis) != 1) {
         $validation = "failed";
         $this->view->errors['kratek_opis'] = "Vnesite naslov težave";
     }
     if (!$validate->date($datum, 'm/d/Y')) {
         $validation = "failed";
         $this->view->errors['datum'] = "Izberite datum";
     }
     if ($validate->string($podrocje) != 1) {
         $validation = "failed";
         $this->view->errors['podrocje'] = "Vnesite področje na katerem imate težavo";
     }
     if ($validate->string($opis) != 1) {
         $validation = "failed";
         $this->view->errors['opis'] = "Vnesite opis vaše težave";
     }
     if ($validate->phone($tel) != 1) {
         $validation = "failed";
         $this->view->errors['tel'] = "Telefonska številka ni prave oblike";
     }
     /*samples
       var_dump($validate->email('*****@*****.**'));
       var_dump($validate->phone('031 772-079'));
       var_dump($validate->date('01/30/2014'));
       var_dump($validate->date('30/01/2012', 'd/m/Y'));
       var_dump($validate->string('test'));*/
     //$validation = "failed";
     if ($validation == "failed") {
         $this->view->values['kratek_opis'] = $kratek_opis;
         $this->view->values['datum'] = $datum;
         $this->view->values['podrocje'] = $podrocje;
         $this->view->values['opis'] = $opis;
         $this->view->values['tel'] = $tel;
         $this->view->render('user/prijava_tezave');
         exit;
     }
     //insert into database
     $this->view->result = $model->dodaj($kratek_opis, $datum, $podrocje, $opis, $tel, $userid);
     if ($this->view->result == 1) {
         //$this->view->msg="Zahtevek uspešno dodan.";
         //$this->view->render('user/zahtevki');
         $redirect = sprintf("location: %szahtevki", STATIC_URL);
         header($redirect);
         exit;
     } else {
         $this->view->render('user/prijava_tezave');
         exit;
     }
     //$this->view->render('user/zahtevki');
     //header($redirect);
     //exit();
 }
Example #10
0
 /**
  * validate - override this to set up your validation rules
  *
  * validate the current objects values either just testing strings/numbers or
  * using the user defined validate{Row name}() methods.
  * will attempt to call $this->validate{column_name}() - expects true = ok  false = ERROR
  * you can the use the validate Class from your own methods.
  *
  * This should really be in a extenal class - eg. DB_DataObject_Validate.
  *
  * @access  public
  * @return  array of validation results or true
  */
 function validate()
 {
     require_once 'Validate.php';
     $table = $this->table();
     $ret = array();
     $seq = $this->sequenceKey();
     foreach ($table as $key => $val) {
         // call user defined validation always...
         $method = "Validate" . ucfirst($key);
         if (method_exists($this, $method)) {
             $ret[$key] = $this->{$method}();
             continue;
         }
         // if not null - and it's not set.......
         if (!isset($this->{$key}) && $val & DB_DATAOBJECT_NOTNULL) {
             // dont check empty sequence key values..
             if ($key == $seq[0] && $seq[1] == true) {
                 continue;
             }
             $ret[$key] = false;
             continue;
         }
         if (is_string($this->{$key}) && strtolower($this->{$key}) == 'null' && $val & DB_DATAOBJECT_NOTNULL) {
             $ret[$key] = false;
             continue;
         }
         // ignore things that are not set. ?
         if (!isset($this->{$key})) {
             continue;
         }
         // if the string is empty.. assume it is ok..
         if (!is_object($this->{$key}) && !is_array($this->{$key}) && !strlen((string) $this->{$key})) {
             continue;
         }
         switch (true) {
             // todo: date time.....
             case $val & DB_DATAOBJECT_STR:
                 $ret[$key] = Validate::string($this->{$key}, VALIDATE_PUNCTUATION . VALIDATE_NAME);
                 continue;
             case $val & DB_DATAOBJECT_INT:
                 $ret[$key] = Validate::number($this->{$key}, array('decimal' => '.'));
                 continue;
         }
     }
     foreach ($ret as $key => $val) {
         if ($val === false) {
             return $ret;
         }
     }
     return true;
     // everything is OK.
 }
Example #11
0
 /**
  * validate the values of the object (usually prior to inserting/updating..)
  *
  * Note: This was always intended as a simple validation routine.
  * It lacks understanding of field length, whether you are inserting or updating (and hence null key values)
  *
  * This should be moved to another class: DB_DataObject_Validate 
  *      FEEL FREE TO SEND ME YOUR VERSION FOR CONSIDERATION!!!
  *
  * Usage:
  * if (is_array($ret = $obj->validate())) { ... there are problems with the data ... }
  *
  * Logic:
  *   - defaults to only testing strings/numbers if numbers or strings are the correct type and null values are correct
  *   - validate Column methods : "validate{ROWNAME}()"  are called if they are defined.
  *            These methods should return 
  *                  true = everything ok
  *                  false|object = something is wrong!
  * 
  *   - This method loads and uses the PEAR Validate Class.
  *
  *
  * @access  public
  * @return  array of validation results (where key=>value, value=false|object if it failed) or true (if they all succeeded)
  */
 function validate()
 {
     global $_DB_DATAOBJECT;
     require_once 'Validate.php';
     $table = $this->table();
     $ret = array();
     $seq = $this->sequenceKey();
     $options = $_DB_DATAOBJECT['CONFIG'];
     foreach ($table as $key => $val) {
         // call user defined validation always...
         $method = "Validate" . ucfirst($key);
         if (method_exists($this, $method)) {
             $ret[$key] = $this->{$method}();
             continue;
         }
         // if not null - and it's not set.......
         if ($val & DB_DATAOBJECT_NOTNULL && DB_DataObject::_is_null($this, $key)) {
             // dont check empty sequence key values..
             if ($key == $seq[0] && $seq[1] == true) {
                 continue;
             }
             $ret[$key] = false;
             continue;
         }
         if (DB_DataObject::_is_null($this, $key)) {
             if ($val & DB_DATAOBJECT_NOTNULL) {
                 $this->debug("'null' field used for '{$key}', but it is defined as NOT NULL", 'VALIDATION', 4);
                 $ret[$key] = false;
                 continue;
             }
             continue;
         }
         // ignore things that are not set. ?
         if (!isset($this->{$key})) {
             continue;
         }
         // if the string is empty.. assume it is ok..
         if (!is_object($this->{$key}) && !is_array($this->{$key}) && !strlen((string) $this->{$key})) {
             continue;
         }
         // dont try and validate cast objects - assume they are problably ok..
         if (is_object($this->{$key}) && is_a($this->{$key}, 'DB_DataObject_Cast')) {
             continue;
         }
         // at this point if you have set something to an object, and it's not expected
         // the Validate will probably break!!... - rightly so! (your design is broken,
         // so issuing a runtime error like PEAR_Error is probably not appropriate..
         switch (true) {
             // todo: date time.....
             case $val & DB_DATAOBJECT_STR:
                 $ret[$key] = Validate::string($this->{$key}, VALIDATE_PUNCTUATION . VALIDATE_NAME);
                 continue;
             case $val & DB_DATAOBJECT_INT:
                 $ret[$key] = Validate::number($this->{$key}, array('decimal' => '.'));
                 continue;
         }
     }
     // if any of the results are false or an object (eg. PEAR_Error).. then return the array..
     foreach ($ret as $key => $val) {
         if ($val !== true) {
             return $ret;
         }
     }
     return true;
     // everything is OK.
 }
Example #12
0
 function isNewNickname($str)
 {
     if (!Validate::string($str, array('min_length' => 1, 'max_length' => 64, 'format' => VALIDATE_NUM . VALIDATE_ALPHA_LOWER))) {
         return false;
     }
     if (!User::allowed_nickname($str)) {
         return false;
     }
     if (User::staticGet('nickname', $str)) {
         return false;
     }
     return true;
 }
 /**
  * Handle a post
  *
  * Validate input and save changes. Reload the form with a success
  * or error message.
  *
  * @return void
  */
 function handlePost()
 {
     // CSRF protection
     $token = $this->trimmed('token');
     if (!$token || $token != common_session_token()) {
         $this->showForm(_('There was a problem with your session token. ' . 'Try again, please.'));
         return;
     }
     if (Event::handle('StartProfileSaveForm', array($this))) {
         $nickname = $this->trimmed('nickname');
         $fullname = $this->trimmed('fullname');
         $homepage = $this->trimmed('homepage');
         $bio = $this->trimmed('bio');
         $location = $this->trimmed('location');
         $autosubscribe = $this->boolean('autosubscribe');
         $language = $this->trimmed('language');
         $timezone = $this->trimmed('timezone');
         $tagstring = $this->trimmed('tags');
         // Some validation
         if (!Validate::string($nickname, array('min_length' => 1, 'max_length' => 64, 'format' => NICKNAME_FMT))) {
             $this->showForm(_('Nickname must have only lowercase letters and numbers and no spaces.'));
             return;
         } else {
             if (!User::allowed_nickname($nickname)) {
                 $this->showForm(_('Not a valid nickname.'));
                 return;
             } else {
                 if (!is_null($homepage) && strlen($homepage) > 0 && !Validate::uri($homepage, array('allowed_schemes' => array('http', 'https')))) {
                     $this->showForm(_('Homepage is not a valid URL.'));
                     return;
                 } else {
                     if (!is_null($fullname) && mb_strlen($fullname) > 255) {
                         $this->showForm(_('Full name is too long (max 255 chars).'));
                         return;
                     } else {
                         if (Profile::bioTooLong($bio)) {
                             $this->showForm(sprintf(_('Bio is too long (max %d chars).'), Profile::maxBio()));
                             return;
                         } else {
                             if (!is_null($location) && mb_strlen($location) > 255) {
                                 $this->showForm(_('Location is too long (max 255 chars).'));
                                 return;
                             } else {
                                 if (is_null($timezone) || !in_array($timezone, DateTimeZone::listIdentifiers())) {
                                     $this->showForm(_('Timezone not selected.'));
                                     return;
                                 } else {
                                     if ($this->nicknameExists($nickname)) {
                                         $this->showForm(_('Nickname already in use. Try another one.'));
                                         return;
                                     } else {
                                         if (!is_null($language) && strlen($language) > 50) {
                                             $this->showForm(_('Language is too long (max 50 chars).'));
                                             return;
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
         if ($tagstring) {
             $tags = array_map('common_canonical_tag', preg_split('/[\\s,]+/', $tagstring));
         } else {
             $tags = array();
         }
         foreach ($tags as $tag) {
             if (!common_valid_profile_tag($tag)) {
                 $this->showForm(sprintf(_('Invalid tag: "%s"'), $tag));
                 return;
             }
         }
         $user = common_current_user();
         $user->query('BEGIN');
         if ($user->nickname != $nickname || $user->language != $language || $user->timezone != $timezone) {
             common_debug('Updating user nickname from ' . $user->nickname . ' to ' . $nickname, __FILE__);
             common_debug('Updating user language from ' . $user->language . ' to ' . $language, __FILE__);
             common_debug('Updating user timezone from ' . $user->timezone . ' to ' . $timezone, __FILE__);
             $original = clone $user;
             $user->nickname = $nickname;
             $user->language = $language;
             $user->timezone = $timezone;
             $result = $user->updateKeys($original);
             if ($result === false) {
                 common_log_db_error($user, 'UPDATE', __FILE__);
                 $this->serverError(_('Couldn\'t update user.'));
                 return;
             } else {
                 // Re-initialize language environment if it changed
                 common_init_language();
                 // Clear the site owner, in case nickname changed
                 if ($user->hasRole(Profile_role::OWNER)) {
                     User::blow('user:site_owner');
                 }
             }
         }
         // XXX: XOR
         if ($user->autosubscribe ^ $autosubscribe) {
             $original = clone $user;
             $user->autosubscribe = $autosubscribe;
             $result = $user->update($original);
             if ($result === false) {
                 common_log_db_error($user, 'UPDATE', __FILE__);
                 $this->serverError(_('Couldn\'t update user for autosubscribe.'));
                 return;
             }
         }
         $profile = $user->getProfile();
         $orig_profile = clone $profile;
         $profile->nickname = $user->nickname;
         $profile->fullname = $fullname;
         $profile->homepage = $homepage;
         $profile->bio = $bio;
         $profile->location = $location;
         $loc = Location::fromName($location);
         if (empty($loc)) {
             $profile->lat = null;
             $profile->lon = null;
             $profile->location_id = null;
             $profile->location_ns = null;
         } else {
             $profile->lat = $loc->lat;
             $profile->lon = $loc->lon;
             $profile->location_id = $loc->location_id;
             $profile->location_ns = $loc->location_ns;
         }
         $profile->profileurl = common_profile_url($nickname);
         if (common_config('location', 'share') == 'user') {
             $exists = false;
             $prefs = User_location_prefs::staticGet('user_id', $user->id);
             if (empty($prefs)) {
                 $prefs = new User_location_prefs();
                 $prefs->user_id = $user->id;
                 $prefs->created = common_sql_now();
             } else {
                 $exists = true;
                 $orig = clone $prefs;
             }
             $prefs->share_location = $this->boolean('sharelocation');
             if ($exists) {
                 $result = $prefs->update($orig);
             } else {
                 $result = $prefs->insert();
             }
             if ($result === false) {
                 common_log_db_error($prefs, $exists ? 'UPDATE' : 'INSERT', __FILE__);
                 $this->serverError(_('Couldn\'t save location prefs.'));
                 return;
             }
         }
         common_debug('Old profile: ' . common_log_objstring($orig_profile), __FILE__);
         common_debug('New profile: ' . common_log_objstring($profile), __FILE__);
         $result = $profile->update($orig_profile);
         if ($result === false) {
             common_log_db_error($profile, 'UPDATE', __FILE__);
             $this->serverError(_('Couldn\'t save profile.'));
             return;
         }
         // Set the user tags
         $result = $user->setSelfTags($tags);
         if (!$result) {
             $this->serverError(_('Couldn\'t save tags.'));
             return;
         }
         $user->query('COMMIT');
         Event::handle('EndProfileSaveForm', array($this));
         common_broadcast_profile($profile);
         $this->showForm(_('Settings saved.'), true);
     }
 }
Example #14
0
 /** Validate the order amount currency
  *
  * The abbrivation for a currency, usually 2-3 chars
  *
  * @access private
  * @return boolean true if valid, false otherwise
  */
 function _validateCurrency()
 {
     return Validate::string($this->currency, array('format' => VALIDATE_ALPHA_UPPER, 'min_length' => 2, 'max_length' => 3));
 }
Example #15
0
 function trySave()
 {
     $nickname = $this->trimmed('nickname');
     $fullname = $this->trimmed('fullname');
     $homepage = $this->trimmed('homepage');
     $description = $this->trimmed('description');
     $location = $this->trimmed('location');
     $aliasstring = $this->trimmed('aliases');
     if (!Validate::string($nickname, array('min_length' => 1, 'max_length' => 64, 'format' => NICKNAME_FMT))) {
         $this->showForm(_('Nickname must have only lowercase letters ' . 'and numbers and no spaces.'));
         return;
     } else {
         if ($this->nicknameExists($nickname)) {
             $this->showForm(_('Nickname already in use. Try another one.'));
             return;
         } else {
             if (!User_group::allowedNickname($nickname)) {
                 $this->showForm(_('Not a valid nickname.'));
                 return;
             } else {
                 if (!is_null($homepage) && strlen($homepage) > 0 && !Validate::uri($homepage, array('allowed_schemes' => array('http', 'https')))) {
                     $this->showForm(_('Homepage is not a valid URL.'));
                     return;
                 } else {
                     if (!is_null($fullname) && mb_strlen($fullname) > 255) {
                         $this->showForm(_('Full name is too long (max 255 chars).'));
                         return;
                     } else {
                         if (User_group::descriptionTooLong($description)) {
                             $this->showForm(sprintf(_('description is too long (max %d chars).'), User_group::maxDescription()));
                             return;
                         } else {
                             if (!is_null($location) && mb_strlen($location) > 255) {
                                 $this->showForm(_('Location is too long (max 255 chars).'));
                                 return;
                             }
                         }
                     }
                 }
             }
         }
     }
     if (!empty($aliasstring)) {
         $aliases = array_map('common_canonical_nickname', array_unique(preg_split('/[\\s,]+/', $aliasstring)));
     } else {
         $aliases = array();
     }
     if (count($aliases) > common_config('group', 'maxaliases')) {
         $this->showForm(sprintf(_('Too many aliases! Maximum %d.'), common_config('group', 'maxaliases')));
         return;
     }
     foreach ($aliases as $alias) {
         if (!Validate::string($alias, array('min_length' => 1, 'max_length' => 64, 'format' => NICKNAME_FMT))) {
             $this->showForm(sprintf(_('Invalid alias: "%s"'), $alias));
             return;
         }
         if ($this->nicknameExists($alias)) {
             $this->showForm(sprintf(_('Alias "%s" already in use. Try another one.'), $alias));
             return;
         }
         // XXX assumes alphanum nicknames
         if (strcmp($alias, $nickname) == 0) {
             $this->showForm(_('Alias can\'t be the same as nickname.'));
             return;
         }
     }
     $mainpage = common_local_url('showgroup', array('nickname' => $nickname));
     $cur = common_current_user();
     // Checked in prepare() above
     assert(!is_null($cur));
     $group = User_group::register(array('nickname' => $nickname, 'fullname' => $fullname, 'homepage' => $homepage, 'description' => $description, 'location' => $location, 'aliases' => $aliases, 'userid' => $cur->id, 'mainpage' => $mainpage, 'local' => true));
     common_redirect($group->homeUrl(), 303);
 }
Example #16
0
 function validateOmb(&$req)
 {
     foreach (array('omb_version', 'omb_listener', 'omb_listenee', 'omb_listenee_profile', 'omb_listenee_nickname', 'omb_listenee_license') as $param) {
         if (is_null($req->get_parameter($param))) {
             throw new OAuthException("Required parameter '{$param}' not found");
         }
     }
     # Now, OMB stuff
     $version = $req->get_parameter('omb_version');
     if ($version != OMB_VERSION_01) {
         throw new OAuthException("OpenMicroBlogging version '{$version}' not supported");
     }
     $listener = $req->get_parameter('omb_listener');
     $user = User::staticGet('uri', $listener);
     if (!$user) {
         throw new OAuthException("Listener URI '{$listener}' not found here");
     }
     $cur = common_current_user();
     if ($cur->id != $user->id) {
         throw new OAuthException("Can't add for another user!");
     }
     $listenee = $req->get_parameter('omb_listenee');
     if (!Validate::uri($listenee) && !common_valid_tag($listenee)) {
         throw new OAuthException("Listenee URI '{$listenee}' not a recognizable URI");
     }
     if (strlen($listenee) > 255) {
         throw new OAuthException("Listenee URI '{$listenee}' too long");
     }
     $other = User::staticGet('uri', $listenee);
     if ($other) {
         throw new OAuthException("Listenee URI '{$listenee}' is local user");
     }
     $remote = Remote_profile::staticGet('uri', $listenee);
     if ($remote) {
         $sub = new Subscription();
         $sub->subscriber = $user->id;
         $sub->subscribed = $remote->id;
         if ($sub->find(true)) {
             throw new OAuthException("Already subscribed to user!");
         }
     }
     $nickname = $req->get_parameter('omb_listenee_nickname');
     if (!Validate::string($nickname, array('min_length' => 1, 'max_length' => 64, 'format' => VALIDATE_NUM . VALIDATE_ALPHA_LOWER))) {
         throw new OAuthException('Nickname must have only letters and numbers and no spaces.');
     }
     $profile = $req->get_parameter('omb_listenee_profile');
     if (!common_valid_http_url($profile)) {
         throw new OAuthException("Invalid profile URL '{$profile}'.");
     }
     if ($profile == common_local_url('showstream', array('nickname' => $nickname))) {
         throw new OAuthException("Profile URL '{$profile}' is for a local user.");
     }
     $license = $req->get_parameter('omb_listenee_license');
     if (!common_valid_http_url($license)) {
         throw new OAuthException("Invalid license URL '{$license}'.");
     }
     $site_license = common_config('license', 'url');
     if (!common_compatible_license($license, $site_license)) {
         throw new OAuthException("Listenee stream license '{$license}' not compatible with site license '{$site_license}'.");
     }
     # optional stuff
     $fullname = $req->get_parameter('omb_listenee_fullname');
     if ($fullname && mb_strlen($fullname) > 255) {
         throw new OAuthException("Full name '{$fullname}' too long.");
     }
     $homepage = $req->get_parameter('omb_listenee_homepage');
     if ($homepage && (!common_valid_http_url($homepage) || mb_strlen($homepage) > 255)) {
         throw new OAuthException("Invalid homepage '{$homepage}'");
     }
     $bio = $req->get_parameter('omb_listenee_bio');
     if ($bio && mb_strlen($bio) > 140) {
         throw new OAuthException("Bio too long '{$bio}'");
     }
     $location = $req->get_parameter('omb_listenee_location');
     if ($location && mb_strlen($location) > 255) {
         throw new OAuthException("Location too long '{$location}'");
     }
     $avatar = $req->get_parameter('omb_listenee_avatar');
     if ($avatar) {
         if (!common_valid_http_url($avatar) || strlen($avatar) > 255) {
             throw new OAuthException("Invalid avatar URL '{$avatar}'");
         }
         $size = @getimagesize($avatar);
         if (!$size) {
             throw new OAuthException("Can't read avatar URL '{$avatar}'");
         }
         if ($size[0] != AVATAR_PROFILE_SIZE || $size[1] != AVATAR_PROFILE_SIZE) {
             throw new OAuthException("Wrong size image at '{$avatar}'");
         }
         if (!in_array($size[2], array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG))) {
             throw new OAuthException("Wrong image type for '{$avatar}'");
         }
     }
     $callback = $req->get_parameter('oauth_callback');
     if ($callback && !common_valid_http_url($callback)) {
         throw new OAuthException("Invalid callback URL '{$callback}'");
     }
     if ($callback && $callback == common_local_url('finishremotesubscribe')) {
         throw new OAuthException("Callback URL '{$callback}' is for local site.");
     }
 }
Example #17
0
 /**
  * Associate a Twitter account with the user's account
  *
  * Validates post input; verifies it against Twitter; and if
  * successful stores in the database.
  *
  * @return void
  */
 function addTwitterAccount()
 {
     $screen_name = $this->trimmed('twitter_username');
     $password = $this->trimmed('twitter_password');
     $noticesync = $this->boolean('noticesync');
     $replysync = $this->boolean('replysync');
     $friendsync = $this->boolean('friendsync');
     if (!Validate::string($screen_name, array('min_length' => 1, 'max_length' => 15, 'format' => VALIDATE_NUM . VALIDATE_ALPHA . '_'))) {
         $this->showForm(_('Username must have only numbers, ' . 'upper- and lowercase letters, ' . 'and underscore (_). 15 chars max.'));
         return;
     }
     if (!$this->verifyCredentials($screen_name, $password)) {
         $this->showForm(_('Could not verify your Twitter credentials!'));
         return;
     }
     $twit_user = twitter_user_info($screen_name, $password);
     if (!$twit_user) {
         $this->showForm(sprintf(_('Unable to retrieve account information ' . 'For "%s" from Twitter.'), $screen_name));
         return;
     }
     if (!save_twitter_user($twit_user->id, $screen_name)) {
         $this->showForm(_('Unable to save your Twitter settings!'));
         return;
     }
     $user = common_current_user();
     $flink = new Foreign_link();
     $flink->user_id = $user->id;
     $flink->foreign_id = $twit_user->id;
     $flink->service = TWITTER_SERVICE;
     $flink->credentials = $password;
     $flink->created = common_sql_now();
     $flink->set_flags($noticesync, $replysync, $friendsync);
     $flink_id = $flink->insert();
     if (!$flink_id) {
         common_log_db_error($flink, 'INSERT', __FILE__);
         $this->showForm(_('Unable to save your Twitter settings!'));
         return;
     }
     if ($friendsync) {
         save_twitter_friends($user, $twit_user->id, $screen_name, $password);
     }
     $this->showForm(_('Twitter settings saved.'), true);
 }
Example #18
0
 /**
  * validate - override this to set up your validation rules
  *
  * validate the current objects values either just testing strings/numbers or
  * using the user defined validate{Row name}() methods.
  * will attempt to call $this->validate{column_name}() - expects true = ok  false = ERROR
  * you can the use the validate Class from your own methods.
  *
  * @access  public
  * @return  array of validation results or true
  */
 function validate()
 {
     require_once 'Validate.php';
     $table =& $this->_get_table();
     $ret = array();
     foreach ($table as $key => $val) {
         // ignore things that are not set. ?
         if (!isset($this->{$key})) {
             continue;
         }
         // call user defined validation
         $method = "Validate" . ucfirst($key);
         if (method_exists($this, $method)) {
             $ret[$key] = $this->{$method}();
             continue;
         }
         // if the string is empty.. assume it is ok..
         if (!strlen($this->{$key})) {
             continue;
         }
         switch ($val) {
             case DB_DATAOBJECT_STR:
                 $ret[$key] = Validate::string($this->{$key}, VALIDATE_PUNCTUATION . VALIDATE_NAME);
                 continue;
             case DB_DATAOBJECT_INT:
                 $ret[$key] = Validate::number($this->{$key}, array('decimal' => '.'));
                 continue;
         }
     }
     foreach ($ret as $key => $val) {
         if ($val == false) {
             return $ret;
         }
     }
     return true;
     // everything is OK.
 }
Example #19
0
 /**
  * Handle a post
  *
  * Validate input and save changes. Reload the form with a success
  * or error message.
  *
  * @return void
  */
 function handlePost()
 {
     # CSRF protection
     $token = $this->trimmed('token');
     if (!$token || $token != common_session_token()) {
         $this->showForm(_('There was a problem with your session token. ' . 'Try again, please.'));
         return;
     }
     $nickname = $this->trimmed('nickname');
     $fullname = $this->trimmed('fullname');
     $homepage = $this->trimmed('homepage');
     $bio = $this->trimmed('bio');
     $location = $this->trimmed('location');
     $autosubscribe = $this->boolean('autosubscribe');
     $language = $this->trimmed('language');
     $timezone = $this->trimmed('timezone');
     $tagstring = $this->trimmed('tags');
     # Some validation
     if (!Validate::string($nickname, array('min_length' => 1, 'max_length' => 64, 'format' => VALIDATE_NUM . VALIDATE_ALPHA_LOWER))) {
         $this->showForm(_('Nickname must have only lowercase letters and numbers and no spaces.'));
         return;
     } else {
         if (!User::allowed_nickname($nickname)) {
             $this->showForm(_('Not a valid nickname.'));
             return;
         } else {
             if (!is_null($homepage) && strlen($homepage) > 0 && !Validate::uri($homepage, array('allowed_schemes' => array('http', 'https')))) {
                 $this->showForm(_('Homepage is not a valid URL.'));
                 return;
             } else {
                 if (!is_null($fullname) && mb_strlen($fullname) > 255) {
                     $this->showForm(_('Full name is too long (max 255 chars).'));
                     return;
                 } else {
                     if (!is_null($bio) && mb_strlen($bio) > 140) {
                         $this->showForm(_('Bio is too long (max 140 chars).'));
                         return;
                     } else {
                         if (!is_null($location) && mb_strlen($location) > 255) {
                             $this->showForm(_('Location is too long (max 255 chars).'));
                             return;
                         } else {
                             if (is_null($timezone) || !in_array($timezone, DateTimeZone::listIdentifiers())) {
                                 $this->showForm(_('Timezone not selected.'));
                                 return;
                             } else {
                                 if ($this->nicknameExists($nickname)) {
                                     $this->showForm(_('Nickname already in use. Try another one.'));
                                     return;
                                 } else {
                                     if (!is_null($language) && strlen($language) > 50) {
                                         $this->showForm(_('Language is too long (max 50 chars).'));
                                         return;
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     if ($tagstring) {
         $tags = array_map('common_canonical_tag', preg_split('/[\\s,]+/', $tagstring));
     } else {
         $tags = array();
     }
     foreach ($tags as $tag) {
         if (!common_valid_profile_tag($tag)) {
             $this->showForm(sprintf(_('Invalid tag: "%s"'), $tag));
             return;
         }
     }
     $user = common_current_user();
     $user->query('BEGIN');
     if ($user->nickname != $nickname || $user->language != $language || $user->timezone != $timezone) {
         common_debug('Updating user nickname from ' . $user->nickname . ' to ' . $nickname, __FILE__);
         common_debug('Updating user language from ' . $user->language . ' to ' . $language, __FILE__);
         common_debug('Updating user timezone from ' . $user->timezone . ' to ' . $timezone, __FILE__);
         $original = clone $user;
         $user->nickname = $nickname;
         $user->language = $language;
         $user->timezone = $timezone;
         $result = $user->updateKeys($original);
         if ($result === false) {
             common_log_db_error($user, 'UPDATE', __FILE__);
             $this->serverError(_('Couldn\'t update user.'));
             return;
         } else {
             # Re-initialize language environment if it changed
             common_init_language();
         }
     }
     # XXX: XOR
     if ($user->autosubscribe ^ $autosubscribe) {
         $original = clone $user;
         $user->autosubscribe = $autosubscribe;
         $result = $user->update($original);
         if ($result === false) {
             common_log_db_error($user, 'UPDATE', __FILE__);
             $this->serverError(_('Couldn\'t update user for autosubscribe.'));
             return;
         }
     }
     $profile = $user->getProfile();
     $orig_profile = clone $profile;
     $profile->nickname = $user->nickname;
     $profile->fullname = $fullname;
     $profile->homepage = $homepage;
     $profile->bio = $bio;
     $profile->location = $location;
     $profile->profileurl = common_profile_url($nickname);
     common_debug('Old profile: ' . common_log_objstring($orig_profile), __FILE__);
     common_debug('New profile: ' . common_log_objstring($profile), __FILE__);
     $result = $profile->update($orig_profile);
     if (!$result) {
         common_log_db_error($profile, 'UPDATE', __FILE__);
         $this->serverError(_('Couldn\'t save profile.'));
         return;
     }
     # Set the user tags
     $result = $user->setSelfTags($tags);
     if (!$result) {
         $this->serverError(_('Couldn\'t save tags.'));
         return;
     }
     $user->query('COMMIT');
     common_broadcast_profile($profile);
     $this->showForm(_('Settings saved.'), true);
 }
Example #20
0
 /** Validate the order amount currency
  *
  * The abbrivation for a currency, usually 2-3 chars
  *
  * @access private
  * @return boolean true if valid, false otherwise
  */
 function _validateCurrency()
 {
     $result = Validate::string($this->currency, array('format' => VALIDATE_ALPHA_UPPER, 'min_length' => 2, 'max_length' => 3));
     if (!$result) {
         throw new Payment_Process2_Exception("Invalid currency");
     }
     return true;
 }
Example #21
0
 /**
  * Validate the customer id
  *
  * Customer id must be a 15-character long alphanumeric string.
  *
  * @return bool
  * @throws Payment_Process2_Exception
  */
 function _validateCustomerId()
 {
     $options = array('format' => VALIDATE_NUM . VALIDATE_ALPHA, 'min_length' => 15, 'max_length' => 15);
     if (!Validate::string($this->customerId, $options)) {
         throw new Payment_Process2_Exception("Invalid customerId");
     }
     return true;
 }
Example #22
0
 function trySave()
 {
     $cur = common_current_user();
     if (!$cur->isAdmin($this->group)) {
         $this->clientError(_('You must be an admin to edit the group'), 403);
         return;
     }
     $nickname = common_canonical_nickname($this->trimmed('nickname'));
     $fullname = $this->trimmed('fullname');
     $homepage = $this->trimmed('homepage');
     $description = $this->trimmed('description');
     $location = $this->trimmed('location');
     if (!Validate::string($nickname, array('min_length' => 1, 'max_length' => 64, 'format' => NICKNAME_FMT))) {
         $this->showForm(_('Nickname must have only lowercase letters ' . 'and numbers and no spaces.'));
         return;
     } else {
         if ($this->nicknameExists($nickname)) {
             $this->showForm(_('Nickname already in use. Try another one.'));
             return;
         } else {
             if (!User_group::allowedNickname($nickname)) {
                 $this->showForm(_('Not a valid nickname.'));
                 return;
             } else {
                 if (!is_null($homepage) && strlen($homepage) > 0 && !Validate::uri($homepage, array('allowed_schemes' => array('http', 'https')))) {
                     $this->showForm(_('Homepage is not a valid URL.'));
                     return;
                 } else {
                     if (!is_null($fullname) && mb_strlen($fullname) > 255) {
                         $this->showForm(_('Full name is too long (max 255 chars).'));
                         return;
                     } else {
                         if (!is_null($description) && mb_strlen($description) > 140) {
                             $this->showForm(_('description is too long (max 140 chars).'));
                             return;
                         } else {
                             if (!is_null($location) && mb_strlen($location) > 255) {
                                 $this->showForm(_('Location is too long (max 255 chars).'));
                                 return;
                             }
                         }
                     }
                 }
             }
         }
     }
     $orig = clone $this->group;
     $this->group->nickname = $nickname;
     $this->group->fullname = $fullname;
     $this->group->homepage = $homepage;
     $this->group->description = $description;
     $this->group->location = $location;
     $this->group->created = common_sql_now();
     $result = $this->group->update($orig);
     if (!$result) {
         common_log_db_error($this->group, 'UPDATE', __FILE__);
         $this->serverError(_('Could not update group.'));
     }
     if ($this->group->nickname != $orig->nickname) {
         common_redirect(common_local_url('editgroup', array('nickname' => $nickname)), 307);
     } else {
         $this->showForm(_('Options saved.'));
     }
 }
Example #23
0
 /**
  * Validate the invoice number.
  *
  * Invoice no. must be a 15-character long alphanumeric string.
  *
  * @return boolean true on success, false otherwise
  */
 function _validateCustomerId()
 {
     return Validate::string($this->customerId, array('format' => VALIDATE_NUM . VALIDATE_ALPHA, 'min_length' => 15, 'max_length' => 15));
 }
 public function dodaj($arg = false)
 {
     echo "Dodajam..";
     //get user id
     Session::init();
     $userid = Session::get('userid');
     $level = Session::get("level");
     if ($userid == "" || $level < 2) {
         $redirect = sprintf("location: %sprijava", STATIC_URL);
         header($redirect);
         exit;
     }
     //parse POST variables add validation here
     $kratek_opis = $_POST['kratek_opis'];
     $datum = $_POST['date'];
     $podrocje = $_POST['podrocje'];
     $opis = $_POST['opis'];
     $tel = $_POST['tel'];
     $user = $_POST['username'];
     $closed = $_POST['closed'];
     $expert = $_POST['expert'];
     //echo $kratek_opis, $datum, $podrocje, $opis, $tel, $userid;
     //exit();
     //validate
     $validate = new Validate();
     if ($validate->string($user) != 1) {
         $validation = "failed";
         $this->view->errors['user'] = "******";
     }
     if ($validate->string($kratek_opis) != 1) {
         $validation = "failed";
         $this->view->errors['kratek_opis'] = "Vnesite naslov težave";
     }
     if (!$validate->date($datum, 'm/d/Y')) {
         $validation = "failed";
         $this->view->errors['datum'] = "Izberite datum";
     }
     if ($validate->string($podrocje) != 1) {
         $validation = "failed";
         $this->view->errors['podrocje'] = "Vnesite področje na katerem imate težavo";
     }
     if ($validate->string($opis) != 1) {
         $validation = "failed";
         $this->view->errors['opis'] = "Vnesite opis vaše težave";
     }
     if ($validate->phone($tel) != 1) {
         $validation = "failed";
         $this->view->errors['tel'] = "Telefonska številka ni prave oblike";
     }
     /*samples
       var_dump($validate->email('*****@*****.**'));
       var_dump($validate->phone('031 772-079'));
       var_dump($validate->date('01/30/2014'));
       var_dump($validate->date('30/01/2012', 'd/m/Y'));
       var_dump($validate->string('test'));*/
     //$validation = "failed";
     $validation = "succeded";
     if ($validation == "failed") {
         $this->view->values['username'] = $user;
         $this->view->values['kratek_opis'] = $kratek_opis;
         $this->view->values['datum'] = $datum;
         $this->view->values['podrocje'] = $podrocje;
         $this->view->values['opis'] = $opis;
         $this->view->values['tel'] = $tel;
         $this->view->render('admin/prijava_tezave');
         exit;
     }
     //set values
     if ($expert == "Da") {
         $level = 3;
     }
     if ($closed) {
         $state = "4";
     } else {
         $state = "2";
     }
     //get user id from username
     require 'models/zahtevki.php';
     $model = new Zahtevki_Model();
     $userinfo = $model->uporabnik_id($user);
     //print_r($userinfo);
     $callerid = $userinfo[0]['userid'];
     //$callerid=1;
     //$state="3";
     //echo "inserting into db";
     //echo $level, $userid, $callerid;
     //exit();
     //insert into database
     //inicialize model
     require 'models/prijava_tezave.php';
     $model = new Prijava_Tezave_Model();
     //$kratek_opis, $datum, $podrocje, $opis, $tel, $userid, $adminid='NONE', $level=2, $state="1"
     $this->view->result = $model->dodaj($kratek_opis, $datum, $podrocje, $opis, $tel, $callerid, $level, $state, $userid);
     if ($this->view->result == 1) {
         //$this->view->msg="Zahtevek uspešno dodan.";
         //$this->view->render('user/zahtevki');
         $redirect = sprintf("location: %szahtevki_admin", STATIC_URL);
         header($redirect);
         exit;
     } else {
         $this->view->render('admin/prijava_tezave');
         exit;
     }
     //$this->view->render('user/zahtevki');
     //header($redirect);
     //exit();
 }
Example #25
0
 /**
  * Validate params for the new group
  *
  * @return void
  */
 function validateParams()
 {
     $valid = Validate::string($this->nickname, array('min_length' => 1, 'max_length' => 64, 'format' => NICKNAME_FMT));
     if (!$valid) {
         $this->clientError(_('Nickname must have only lowercase letters ' . 'and numbers and no spaces.'), 403, $this->format);
         return false;
     } elseif ($this->groupNicknameExists($this->nickname)) {
         $this->clientError(_('Nickname already in use. Try another one.'), 403, $this->format);
         return false;
     } else {
         if (!User_group::allowedNickname($this->nickname)) {
             $this->clientError(_('Not a valid nickname.'), 403, $this->format);
             return false;
         } elseif (!is_null($this->homepage) && strlen($this->homepage) > 0 && !Validate::uri($this->homepage, array('allowed_schemes' => array('http', 'https')))) {
             $this->clientError(_('Homepage is not a valid URL.'), 403, $this->format);
             return false;
         } elseif (!is_null($this->fullname) && mb_strlen($this->fullname) > 255) {
             $this->clientError(_('Full name is too long (maximum 255 characters).'), 403, $this->format);
             return false;
         } elseif (User_group::descriptionTooLong($this->description)) {
             $this->clientError(sprintf(_m('Description is too long (maximum %d character).', 'Description is too long (maximum %d characters).', User_group::maxDescription()), User_group::maxDescription()), 403, $this->format);
             return false;
         } elseif (!is_null($this->location) && mb_strlen($this->location) > 255) {
             $this->clientError(_('Location is too long (maximum 255 characters).'), 403, $this->format);
             return false;
         }
     }
     if (!empty($this->aliasstring)) {
         $this->aliases = array_map('common_canonical_nickname', array_unique(preg_split('/[\\s,]+/', $this->aliasstring)));
     } else {
         $this->aliases = array();
     }
     if (count($this->aliases) > common_config('group', 'maxaliases')) {
         $this->clientError(sprintf(_m('Too many aliases! Maximum %d allowed.', 'Too many aliases! Maximum %d allowed.', common_config('group', 'maxaliases')), common_config('group', 'maxaliases')), 403, $this->format);
         return false;
     }
     foreach ($this->aliases as $alias) {
         $valid = Validate::string($alias, array('min_length' => 1, 'max_length' => 64, 'format' => NICKNAME_FMT));
         if (!$valid) {
             $this->clientError(sprintf(_('Invalid alias: "%s".'), $alias), 403, $this->format);
             return false;
         }
         if ($this->groupNicknameExists($alias)) {
             $this->clientError(sprintf(_('Alias "%s" already in use. Try another one.'), $alias), 403, $this->format);
             return false;
         }
         // XXX assumes alphanum nicknames
         if (strcmp($alias, $this->nickname) == 0) {
             $this->clientError(_('Alias can\'t be the same as nickname.'), 403, $this->format);
             return false;
         }
     }
     // Everything looks OK
     return true;
 }
Example #26
0
 function trySave()
 {
     $nickname = $this->trimmed('nickname');
     $fullname = $this->trimmed('fullname');
     $homepage = $this->trimmed('homepage');
     $description = $this->trimmed('description');
     $location = $this->trimmed('location');
     if (!Validate::string($nickname, array('min_length' => 1, 'max_length' => 64, 'format' => NICKNAME_FMT))) {
         $this->showForm(_('Nickname must have only lowercase letters ' . 'and numbers and no spaces.'));
         return;
     } else {
         if ($this->nicknameExists($nickname)) {
             $this->showForm(_('Nickname already in use. Try another one.'));
             return;
         } else {
             if (!User_group::allowedNickname($nickname)) {
                 $this->showForm(_('Not a valid nickname.'));
                 return;
             } else {
                 if (!is_null($homepage) && strlen($homepage) > 0 && !Validate::uri($homepage, array('allowed_schemes' => array('http', 'https')))) {
                     $this->showForm(_('Homepage is not a valid URL.'));
                     return;
                 } else {
                     if (!is_null($fullname) && mb_strlen($fullname) > 255) {
                         $this->showForm(_('Full name is too long (max 255 chars).'));
                         return;
                     } else {
                         if (!is_null($description) && mb_strlen($description) > 140) {
                             $this->showForm(_('description is too long (max 140 chars).'));
                             return;
                         } else {
                             if (!is_null($location) && mb_strlen($location) > 255) {
                                 $this->showForm(_('Location is too long (max 255 chars).'));
                                 return;
                             }
                         }
                     }
                 }
             }
         }
     }
     $cur = common_current_user();
     // Checked in prepare() above
     assert(!is_null($cur));
     $group = new User_group();
     $group->query('BEGIN');
     $group->nickname = $nickname;
     $group->fullname = $fullname;
     $group->homepage = $homepage;
     $group->description = $description;
     $group->location = $location;
     $group->created = common_sql_now();
     $result = $group->insert();
     if (!$result) {
         common_log_db_error($group, 'INSERT', __FILE__);
         $this->serverError(_('Could not create group.'));
     }
     $member = new Group_member();
     $member->group_id = $group->id;
     $member->profile_id = $cur->id;
     $member->is_admin = 1;
     $member->created = $group->created;
     $result = $member->insert();
     if (!$result) {
         common_log_db_error($member, 'INSERT', __FILE__);
         $this->serverError(_('Could not set group membership.'));
     }
     $group->query('COMMIT');
     common_redirect($group->homeUrl(), 307);
 }
Example #27
0
 function isNewNickname($str)
 {
     if (!Validate::string($str, array('min_length' => 1, 'max_length' => 64, 'format' => NICKNAME_FMT))) {
         return false;
     }
     if (!User::allowed_nickname($str)) {
         return false;
     }
     if (User::staticGet('nickname', $str)) {
         return false;
     }
     return true;
 }
 public function testString($value, $rules)
 {
     if (!Validate::string($value, $rules)) {
         array_push($this->errorCollection, 'password_error');
         $this->context->smarty->assign('passwordError', 'error');
         return false;
     }
     return true;
 }
Example #29
0
 function trySave()
 {
     $cur = common_current_user();
     if (!$cur->isAdmin($this->group)) {
         $this->clientError(_('You must be an admin to edit the group.'), 403);
         return;
     }
     $nickname = common_canonical_nickname($this->trimmed('nickname'));
     $fullname = $this->trimmed('fullname');
     $homepage = $this->trimmed('homepage');
     $description = $this->trimmed('description');
     $location = $this->trimmed('location');
     $aliasstring = $this->trimmed('aliases');
     if (!Validate::string($nickname, array('min_length' => 1, 'max_length' => 64, 'format' => NICKNAME_FMT))) {
         $this->showForm(_('Nickname must have only lowercase letters ' . 'and numbers and no spaces.'));
         return;
     } else {
         if ($this->nicknameExists($nickname)) {
             $this->showForm(_('Nickname already in use. Try another one.'));
             return;
         } else {
             if (!User_group::allowedNickname($nickname)) {
                 $this->showForm(_('Not a valid nickname.'));
                 return;
             } else {
                 if (!is_null($homepage) && strlen($homepage) > 0 && !Validate::uri($homepage, array('allowed_schemes' => array('http', 'https')))) {
                     $this->showForm(_('Homepage is not a valid URL.'));
                     return;
                 } else {
                     if (!is_null($fullname) && mb_strlen($fullname) > 255) {
                         $this->showForm(_('Full name is too long (max 255 chars).'));
                         return;
                     } else {
                         if (User_group::descriptionTooLong($description)) {
                             $this->showForm(sprintf(_('description is too long (max %d chars).'), User_group::maxDescription()));
                             return;
                         } else {
                             if (!is_null($location) && mb_strlen($location) > 255) {
                                 $this->showForm(_('Location is too long (max 255 chars).'));
                                 return;
                             }
                         }
                     }
                 }
             }
         }
     }
     if (!empty($aliasstring)) {
         $aliases = array_map('common_canonical_nickname', array_unique(preg_split('/[\\s,]+/', $aliasstring)));
     } else {
         $aliases = array();
     }
     if (count($aliases) > common_config('group', 'maxaliases')) {
         $this->showForm(sprintf(_('Too many aliases! Maximum %d.'), common_config('group', 'maxaliases')));
         return;
     }
     foreach ($aliases as $alias) {
         if (!Validate::string($alias, array('min_length' => 1, 'max_length' => 64, 'format' => NICKNAME_FMT))) {
             $this->showForm(sprintf(_('Invalid alias: "%s"'), $alias));
             return;
         }
         if ($this->nicknameExists($alias)) {
             $this->showForm(sprintf(_('Alias "%s" already in use. Try another one.'), $alias));
             return;
         }
         // XXX assumes alphanum nicknames
         if (strcmp($alias, $nickname) == 0) {
             $this->showForm(_('Alias can\'t be the same as nickname.'));
             return;
         }
     }
     $this->group->query('BEGIN');
     $orig = clone $this->group;
     $this->group->nickname = $nickname;
     $this->group->fullname = $fullname;
     $this->group->homepage = $homepage;
     $this->group->description = $description;
     $this->group->location = $location;
     $this->group->mainpage = common_local_url('showgroup', array('nickname' => $nickname));
     $result = $this->group->update($orig);
     if (!$result) {
         common_log_db_error($this->group, 'UPDATE', __FILE__);
         $this->serverError(_('Could not update group.'));
     }
     $result = $this->group->setAliases($aliases);
     if (!$result) {
         $this->serverError(_('Could not create aliases.'));
     }
     if ($nickname != $orig->nickname) {
         common_log(LOG_INFO, "Saving local group info.");
         $local = Local_group::staticGet('group_id', $this->group->id);
         $local->setNickname($nickname);
     }
     $this->group->query('COMMIT');
     if ($this->group->nickname != $orig->nickname) {
         common_redirect(common_local_url('editgroup', array('nickname' => $nickname)), 303);
     } else {
         $this->showForm(_('Options saved.'));
     }
 }
Example #30
0
 protected static function validateNickname($str)
 {
     return Validate::string($str, array('min_length' => 1, 'max_length' => 64, 'format' => VALIDATE_NUM . VALIDATE_ALPHA));
 }