Profile Module; redirect on update (success or error)

How do I push user back to his profile edit page if core_success or core_error is thrown?

In the code below index() pulls profile_main.php which is not used (at all)–I can’t set profile_edit because if I do then it shows no data. Is there way to force index() to move on to public function view($pilotid=‘’) where the actual profile builds?

 public function index() { if(!Auth::LoggedIn()) { $this-\>set('message', 'You must be logged in to access this feature!'); $this-\>render('core\_error.php'); return; } /\* \* This is from /profile/editprofile \*/ if(isset($this-\>post-\>action)) { if($this-\>post-\>action == 'saveprofile') { $this-\>save\_profile\_post(); } /\* this comes from /profile/changepassword \*/ if($this-\>post-\>action == 'changepassword') { $this-\>change\_password\_post(); } } $pilot = PilotData::getPilotData(Auth::$pilot-\>pilotid); if(Config::Get('TRANSFER\_HOURS\_IN\_RANKS') == true) { $totalhours = $pilot-\>totalhours + $pilot-\>transferhours; } else { $totalhours = $pilot-\>totalhours; } $this-\>set('pilotcode', PilotData::getPilotCode($pilot-\>code, $pilot-\>pilotid)); $this-\>set('report', PIREPData::getLastReports($pilot-\>pilotid)); $this-\>set('nextrank', RanksData::getNextRank($totalhours)); $this-\>set('allawards', AwardsData::getPilotAwards($pilot-\>pilotid)); $this-\>set('userinfo', $pilot); $this-\>set('pilot', $pilot); $this-\>set('pilot\_hours', $totalhours); /\*$this-\>render('profile\_main.php');\*/ CodonEvent::Dispatch('profile\_viewed', 'Profile'); }

 

What happens if you replace

if($this-\>post-\>action == 'saveprofile') { $this-\>save\_profile\_post(); }

with

if($this-\>post-\>action == 'saveprofile') { $this-\>save\_profile\_post(); $this-\>editProfile(); return; }

Check if that has worked first, and if not try adding this:

Auth::$pilot = $pilot;

After this line in save_profile_post() function (around line 226)

PilotData::SaveFields($pilot-\>pilotid, $\_POST);

That’s a workaround (not ideal) so that the editProfile() function doesn’t have to be changed slightly.

1 hour ago, web541 said:

 

if($this->post->action == ‘saveprofile’) { $this->save_profile_post(); $this->editProfile(); return; }

 

Yes and no; it did update the database but when it returned to edit profile the value was previous value. If I hit refresh then the field would show update.

 

Did you manage to try the second part of that and did it work? If not then there’s a couple more steps that need to be done.

Oh. I didn’t think I had to do that since it did update in database and took me to edit profile page.

Let me make those modifications and I’ll report back soon.

Same situation; it works fine in regards to updating the columns in the database–but the this-> editprofile just pulls back up previous data in cache

51 minutes ago, Ither said:

this-> editprofile just pulls back up previous data

Had a suspicion that would be the case.

On the same line (The one that you just put in, Auth::$pilot = $pilot;), try and replace it with this:

Auth::$pilot = PilotData::getPilotData($pilot-\>pilotid);

 

If that doesn’t work, try and replace these 3 functions and see if that works for you

 

 public function index() { if(!Auth::LoggedIn()) { $this-\>set('message', 'You must be logged in to access this feature!'); $this-\>render('core\_error.php'); return; } /\* \* This is from /profile/editprofile \*/ if(isset($this-\>post-\>action)) { if($this-\>post-\>action == 'saveprofile') { $this-\>save\_profile\_post(); return; } /\* this comes from /profile/changepassword \*/ if($this-\>post-\>action == 'changepassword') { $this-\>change\_password\_post(); } } $pilot = PilotData::getPilotData(Auth::$pilot-\>pilotid); if(Config::Get('TRANSFER\_HOURS\_IN\_RANKS') == true) { $totalhours = $pilot-\>totalhours + $pilot-\>transferhours; } else { $totalhours = $pilot-\>totalhours; } $this-\>set('pilotcode', PilotData::getPilotCode($pilot-\>code, $pilot-\>pilotid)); $this-\>set('report', PIREPData::getLastReports($pilot-\>pilotid)); $this-\>set('nextrank', RanksData::getNextRank($totalhours)); $this-\>set('allawards', AwardsData::getPilotAwards($pilot-\>pilotid)); $this-\>set('userinfo', $pilot); $this-\>set('pilot', $pilot); $this-\>set('pilot\_hours', $totalhours); $this-\>render('profile\_main.php'); CodonEvent::Dispatch('profile\_viewed', 'Profile'); }

 

 public function editprofile() { if(!Auth::LoggedIn()) { $this-\>set('message', 'You must be logged in to access this feature!'); $this-\>render('core\_error.php'); return; } $p = PilotData::getPilotData(Auth::$pilotid); $this-\>set('userinfo', $p); $this-\>set('pilot', $p); $this-\>set('customfields', PilotData::getFieldData($p-\>pilotid, true)); $this-\>set('bgimages', PilotData::getBackgroundImages()); $this-\>set('countries', Countries::getAllCountries()); $this-\>set('pilotcode', PilotData::getPilotCode($p-\>code, $p-\>pilotid)); $this-\>render('profile\_edit.php'); }

 protected function save\_profile\_post() { if(!Auth::LoggedIn()) { $this-\>set('message', 'You must be logged in to access this feature!'); $this-\>render('core\_error.php'); return; } $pilot = Auth::$pilot; //TODO: check email validity if($this-\>post-\>email == '') { $this-\>set('message', 'The email address cannot be blank.'); $this-\>render('core\_error.php'); return; } $fields = RegistrationData::getCustomFields(); if(is\_array($fields) || $fields instanceof Countable) { if(count($fields) \> 0) { foreach ($fields as $field) { $value = Vars::POST($field-\>fieldname); $value1 = DB::escape($value); if ($field-\>required == 1 && $value1 == '') { $this-\>set('message', ''.$field-\>title.' cannot be blank!'); $this-\>render('core\_error.php'); return; } } } } $params = array( 'code' =\> $pilot-\>code, 'email' =\> $this-\>post-\>email, 'location' =\> $this-\>post-\>location, 'hub' =\> $pilot-\>hub, 'bgimage' =\> $this-\>post-\>bgimage, 'retired' =\> false ); PilotData::updateProfile($pilot-\>pilotid, $params); PilotData::SaveFields($pilot-\>pilotid, $\_POST); # Generate a fresh signature PilotData::GenerateSignature($pilot-\>pilotid); PilotData::SaveAvatar($pilot-\>code, $pilot-\>pilotid, $\_FILES); $this-\>set('message', 'Profile saved!'); $this-\>render('core\_success.php'); $this-\>editProfile(); }

 

[END SPOILER] 

 

[END SPOILER] 

10 hours ago, web541 said:

Had a suspicion that would be the case.

On the same line (The one that you just put in, Auth::$pilot = $pilot;), try and replace it with this:

Auth::$pilot = PilotData::getPilotData($pilot->pilotid);

 

That solved it; now it’s pulling data correctly. It also now returns to edit profile page and gives you the error/success instead of tossing you to the main dashboard.