Exemplo n.º 1
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);
         }
     }
 }
Exemplo n.º 2
0
 /**
  * Account confirmation through the previous sent mail.
  */
 public function confirmEmailAction()
 {
     $code = $this->dispatcher->getParam('code');
     $confirmation = EmailConfirmations::findFirstByCode($code);
     if (!$confirmation) {
         return $this->dispatcher->forward(array('controller' => 'index', 'action' => 'index'));
     }
     if ($confirmation->confirmed != 'N') {
         return $this->dispatcher->forward(array('controller' => 'session', 'action' => 'login'));
     }
     $confirmation->confirmed = 'Y';
     $confirmation->user->active = 1;
     /**
      * Change the confirmation to 'confirmed' and update the user to 'active'
      */
     if (!$confirmation->save()) {
         foreach ($confirmation->getMessages() as $message) {
             $this->flash->error($message);
         }
         return $this->dispatcher->forward(array('controller' => 'index', 'action' => 'index'));
     }
     /**
      * Identify the user in the application
      */
     $this->flash->success('The email was successfully confirmed');
     return $this->dispatcher->forward(array('controller' => 'index', 'action' => 'index'));
 }
Exemplo n.º 3
0
 /**
  * Login user
  * @return \Phalcon\Http\ResponseInterface
  */
 public function loginAction()
 {
     if ($this->request->isPost()) {
         // if($this->security->checkToken() == false){
         // 	$this->flash->error('<button type="button" class="close" data-dismiss="alert">×</button>Invalid CSRF Token');
         // 	return $this->response->redirect('login');
         // }
         $this->view->disable();
         $email = $this->request->getPost('email');
         // $_POST
         $password = $this->request->getPost('password');
         if (empty($email) || empty($password)) {
             $this->flash->warning('<button type="button" class="close" data-dismiss="alert">×</button>All fields required');
             return $this->response->redirect('');
         }
         $member = Members::findFirstByEmail($email);
         if ($member == true && $this->security->checkHash($password, $member->password)) {
             $emaiConfirmed = EmailConfirmations::findFirst(array('columns' => '*', 'conditions' => 'user_id = ?1 AND email=?2 AND confirmed = ?3', 'bind' => array(1 => $member->id, 2 => $email, 3 => 'Y')));
             if (!$emaiConfirmed) {
                 $this->flash->warning('<button type="button" class="close" data-dismiss="alert">×</button>You\'re email is not yet confirmed.');
                 return $this->response->redirect('');
             }
             $userSession = get_object_vars($member);
             //$userSession['type'] = 'Member';
             $profilePic = MemberPhotos::findFirst(array('member_id="' . $userSession['id'] . '"', 'primary_pic="Yes"'));
             $userSession['primary_pic'] = $profilePic->file_path . $profilePic->filename;
             $this->session->set('userSession', $userSession);
             //member id
             $cookie_name = "mid";
             $cookie_value = $userSession['id'];
             $date_of_expiry = time() + 60 * 60 * 24 * 90;
             setcookie($cookie_name, $this->encrypt($cookie_value), $date_of_expiry, "/");
             //email
             $cookie_name = "e";
             $cookie_value = $userSession['email'];
             setcookie($cookie_name, $this->encrypt($cookie_value), $date_of_expiry, "/");
             //cookie token
             $cookie_name = "token";
             $cookie_token = substr(md5(uniqid(rand(), true)), 0, 20);
             setcookie($cookie_name, $this->encrypt($cookie_token), $date_of_expiry, "/");
             $member->modified = date('Y-m-d H:i:s');
             $member->cookie_token = $this->security->hash($cookie_token);
             if ($member->update()) {
                 $this->flash->success('<button type="button" class="close" data-dismiss="alert">×</button>You are now logged in.');
                 $this->response->redirect('biz/page/' . $userSession['id']);
             }
         } else {
             $this->flash->error('<button type="button" class="close" data-dismiss="alert">×</button>Incorrect username or password.');
             $this->response->redirect('');
         }
     }
 }
Exemplo n.º 4
0
 public function admin_addAction()
 {
     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');
         $middleName = $this->request->getPost('middle_name');
         $lastName = $this->request->getPost('last_name');
         $street = $this->request->getPost('street');
         $city = $this->request->getPost('city');
         $country_id = $this->request->getPost('country_id');
         $mobile = $this->request->getPost('mobile');
         $email = $this->request->getPost('email');
         $password = $this->request->getPost('password');
         if (empty($firstName) || empty($lastName) || empty($email) || empty($password)) {
             $this->flash->warning('<button type="button" class="close" data-dismiss="alert">×</button>All fields required');
             return $this->response->redirect();
         }
         if (!empty($email) && Users::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();
         }
         $user = new Users();
         $user->created = date('Y-m-d H:i:s');
         $user->modified = date('Y-m-d H:i:s');
         $user->first_name = $firstName;
         $user->middle_name = $middleName;
         $user->last_name = $lastName;
         $user->mobile = $mobile;
         $user->street = $street;
         $user->city = $city;
         $user->country_id = $country_id;
         $user->email = $email;
         $user->password = $this->security->hash($password);
         if ($user->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 = $user->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' => 'admin/user/emailConfimation/' . $user->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();
     }
     $countries = Countries::find();
     $this->view->setVar('countries', $countries);
 }
Exemplo n.º 5
0
 /**
  * Confirms an e-mail, if the user must change its password then changes it
  */
 public function confirmEmail2Action()
 {
     if ($this->request->isPost()) {
         if ($this->request->getPost()) {
             $this->response->setContentType('application/json');
             $code = $this->request->getPost('code');
             $confirmation = EmailConfirmations::findFirstByCode($code);
             if (!$confirmation) {
                 $data = array('code' => 1, 'status' => 'error', 'msg' => 'invalid code');
             } else {
                 $confirmation->confirmed = 'Y';
                 $confirmation->user->activated = 1;
                 $confirmation->code = 'ffghfghfhf';
                 $confirmation->save();
                 $data = array('code' => 2, 'status' => 'success', 'msg' => 'The email was successfully confirmed. Now you must change your password');
             }
             $this->response->setContent(json_encode($data));
             $this->response->send();
         }
     }
 }
Exemplo n.º 6
0
 public function advertiser_emailConfimationAction($userId = null, $email = null, $activationToken = null)
 {
     $emaiConfirmed = EmailConfirmations::findFirst(array('columns' => '*', 'conditions' => 'user_id = ?1 AND email=?2 AND token = ?3 AND confirmed = ?4', 'bind' => array(1 => $userId, 2 => $email, 3 => $activationToken, 4 => 'N')));
     if ($emaiConfirmed) {
         $emaiConfirmed->confirmed = 'Y';
         $emaiConfirmed->update();
         error_log('PASOK Confirmed');
         $this->flash->success('<button type="button" class="close" data-dismiss="alert">×</button><H4>You \'re email has been confirmed.</H4>You\'re now officially part of the <strong>MyBarangay</strong> community. Mabuhay!');
         //return $this->response->redirect();
     } else {
         //return $this->response->redirect();
     }
 }