Prompting for a Password


as of: August 13, 2013

Sometimes POS functionality is restricted to only supervisor/manager cashiers. The built in adminlogin.php gui-module lets you display a password prompt and then continue on only if a valid password is entered. To use this functionality, pass the name of an appropriate class to adminlogin.php as the URL parameter class. The class does not have to inherit from any particular base class; it merely has to provide the methods and properties that requestInfo.php needs (i.e., duck typing). This structure lets you attach an information request to another class.

static string adminLoginMsg
static int adminLoginLevel
static mixed adminLoginCallback(boolean $success)

The proprty adminLoginMsg is the prompt displayed on the cashier's login screen. The property adminLoginLevel corresponds to the value of frontendsecurity in the employees table that is required to get past the prompt.

The method adminLoginCallback is called after the prompt is done. If the cashier did not provide a valid password, $success will be False. In this case the method's return value does not matter. Control will always return to the main POS page after the callback method completes. If the cashier provided a valid password, $success will be True. In this case return a URL indicating which page POS should go to next. Returning boolean True is a synonym for the URL for the main POS page.

Example: Allow member sales even if they normally would not apply to the current member.

class ForceMemPricing extends Parser {
	function check($str){
		if ($str == 'MPO') return True;
		else return False;
	}

	function parse($str){
		$ret = $this->default_json();
		// redirect to the prompt page
		$ret['main_frame'] = MiscLib::base_url().'gui-modules/adminlogin.php?class=ForceMemPricing';
		return $ret;
	}

	public static $adminLoginMsg = 'grant member pricing';

	public static $adminLoginLevel = 30;

	public static function adminLoginCallback($success){
		global $CORE_LOCAL;
		if ($success){
			$CORE_LOCAL->set('isMember', 1);
			PrehLib::ttl();
			return True;
		}
		else
			return False;
	}
}