Jump to content

Profile Module; redirect on update (success or error)


Recommended Posts

Posted

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');
	}

 

Posted

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.

Posted
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.

 

Posted (edited)
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] 

Edited by web541
Posted
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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...