Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Simply calling your authenticate method should trigger logic within <code>Auth</code> to store the proper data in the session (or some other data store) and <code>Auth</code> should also be used exclusively to retreive/revoke this info. So using the example form your comment it might be:</p> <pre><code>class Auth { public static function authenticate($identity, $pass) { // do lookup to match identity/pass if its good then /* assume $auth is an array with the username/email or whatever data you need to store as part of authentication */ Session::set('auth', $auth); return true; // if auth failed then Session::set('auth', array('user'=&gt;'anonymous')); return false; } public function isAuthenticated() { $auth = Session::get('auth'); if(!$auth) { return false; } return (isset($auth['user']) &amp;&amp; $auth['user'] !== 'anonymous'); } } </code></pre> <blockquote> <p>[...] as it stands right now I feel as though I'm getting too much wrapped up in my Session object.</p> </blockquote> <p>And id agree. Idelaly for authentication/credentials you shoudl only be interacting with the Auth/Acl object(s). They would then utilize the session as stateful store... but you shouldnt care that its even stored in session. The code utilizng the Auth/Acl object(s) should be completely unaware of this fact.</p> <p>For example:</p> <pre><code>//Bad if($session-&gt;get('authenticated', 'auth')) { // do stuff } // also bad if(isset($_SESSION['authenticated'])) { // do stuff } //Good if($auth-&gt;isAuthenticated()) { // do stuff } // inside $auth class it might look like this public function isAuthenticated() { $store = $this-&gt;getSotrage(); // assume this returns the $_SESSION['auth'] return isset($store['authenticated']); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload