Пример #1
0
 public function signupAction()
 {
     if ($this->request->isPost()) {
         $error = 0;
         // if($this->security->checkToken() == false){
         // 	$error = 1;
         // 	$this->flash->error('<button type="button" class="close" data-dismiss="alert">×</button>Invalid CSRF Token');
         // 	return $this->response->redirect('signup');
         // }
         $firstName = $this->request->getPost('first_name');
         $lastName = $this->request->getPost('last_name');
         $email = $this->request->getPost('email');
         $password = $this->request->getPost('password');
         $confirmPassword = $this->request->getPost('confirm_password');
         if (empty($firstName) || empty($lastName) || empty($email) || empty($password) || empty($confirmPassword)) {
             $this->flash->warning('<button type="button" class="close" data-dismiss="alert">×</button>All fields required');
             return $this->response->redirect();
         }
         if ($password != $confirmPassword) {
             $errorMsg = "Confirm password does not match";
             $this->flash->error('<button type="button" class="close" data-dismiss="alert">×</button>' . $errorMsg);
             return $this->response->redirect();
         }
         if (!empty($email) && Members::findFirstByEmail($email)) {
             $errorMsg = "Email is already in use. Please try again.";
             $this->flash->error('<button type="button" class="close" data-dismiss="alert">×</button>' . $errorMsg);
             return $this->response->redirect();
         }
         $member = new Members();
         $member->created = date('Y-m-d H:i:s');
         $member->modified = date('Y-m-d H:i:s');
         $member->first_name = $firstName;
         $member->last_name = $lastName;
         $member->email = $email;
         $member->type = 'Business';
         $member->password = $this->security->hash($password);
         if ($member->create()) {
             $activationToken = substr(str_shuffle('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'), 0, 50);
             $emailConfimation = new EmailConfirmations();
             $emailConfimation->created = date('Y-m-d H:i:s');
             $emailConfimation->modified = date('Y-m-d H:i:s');
             $emailConfimation->user_id = $member->id;
             $emailConfimation->email = $email;
             $emailConfimation->token = $activationToken;
             $emailConfimation->confirmed = 'N';
             if ($emailConfimation->save()) {
                 $this->getDI()->getMail()->send(array($email => $firstName . ' ' . $lastName), 'Please confirm your email', 'confirmation', array('confirmUrl' => 'biz/emailConfimation/' . $member->id . '/' . $email . '/' . $activationToken));
             }
             $this->flash->success('<button type="button" class="close" data-dismiss="alert">×</button>You\'ve successfully created a MyBarangay account. We sent a confirmation email to ' . $email . '.');
         } else {
             //print_r($user->getMessages());
             $this->flash->error('<button type="button" class="close" data-dismiss="alert">×</button>Registration failed. Please try again.');
         }
         return $this->response->redirect();
     }
 }
Пример #2
0
 /**
  * Send a confirmation e-mail to the user if the account is not active
  */
 public function afterSave()
 {
     if ($this->active == 'N') {
         $emailConfirmation = new EmailConfirmations();
         $emailConfirmation->usersId = $this->id;
         if ($emailConfirmation->save()) {
             $this->getDI()->getFlash()->notice('<h4> A confirmation mail has been sent to </h4> ' . $this->email);
         }
     }
 }
Пример #3
0
 public function signupAction()
 {
     if ($this->request->isPost()) {
         if ($this->request->getPost()) {
             $this->response->setContentType('application/json');
             $email = $this->request->getPost('email', 'striptags');
             if (!Users::findFirst("email = '{$email}'")) {
                 $user = new Users();
                 $user->assign(array('first_name' => $this->request->getPost('firstname', 'striptags'), 'last_name' => $this->request->getPost('lastname', 'striptags'), 'email' => $this->request->getPost('email', 'striptags'), 'password' => $this->security->hash('changeme'), 'activated' => 0));
                 if ($user->save()) {
                     $emailConfirmation = new EmailConfirmations();
                     $emailConfirmation->usersId = $user->id;
                     $emailConfirmation->save();
                     $smsbalance = new SmsBalance();
                     $smsbalance->assign(array('user_id' => $user->id, 'balance' => 0, 'used' => 0, 'created_at' => date("Y-m-d H:i:s"), 'updated_at' => date("Y-m-d H:i:s")));
                     $smsbalance->save();
                     $data = array('code' => 1, 'msg' => 'A confirmation mail has been sent to' . $user->email, 'status' => 'success');
                 } else {
                     $data = array('code' => 2, 'msg' => 'something went wrong', 'status' => 'error');
                 }
             } else {
                 $data = array('code' => 2, 'msg' => 'Already Exist', 'status' => 'error');
             }
             $this->response->setContent(json_encode($data));
             $this->response->send();
         }
     }
 }