/** * Update user data * * @access private */ private function update() { if ($this->check_post_data()) { try { $this->_profile->update('_firstname', 'str'); $this->_profile->update('_lastname', 'str'); $this->_profile->update('_nickname', 'str'); $this->_profile->update('_publicname', 'str'); $this->_profile->update('_email', 'str'); $this->_profile->update('_website', 'str'); $this->_profile->update('_msn', 'str'); $this->_profile->update('_twitter', 'str'); $this->_profile->update('_facebook', 'str'); $this->_profile->update('_google', 'str'); $this->_profile->update('_avatar', 'int'); $this->_profile->update('_bio', 'str'); if (VPost::role(false)) { $this->_profile->update('_role', 'str'); } $pwd = $this->_profile->_password; if (!empty($pwd)) { $this->_profile->update('_password', 'str'); } $this->build_avatar(); $this->_action_msg = ActionMessages::profile_update(true); } catch (Exception $e) { $this->_action_msg = ActionMessages::profile_update(ucfirst($e->getMessage())); } } }
/** * Set passed data into the user object and return errors if data doesn't fit * * @access private * @return boolean */ private function check_post_data() { $results = array(); $errors = array(); array_push($results, $this->_new_user->__set('_username', VPost::username())); array_push($results, $this->_new_user->__set('_nickname', VPost::username())); array_push($results, $this->_new_user->__set('_publicname', VPost::username())); array_push($results, $this->_new_user->__set('_email', VPost::email())); array_push($results, $this->_new_user->__set('_firstname', VPost::firstname())); array_push($results, $this->_new_user->__set('_lastname', VPost::lastname())); if (VPost::website()) { array_push($results, $this->_new_user->__set('_website', VPost::website())); } array_push($results, $this->_new_user->__set('_role', VPost::role())); if (VPost::pwd() == VPost::re_pwd()) { array_push($results, $this->_new_user->__set('_password', VPost::pwd())); } else { array_push($results, 'Passwords doesn\'t match'); } foreach ($results as $result) { if ($result !== true) { array_push($errors, '<li>- ' . $result . '</li>'); } } if (!empty($errors)) { $error_msg = 'Check your informations:<br/><ul>' . implode('', $errors) . '</ul>'; $this->_action_msg = ActionMessages::custom_wrong($error_msg); return false; } else { return true; } }
/** * Create a new role * * @access private */ private function create() { if (VPost::add_role(false) && $this->check_post_data()) { try { $new_role = new Setting(); $new_role->_name = strtolower(VPost::role()); $new_role->_type = 'role'; $new_role->_data = json_encode(array('dashboard' => false, 'post' => false, 'media' => false, 'album_photo' => false, 'comments' => false, 'delete_content' => false, 'settings' => false)); $new_role->create(); //update array containing all roles name $to_read['table'] = 'setting'; $to_read['columns'] = array('SETTING_ID'); $to_read['condition_columns'][':t'] = 'setting_type'; $to_read['condition_select_types'][':t'] = '='; $to_read['condition_values'][':t'] = 'all_roles'; $to_read['value_types'][':t'] = 'str'; $all_roles = $this->_db->read($to_read); //if the setting does't exist, we create it with the new role if (empty($all_roles)) { $all_roles = new Setting(); $all_roles->_name = 'All roles'; $all_roles->_type = 'all_roles'; $all_roles->_data = json_encode(array(strtolower(VPost::role()))); $all_roles->create(); } else { $all_roles = new Setting($all_roles[0]['SETTING_ID']); $roles = json_decode($all_roles->_data, true); array_push($roles, strtolower(VPost::role())); $all_roles->_data = json_encode($roles); $all_roles->update('_data', 'str'); } //end update $result = true; } catch (Exception $e) { $result = $e->getMessage(); } $this->_action_msg = ActionMessages::created($result); } }