Ferreteria/v2/usage/login: Difference between revisions

From Woozle Writes Code
< Ferreteria‎ | v2‎ | usage
Jump to navigation Jump to search
(brief reminder)
 
(key functions used at login time)
Line 1: Line 1:
==Data==
==Data==
This uses essentially the same tables as [[VbzCart/tables#Users]] -- documentation to be moved here eventually.
This uses essentially the same tables as [[VbzCart/tables#Users]] -- documentation to be moved here eventually.
==Code==
clsPageLogin (see {{l/same|pages}}):
<php>
    protected function DoLoginCheck() {
$this->App()->Session()->UserLogin($this->LoginName(),$this->sPass);
    }
</php>
clsUserSession:
<php>
    /*----
      ACTION: Attempts to log the user in with the given credentials.
      RETURNS: user object if successful, NULL otherwise.
    */
    public function UserLogin($iUser,$iPass) {
$tUsers = $this->UserTable();
$oUser = $tUsers->Login($iUser,$iPass);
$this->SetUserRecord($oUser); // set user for this session
    }
</php>
clsUserAccts:
<php>
    /*----
      RETURNS: user object if login successful, NULL otherwise
    */
    public function Login($iUser,$iPass) {
$rc = $this->FindUser($iUser);
if (is_null($rc)) {
    // username not found
    $oUser = NULL;
} elseif ($rc->AuthValid($iPass)) {
    $oUser = $rc;
} else {
    // username found, password wrong
    $oUser = NULL;
}
return $oUser;
    }
</php>

Revision as of 21:31, 7 June 2015

Data

This uses essentially the same tables as VbzCart/tables#Users -- documentation to be moved here eventually.

Code

clsPageLogin (see pages): <php>

   protected function DoLoginCheck() {

$this->App()->Session()->UserLogin($this->LoginName(),$this->sPass);

   }

</php> clsUserSession: <php>

   /*----
     ACTION: Attempts to log the user in with the given credentials.
     RETURNS: user object if successful, NULL otherwise.
   */
   public function UserLogin($iUser,$iPass) {

$tUsers = $this->UserTable(); $oUser = $tUsers->Login($iUser,$iPass); $this->SetUserRecord($oUser); // set user for this session

   }

</php> clsUserAccts: <php>

   /*----
     RETURNS: user object if login successful, NULL otherwise
   */
   public function Login($iUser,$iPass) {

$rc = $this->FindUser($iUser); if (is_null($rc)) { // username not found $oUser = NULL; } elseif ($rc->AuthValid($iPass)) { $oUser = $rc; } else { // username found, password wrong $oUser = NULL; } return $oUser;

   }

</php>