Example #1
0
 /**
  * Default Constructor
  *
  */
 public function __construct()
 {
     //Let's make this accessible across the admin for display of all dates
     $this->date_format = null;
     //We use this for the profile modal
     $this->logged_user = null;
     $this->db = DinklyDataConnector::fetchDB();
     if (DinklyUser::isLoggedIn()) {
         $this->logged_user = new DinklyUser();
         $this->logged_user->init(DinklyUser::getAuthSessionValue('logged_id'));
         $this->date_format = $this->date_format = $this->logged_user->getDateFormat() . ' ' . $this->logged_user->getTimeFormat();
         return false;
     } else {
         if (Dinkly::getCurrentModule() != 'login') {
             $this->loadModule('admin', 'login', 'default', true, true);
         }
     }
     return true;
 }
 public function validateUserPost($post_array)
 {
     if ($post_array['email'] == "") {
         $this->errors[] = "Email is a required field";
     } else {
         if ($post_array['email'] != $this->user->getUsername()) {
             //Check the username/email for uniqueness
             if (!DinklyUserCollection::isUniqueUsername($post_array['email'])) {
                 $this->errors[] = "Email address already in use, please try another.";
             }
             //Make sure it's also a valid email address
             if (!filter_var($post_array['email'], FILTER_VALIDATE_EMAIL)) {
                 $this->errors[] = "Invalid email. Not a valid email address.";
             }
             $this->user->setUsername(strip_tags($post_array['email']));
             //If we're editing the current user, we should update the session'd username
             if ($this->user->getId() == DinklyUser::getAuthSessionValue('logged_id')) {
                 DinklyUser::setAuthSessionValue('logged_username', $this->user->getUsername());
             }
         }
     }
     //If the password isn't blank
     if ($post_array['password'] != "" && $post_array['confirm-password'] != "") {
         $has_error = false;
         //Make sure both match
         if ($post_array['password'] != $post_array['confirm-password']) {
             $has_error = true;
             $this->errors[] = "Passwords do not match.";
         }
         //Check for length
         if (strlen($post_array['password']) < 8) {
             $has_error = true;
             $this->errors[] = "Password must be at least 8 characters in length.";
         }
         //If the password is valid, update
         if (!$has_error) {
             $this->user->setPassword($post_array['password']);
         }
     } else {
         if ($_POST['user-id'] == "" && $_POST['password'] == "") {
             $this->errors[] = "Password is a required field";
         }
     }
     if ($post_array['first-name'] == "") {
         $this->errors[] = "First Name is a required field";
     }
     if ($post_array['last-name'] == "") {
         $this->errors[] = "Last Name is a required field";
     }
     //If the first name isn't empty and doesn't match the existing one, update
     if ($post_array['first-name'] != "" && $post_array['first-name'] != $this->user->getFirstName()) {
         $this->user->setFirstName(strip_tags($post_array['first-name']));
     }
     //If the last name isn't empty and doesn't match the exiting one, update
     if ($post_array['last-name'] != "" && $post_array['last-name'] != $this->user->getLastName()) {
         $this->user->setLastName(strip_tags($post_array['last-name']));
     }
     //If the title isn't empty and does't match the existing one, update
     if ($post_array['title'] != "" && $post_array['title'] != $this->user->getTitle() || $post_array['title'] == "") {
         $this->user->setTitle(strip_tags($post_array['title']));
     }
     //Nothing to validate here really
     if ($this->user->getTimeZone() == '') {
         $this->user->setTimeZone('America/New_York');
     } else {
         $this->user->setTimeZone(strip_tags($post_array['time-zone']));
     }
 }