Ben Rich Posted November 29, 2011 Share Posted November 29, 2011 Hi, Is there a class' method (or something similar) I can call that will add a customer to the database? For a module I'm putting together I'd like to create a cut down registration form and of course need a method of adding a user to the customer table. I've come up dry after doing some googling and looking around the controllers/classes. Any help would be great! Thanks Link to comment Share on other sites More sharing options...
razaro Posted November 29, 2011 Share Posted November 29, 2011 I think all code you need is in AuthController.php, from line /* Preparing customer */ $customer = new Customer(); and through all checks until line if (!$customer->add()) Where customer is added to its table. And after that there are more code connected to that customer. Link to comment Share on other sites More sharing options...
Ben Rich Posted November 29, 2011 Author Share Posted November 29, 2011 Ok cool. I'll have a play with all that.. thanks, Link to comment Share on other sites More sharing options...
luci1 Posted December 1, 2011 Share Posted December 1, 2011 Hi, Can you add [sOLVED] ? Link to comment Share on other sites More sharing options...
Ben Rich Posted December 1, 2011 Author Share Posted December 1, 2011 I ended up doing the following (this include registration as well as logging in) - useful to others perhaps Note; I removed a fair bit from the Authentication.php text (address stuff) as it wasn't needed for my requirements. Validation also has been edited/added/removed. global $cookie; if(Tools::isSubmit('SubmitNewCustomer')) { //register a new customer $customer = new Customer(); $_POST['firstname'] = Tools::getValue('customer_firstname'); $_POST['lastname'] = Tools::getValue('customer_lastname'); $email = Tools::getValue('email'); $passwd = Tools::getValue('passwd'); $this->errors = $customer->validateControler(); if (Customer::customerExists($email)) $this->errors[] = Tools::displayError('An account is already registered with this e-mail, please fill in the password or request a new one.'); if (!sizeof($this->errors)) { $customer->active = 1; $customer->is_guest = Tools::isSubmit('is_new_customer') ? !Tools::getValue('is_new_customer', 1) : 0 ; if (!$customer->add()) { $this->errors[] = Tools::displayError('An error occurred while creating your account.'); } else { if (!$customer->is_guest) { if (!Mail::Send((int)($cookie->id_lang), 'account', Mail::l('Welcome!'), array('{firstname}' => $customer->firstname, '{lastname}' => $customer->lastname, '{email}' => $customer->email, '{passwd}' => $passwd), $customer->email, $customer->firstname.' '.$customer->lastname)) $this->errors[] = Tools::displayError('Cannot send email'); } $cookie->id_customer = (int)($customer->id); $cookie->customer_lastname = $customer->lastname; $cookie->customer_firstname = $customer->firstname; $cookie->passwd = $customer->passwd; $cookie->logged = 1; $cookie->email = $customer->email; $cookie->is_guest = !Tools::getValue('is_new_customer', 1); Module::hookExec('createAccount', array( '_POST' => $_POST, 'SubmitNewCustomer' => $customer )); } Tools::redirect($_SERVER['REQUEST_URI']); } } if (Tools::isSubmit('SubmitLogin')) //log a user in { Module::hookExec('beforeAuthentication'); $email = trim(Tools::getValue('email')); $passwd = trim(Tools::getValue('passwd')); if (empty($email)) $this->errors[] = Tools::displayError('E-mail address required'); elseif (!Validate::isEmail($email)) $this->errors[] = Tools::displayError('Invalid e-mail address'); if (empty($passwd)) $this->errors[] = Tools::displayError('Password is required'); elseif (Tools::strlen($passwd) > 32) $this->errors[] = Tools::displayError('Password is too long'); elseif (!Validate::isPasswd($passwd)) $this->errors[] = Tools::displayError('Invalid password'); if (!sizeof($this->errors)) { $customer = new Customer(); $authentication = $customer->getByEmail(trim($email), trim($passwd)); if (!$authentication OR !$customer->id) { /* Handle brute force attacks */ sleep(1); $this->errors[] = Tools::displayError('Authentication failed'); } else { $cookie->id_customer = (int)($customer->id); $cookie->customer_lastname = $customer->lastname; $cookie->customer_firstname = $customer->firstname; $cookie->logged = 1; $cookie->is_guest = $customer->isGuest(); $cookie->passwd = $customer->passwd; $cookie->email = $customer->email; } Tools::redirect($_SERVER['REQUEST_URI']); } } $content = '<div id="group-protection">'; if($cookie->isLogged()) { //etc etc etc } Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now