<?php

/**
        Example of how to load a module.
        In this example we have created a module NilFactorReg to simulate how you
        would pull a person record after login.

        Modules allow us to do things quicker and with less code.
        This Login Example (# Lines of Actual Need Code: 8)
         Login.php Example (# Lines of Actual Need Code: 16)
     **/
require_once "Classes/NilFactorDatabase.php";
require_once "Classes/NilFactorModuleBase.php";
require_once 'Modules/NilFactorReg.php';
$request = array('username' => "mtest", 'password' => "NEWpass@word1");
$nfr = new NilFactorReg();
// Dump of what it looks like at start....
// echo print_r($nfr, true);
if ($nfr->authenticateUser($request['username'], $request['password'])) {
    echo "Authentication Successful\n";
} else {
    echo "Authentication Failed\n";
}
echo "Pausing to show authentication....";
system("sleep 5");
// Now dump what happens after we authenticate...
echo print_r($nfr, true);
/** 
        if you had a person id you new already you could load a person record like so as well
     **/
$nfr->loadValueOnID(1);
<?php

/**
        Example of how to update records using a module.
        In this example we have created a module NilFactorReg to simulate how you
        would update a users profile and password.

     **/
require_once "Classes/NilFactorDatabase.php";
require_once "Classes/NilFactorModuleBase.php";
require_once 'Modules/NilFactorReg.php';
$request = array('first_name' => "Real", 'last_name' => "Name", 'email' => "*****@*****.**", 'password' => "NEWpass@word1", 'username' => "mtest", 'oldpassword' => "pass@word1");
$nfr = new NilFactorReg();
// if you didn't want to authenticate the user you could always do this as well..
/**
        if ($nfr->loadUser($request['username'])) {
            $nfr->saveValues($request);
            echo print_r($nfr, true);
            echo "User Created...\n";
        } else {
            echo "User not found...\n";
        }
     **/
if ($nfr->authenticateUser($request['username'], $request['oldpassword'])) {
    echo "Login Successful\n";
    $nfr->saveValues($request);
    echo print_r($nfr, true);
    echo "User Updated...\n";
} else {
    echo "Login Failed...\n";
}
<?php

/**
        Example of how to save using a module.
        In this example we have created a module NilFactorReg to simulate how you
        would save a new user registration.

            Module Required Lines to work: 11
        Non Module Required Lines to work: 40
     **/
require_once "Classes/NilFactorDatabase.php";
require_once "Classes/NilFactorModuleBase.php";
require_once 'Modules/NilFactorReg.php';
$request = array('first_name' => "Module", 'last_name' => "Test", 'email' => "*****@*****.**", 'login' => "mtest", 'password' => "pass@word1", 'street1' => "1234 Any Street", 'street2' => "", 'city' => "City Name", 'state' => "MN", 'country' => "USA", 'postal_code' => "55369", 'phone' => "612-555-5510");
/**
        Verify we haven't already created this user
    **/
$params = array('email' => $request['email'], 'username' => $request['username'], 'first_name' => $request['first_name'], 'last_name' => $request['last_name'], 'postal_code' => $request['postal_code']);
$nfr = new NilFactorReg();
if (!$nfr->checkForDuplicateReg($params)) {
    $nfr->saveValues($request);
    echo print_r($nfr, true);
    echo "User Created...\n";
} else {
    echo "User already exists....\n";
}