/** * Save the profile */ protected function executeSave() { if (empty($_POST)) { // dont process anything if no data has been posted return $this->executeIndex(); } $validator = new \psm\Util\User\UserValidator($this->user); $user = $this->user->getUser(); $fields = $this->profile_fields; $fields[] = 'password'; $fields[] = 'password_repeat'; $clean = array(); foreach ($fields as $field) { if (isset($_POST[$field])) { $clean[$field] = trim(strip_tags($_POST[$field])); } else { $clean[$field] = ''; } } // validate the lot try { $validator->username($clean['user_name'], $this->user->getUserId()); $validator->email($clean['email']); // always validate password for new users, // but only validate it for existing users when they change it. if ($clean['password'] != '') { $validator->password($clean['password'], $clean['password_repeat']); } } catch (\InvalidArgumentException $e) { $this->addMessage(psm_get_lang('users', 'error_' . $e->getMessage()), 'error'); return $this->executeIndex(); } if (!empty($clean['password'])) { $password = $clean['password']; } unset($clean['password']); unset($clean['password_repeat']); $this->db->save(PSM_DB_PREFIX . 'users', $clean, array('user_id' => $this->user->getUserId())); if (isset($password)) { $this->user->changePassword($this->user->getUserId(), $password); } $this->addMessage(psm_get_lang('users', 'profile_updated'), 'success'); return $this->executeIndex(); }