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;
 }
示例#2
0
 /**
  * Process customer data if set
  * @return bool
  */
 private function processCustomer()
 {
     // is updated data available
     if ($this->custdata != null) {
         // if customer record (id) exists
         if ($this->jsonobj->custid > 0) {
             if (WposAdminCustomers::updateCustomerData($this->custdata) === true) {
                 unset($this->jsonobj->custdata);
                 // unset customer data; we don't need to send this back
                 return true;
             } else {
                 return false;
             }
         } else {
             $id = WposAdminCustomers::addCustomerData($this->custdata);
             if (is_numeric($id)) {
                 $this->jsonobj->custid = $id;
                 unset($this->jsonobj->custdata);
                 // unset customer data; we don't need to send this back
                 return true;
             } else {
                 return false;
             }
         }
     } else {
         // email only customers are not added for now (email only used for e-receipt); maybe an option.
         return true;
     }
 }