public function register($result)
 {
     // validate input + additional validation
     $jsonval = new JsonValidate($this->data, '{"name":"", "email":"@", "address":"", "suburb":"", "postcode":"", "state":"", "country":"", "pass":"", "captcha":""}');
     if (($errors = $jsonval->validate()) !== true) {
         $result['error'] = $errors;
         return $result;
     }
     if (!$this->data->phone && !$this->data->mobile) {
         $result['error'] = "At least one contact phone number must be specified.";
         return $result;
     }
     // validate captcha
     require $_SERVER['DOCUMENT_ROOT'] . $_SERVER['APP_ROOT'] . 'assets/secureimage/securimage.php';
     $img = new Securimage();
     // if the code checked is correct, it is destroyed to prevent re-use
     if ($img->check($this->data->captcha) == false) {
         $result['error'] = "Incorrect security code entered";
         return $result;
     }
     // create customer, check for error ( this does email check)
     $wposCust = new WposAdminCustomers();
     $res = $wposCust->addCustomerData($this->data);
     if (!is_numeric($res)) {
         $result['error'] = $res;
         return $result;
     }
     // set activation url with random hash as a token
     $token = WposAdminUtilities::getToken();
     $link = "https://" . $_SERVER['SERVER_NAME'] . "/myaccount/activate.php?token=" . $token;
     // set token
     $custMdl = new CustomerModel();
     if ($custMdl->setAuthToken($res, $token) === false) {
         $result['error'] = "Could not set auth token: " . $custMdl->errorInfo;
     }
     // send reset email
     $linkhtml = '<a href="' . $link . '">' . $link . '</a>';
     $mailer = new WposMail();
     if (($mres = $mailer->sendPredefinedMessage($this->data->email, 'register_email', ['name' => $this->data->name, 'link' => $linkhtml])) !== true) {
         $result['error'] = $mres;
     }
     $mailer->sendPredefinedMessage("*****@*****.**", 'register_notify', ['name' => "Michael", 'custname' => $this->data->name]);
     return $result;
 }
Example #2
0
 /**
  * Send password reset email to customer
  * @param $result
  * @return mixed
  */
 public function sendResetEmail($result)
 {
     // validate input
     if (!is_numeric($this->data->id)) {
         $result['error'] = "A valid id must be supplied";
         return $result;
     }
     // get customer details
     $custMdl = new CustomerModel();
     $customer = $custMdl->get($this->data->id)[0];
     if (strpos($customer['email'], '@') === -1) {
         $result['error'] = "The customer does not have a valid email";
         return $result;
     }
     // generate url
     $token = WposAdminUtilities::getToken();
     $link = "https://" . $_SERVER['SERVER_NAME'] . "/myaccount/resetpassword.php?token=" . $token;
     // set token
     if ($custMdl->setAuthToken($this->data->id, $token) === false) {
         $result['error'] = "Could not set auth token: " . $custMdl->errorInfo;
     }
     // send reset email
     $linkhtml = '<a href="' . $link . '">' . $link . '</a>';
     $mailer = new WposMail();
     if (($mres = $mailer->sendPredefinedMessage($customer['email'], 'reset_email', ['name' => $customer['name'], 'link' => $linkhtml])) !== true) {
         $result['error'] = $mres;
     }
     return $result;
 }
Example #3
0
 /**
  * Generate a new token and auth_hash, save the token in the database
  * @param $id
  * @param $password_hash
  */
 private function setNewSessionToken($id, $password_hash)
 {
     // create unique token
     $tokens = ['token' => WposAdminUtilities::getToken()];
     // create auth_hash
     $tokens['auth_hash'] = hash('sha256', $password_hash . $tokens['token']);
     // save tokens
     $this->authMdl->setAuthToken($id, $tokens['token']);
     $this->authTokens = $tokens;
 }