Note that there are some explanatory texts on larger screens.

plurals
  1. POInitial steps on wiring my registration form to my php class and functions
    primarykey
    data
    text
    <p>I'm looking for all or any information which will help me get started. I'm perplexed on how i should get the ball rolling. What code should be apart of my register.php page? What php code if any should be on the same page as my html form elements.. </p> <p>Form:</p> <pre><code>&lt;form id='register' action='register.php' onsubmit="return validateForm()" method='post' accept-charset='UTF-8'&gt; &lt;fieldset&gt; &lt;legend&gt;&lt;br/&gt;Create An Account&lt;/legend&gt;&lt;br/&gt; &lt;input type='hidden' name='submitted' id='submitted' value='1'/&gt; &lt;label for='username' &gt;Username*: &lt;/label&gt; &lt;input type='text' name='username' id='username' maxlength="50" /&gt;&lt;br/&gt;&lt;br/&gt; &lt;label for='email' &gt;Email Address*:&lt;/label&gt; &lt;input type='text' name='email' id='email' maxlength="50" /&gt;&lt;br/&gt;&lt;br/&gt; &lt;label for="password"&gt;Password*:&lt;/label&gt; &lt;input type="password" name="password" placeholder="password" required&gt;&lt;br/&gt;&lt;br/&gt; &lt;label for="password"&gt;Confirm Password*:&lt;/label&gt; &lt;input type="password" name="password" placeholder="password" required&gt;&lt;br/&gt;&lt;br/&gt; &lt;label for='cpassword' &gt;&amp;zwnj;&lt;/label&gt; &lt;input type="hidden" name="submitted" value="TRUE"&gt;&lt;input type='submit' name='rsubmit' id="rsubmit" value='Register' /&gt; &lt;/fieldset&gt; &lt;/form&gt; </code></pre> <p>Here is my php class:</p> <pre><code>// Most objects in this framework are populated by calling the constructor, but // this one has a variety of entry points. They don't do any sanity checking // with eachother, so you can have $user-&gt;create and $user-&gt;register refer to // completely different rows. class Shopper extends Base { protected $shopper_id; protected $email; protected $user_name; protected $temp_token; protected $sign_in_token; protected $UserShoppingList; function __construct($email = null) { // For testing use only. Declined to wrap in this_is_dev because I // foresee using it somewhere in the code, pushing live, and being // parent::__construct('jfw_shoppers', array('SHOPPER_ID' =&gt; $shopper_id)); // Allow them to pass an e-mail address or the token if (strpos($email, '@') === false) { $this-&gt;sign_in_token = $email; } else { $this-&gt;email = $email; } } // todo: need a new function to do the actual activation. public function activate($temp_token) { global $db; $this-&gt;set_temp_token($temp_token); $vars = array(); $vars[] = array(':i_temp_token', $this-&gt;get_temp_token()); // Returns a Y or N return $db-&gt;get_function_as_proc('custom.japi_shopper_identity.Activate_User(:i_temp_token)', $vars) == 'Y'; } public function create($password) { global $db; if (!$this-&gt;get_email() || !$this-&gt;get_username()) { return false; } $vars = array(); $vars[] = array(':email', $this-&gt;get_email()); $vars[] = array(':username', $this-&gt;get_username()); $vars[] = array(':password', $password); $id = $db-&gt;get_function_as_proc('custom.japi_shopper_identity.create_user(:email, :username, :password)', $vars); $this-&gt;set_id($id); // If it failed, it'll puke on the procedure. If we've come this far, we // know it worked. return true; } public function get_email() { return $this-&gt;email; } private function get_id() { if (isset($this-&gt;shopper_id)) { return $this-&gt;shopper_id; // If this object has an e-mail address or the user sent one } else if ($this-&gt;get_email()) { global $db; $vars = array(); $vars[] = array(':i_email_id', $this-&gt;get_email()); // FUNCTION get_id_by_email(i_email_id IN jfw_shoppers.email%TYPE) $id = array_pop(array_pop($db-&gt;get_function('custom.japi_shopper_identity.get_id_by_email(:i_email_id)', $vars))); $this-&gt;set_id($id); $this-&gt;shopper_id = $id; return $this-&gt;shopper_id; // Can also get from token } else if ($this-&gt;get_sign_in_token()) { // todo: call get_id_by_token return false; } } // todo: test public function get_lists($clobber = false) { global $pd; // $pd-&gt;print_object($this, 'User - has token?'); // $pd-&gt;print_object($this-&gt;get_sign_in_token(), 'Token'); if ($this-&gt;UserShoppingList != null &amp;&amp; !$clobber) { return $this-&gt;UserShoppingList; } else if ($this-&gt;get_sign_in_token()) { global $db; $pd-&gt;print_object($this, 'User - has token?'); $pd-&gt;print_object(strtolower($this-&gt;get_sign_in_token()), 'token?'); $vars = array(); $vars[] = array(':i_sign_in_token', strtolower($this-&gt;get_sign_in_token())); $pd-&gt;print_object($this-&gt;get_sign_in_token(), 'About to seek lists using token'); $rows = $db-&gt;get_function('custom.japi_shopper_identity.get_lists_for_shopper(:i_sign_in_token)', $vars); $pd-&gt;print_object($rows, 'Rows returned by get_lists using token '.$this-&gt;get_sign_in_token()); // Turn the rows into objects $this-&gt;UserShoppingList = array_to_objects($rows, 'UserShoppingList'); return $this-&gt;UserShoppingList; } else { return false; } } public function get_sign_in_token() { if ($this-&gt;sign_in_token != null) { return $this-&gt;sign_in_token; } else { return false; } } public function get_temp_token() { if ($this-&gt;temp_token != null) { return $this-&gt;temp_token; } else { return false; } } public function get_username() { return $this-&gt;user_name; } public function json($obj = null, $return_json = false) { if ($obj == null) { $obj = $this; } return parent::json($obj, $return_json); } // Most objects in this framework are populated by calling the constructor, // but the only way to populate this one is to call this function with good // credentials. public function login($password) { global $db; if (!$this-&gt;get_email()) { return false; } // Log them in now that we know who they are. $vars = array(); $vars[] = array(':i_email_id', $this-&gt;get_email()); $vars[] = array(':i_password', $password); // This also exists, but is not yet in use: // $token = $db-&gt;get_function_as_proc('custom.japi_shopper_identity.login_by_username(:i_username, :i_password)', $vars); $token = $db-&gt;get_function_as_proc('custom.japi_shopper_identity.Login_by_Email(:i_email_id, :i_password)', $vars); // todo: what if it's bad credentials? if ($token == null) { return false; } else { $this-&gt;set_sign_in_token($token); return $this-&gt;get_sign_in_token(); } } public function password_reset($tmp_token, $password) { global $db; if (strlen($password) &lt; 8) { return false; } $vars = array(); $vars[] = array(':temp_token', $tmp_token); $vars[] = array(':new_password', $password); return $db-&gt;get_function_as_proc('custom.japi_shopper_identity.password_reset(:temp_token, :new_password)', $vars) == 'Y'; } public function request_activation() { global $db; $vars = array(); $vars[] = array(':i_shopper_id', $this-&gt;get_id()); // Returns a temp token $temp_token = $db-&gt;get_function_as_proc('custom.japi_shopper_identity.activate_user_request(:i_shopper_id)', $vars); if ($temp_token == null) { return false; } else { $this-&gt;send_activation_email(); return $temp_token; } } public function request_password_reset() { global $db, $pd; if (!$this-&gt;get_id()) { return false; } $vars = array(); $vars[] = array(':shopper_id', $this-&gt;get_id()); $temp_token = $db-&gt;get_function_as_proc('custom.japi_shopper_identity.password_reset_request(:shopper_id)', $vars); if ($temp_token == null) { return false; } else { $this-&gt;set_temp_token($temp_token); $pd-&gt;print_object('About to send the e-mail'); $this-&gt;send_password_email(); $pd-&gt;print_object('Sent the email'); return $this-&gt;get_temp_token(); } } private function send_activation_email() { if (!$this-&gt;get_email() || !$this-&gt;get_temp_token()) { return false; } $fancy = ' &lt;div style="text-align: center;"&gt;&lt;img src="logo.jpg" /&gt;&lt;/div&gt; &lt;h2&gt;Welcome to com!&lt;/h2&gt; &lt;p&gt;To complete your registration, &lt;a href="todo: "&gt;click here&lt;/a&gt; or copy and paste the URL into your browser:&lt;/p&gt; URL?token='.$this-&gt;get_temp_token().' Thanks! '; $plain = 'Welcome to com! To complete your registration, please activate your account by going to the URL below: URL?token='.$this-&gt;get_temp_token().' Thanks! '; // todo: subject could probably be better return email_customer($this-&gt;get_email(), 'Welcome to com!', $fancy, $plain); } private function send_password_email() { global $pd; $pd-&gt;print_object('In send_password_email'); $pd-&gt;print_object($this-&gt;get_email(), 'E-mail'); $pd-&gt;print_object($this-&gt;get_temp_token(), 'Token'); if (!$this-&gt;get_email() || !$this-&gt;get_temp_token()) { return false; } $pd-&gt;print_object($this-&gt;get_email(), 'Have all the data I need'); $fancy = ' &lt;div style="text-align: center;"&gt;&lt;img src="logo.jpg" /&gt;&lt;/div&gt; &lt;h2&gt;Welcome to com!&lt;/h2&gt; &lt;p&gt;To reset your password, &lt;a href="todo: "&gt;click here&lt;/a&gt; or copy and paste the URL into your browser:&lt;/p&gt; &lt;p&gt;URL?token='.$this-&gt;get_temp_token().'&lt;/p&gt; &lt;p&gt;Thanks!&lt;/p&gt; '; $plain = 'Welcome to com! To reset your password by going to the URL below: URL?token='.$this-&gt;get_temp_token().' Thanks! '; $pd-&gt;print_object('About to actually e-mail'); return email_customer($this-&gt;get_email(), "Reset your com password", $fancy, $plain); } public function set_email($email) { return $this-&gt;email = $email; } public function set_id($email) { return $this-&gt;shopper_id; } public function set_sign_in_token($token) { return $this-&gt;sign_in_token = $token; } public function set_temp_token($token) { return $this-&gt;temp_token = $token; } public function set_username($username) { return $this-&gt;user_name = $username; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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