/** * Contact Action * * @package base-app * @version 2.0 */ public function contactAction() { $this->tag->setTitle(__('Contact')); if ($this->request->isPost() === true) { $validation = new \Baseapp\Extension\Validation(); $validation->add('fullName', new \Phalcon\Validation\Validator\PresenceOf()); $validation->add('content', new \Phalcon\Validation\Validator\PresenceOf()); $validation->add('content', new \Phalcon\Validation\Validator\StringLength(array('max' => 5000, 'min' => 10))); $validation->add('email', new \Phalcon\Validation\Validator\PresenceOf()); $validation->add('email', new \Phalcon\Validation\Validator\Email()); $validation->add('repeatEmail', new \Phalcon\Validation\Validator\Confirmation(array('with' => 'email'))); $validation->setLabels(array('fullName' => __('Full name'), 'content' => __('Content'), 'email' => __('Email'), 'repeatEmail' => __('Repeat email'))); $messages = $validation->validate($_POST); if (count($messages)) { $this->view->setVar('errors', $validation->getMessages()); $this->flashSession->warning($this->tag->linkTo(array('#', 'class' => 'close', 'title' => __("Close"), '×')) . '<strong>' . __('Warning') . '!</strong> ' . __("Please correct the errors.")); } else { $this->flashSession->notice($this->tag->linkTo(array('#', 'class' => 'close', 'title' => __("Close"), '×')) . '<strong>' . __('Success') . '!</strong> ' . __("Message was sent")); $email = new \Baseapp\Library\Email(); $email->prepare(__('Contact'), $this->config->app->admin, 'contact', array('fullName' => $this->request->getPost('fullName'), 'email' => $this->request->getPost('email'), 'content' => $this->request->getPost('content'))); $email->addReplyTo($this->request->getPost('email')); if ($email->Send() === true) { unset($_POST); } else { \Baseapp\Bootstrap::log($email->ErrorInfo); } } } }
/** * Add new payment method * * @package base-app * @version 2.0 * * @param array $checkout data * @return object payment or errors */ public function add($checkout) { $validation = new \Baseapp\Extension\Validation(); $validation->add('firstname', new \Phalcon\Validation\Validator\PresenceOf()); $validation->add('lastname', new \Phalcon\Validation\Validator\PresenceOf()); $validation->add('email', new \Phalcon\Validation\Validator\PresenceOf()); $validation->add('email', new \Phalcon\Validation\Validator\Email()); $messages = $validation->validate($_POST); if (count($messages)) { return $validation->getMessages(); } else { $this->user_id = $this->getDI()->getShared('auth')->get_user()->id; $this->firstname = $this->getDI()->getShared('request')->getPost('firstname', 'string'); $this->lastname = $this->getDI()->getShared('request')->getPost('lastname', 'string'); $this->email = $this->getDI()->getShared('request')->getPost('email'); $this->quantity = $checkout['quantity']; $this->amount = $checkout['price']; $this->total = $checkout['price'] * $checkout['quantity']; $date = date("Y-m-d H:i:s"); $this->control = md5($this->getDI()->getShared('request')->getPost('email') . $date); $this->state = 'REQUEST'; $this->date = $date; $this->note = $this->getDI()->getShared('request')->getPost('note', 'string'); $this->ip = $this->getDI()->getShared('request')->getClientAddress(); $this->user_agent = $this->getDI()->getShared('request')->getUserAgent(); if ($this->create() === true) { return $this; } else { \Baseapp\Bootstrap::log($this->getMessages()); return $this->getMessages(); } } }
/** * Sign up User method * * @version 2.0 */ public function signup() { $validation = new \Baseapp\Extension\Validation(); $validation->add('username', new \Phalcon\Validation\Validator\PresenceOf()); $validation->add('username', new \Baseapp\Extension\Uniqueness(array('model' => '\\Baseapp\\Models\\Users'))); $validation->add('username', new \Phalcon\Validation\Validator\StringLength(array('min' => 4, 'max' => 24))); $validation->add('password', new \Phalcon\Validation\Validator\PresenceOf()); $validation->add('repeatPassword', new \Phalcon\Validation\Validator\Confirmation(array('with' => 'password'))); $validation->add('email', new \Phalcon\Validation\Validator\PresenceOf()); $validation->add('email', new \Phalcon\Validation\Validator\Email()); $validation->add('email', new \Baseapp\Extension\Uniqueness(array('model' => '\\Baseapp\\Models\\Users'))); $validation->add('repeatEmail', new \Phalcon\Validation\Validator\Confirmation(array('with' => 'email'))); $validation->setLabels(array('username' => __('Username'), 'password' => __('Password'), 'repeatPassword' => __('Repeat password'), 'email' => __('Email'), 'repeatEmail' => __('Repeat email'))); $messages = $validation->validate($_POST); if (count($messages)) { return $validation->getMessages(); } else { $this->username = $this->request->getPost('username'); $this->password = $this->getDI()->getShared('auth')->hash($this->request->getPost('password')); $this->email = $this->request->getPost('email'); $this->logins = 0; if ($this->create() === true) { $hash = md5($this->id . $this->email . $this->password . $this->getDI()->getShared('config')->auth->hash_key); $email = new Email(); $email->prepare(__('Activation'), $this->request->getPost('email'), 'activation', array('username' => $this->request->getPost('username'), 'hash' => $hash)); if ($email->Send() === true) { unset($_POST); return $this; } else { \Baseapp\Bootstrap::log($email->ErrorInfo); return false; } } else { \Baseapp\Bootstrap::log($this->getMessages()); return false; } } }
/** * USER RESET PASSWORD * This is the process for a user to reset their password if they have forgotten it. * It works in the usual way - user enters email address and if the email address is * recognised, the system sends a reset link to their email. The reset link is * encrypted and contains a JSON encoded object which has the user id, username, * time (link was generated) and a hash key for further verification. */ public function password_resetAction() { // user clicks link via email so we check them then show change password form if ($this->request->getQuery('c')) { // decrypt user $dec = rawurldecode($this->request->getQuery('c')); $decr = $this->getDI()->getShared('crypt')->decrypt($dec); $decar = json_decode($decr); // get the decrypted user info from url $user_id = $decar->user_id; $user_name = $decar->username; $time = $decar->time; $key = $decar->key; // check the link has not expired if ($time > time() - 7200) { // link expires after 2 hours // Show the set form $user = Users::findFirst(array('id=:user_id: AND username=:username:'******'bind' => array('user_id' => $user_id, 'username' => $user_name))); if ($user == TRUE) { $hash = md5($user->id . $user->email . $user->password . $this->config->auth->hash_key); if ($key == $hash) { $this->view->setVar('c', rawurlencode($dec)); $this->view->setVar('user', $user->id); $this->view->setVar('username', $user_name); } else { $this->flashSession->error('<i class="close icon"></i>' . '<div class="ui header">' . __('Error') . '!</div> ' . '<div class="content">Invalid key. You may have used an out of date link.</div>'); } } else { $this->flashSession->error('<i class="close icon"></i>' . '<div class="ui header">' . __('Error') . '!</div> ' . '<div class="content">Invalid user.</div>'); } } else { $this->flashSession->error('<i class="close icon"></i>' . '<div class="ui header">' . __('Error') . '!</div> ' . '<div class="content">The password reset link is invalid or has expired.</div>'); } // send the reset email } else { if ($this->request->isPost() == TRUE) { // request reset email submission if ($this->request->getPost('action') == 'request_reset') { if ($this->security->checkToken()) { $validation = new \Baseapp\Extension\Validation(); $validation->add('email', new \Phalcon\Validation\Validator\PresenceOf()); $validation->add('email', new \Phalcon\Validation\Validator\Email()); $validation->setLabels(array('email' => 'Email')); $messages = $validation->validate($_POST); if (count($messages)) { $this->view->setVar('errors', $validation->getMessages()); } else { $email = $this->request->getPost('email', 'email'); $email_conf = Users::findFirst(array('email=:email:', 'bind' => array('email' => $email))); if ($email_conf == TRUE) { $send = $email_conf->sendReset($email); if ($send) { $this->flashSession->notice('<i class="close icon"></i>' . '<div class="ui header">' . __('Check your inbox!') . '!</div> ' . '<div class="content">An email has been sent to you containing a link to reset your password.</div>'); } } else { $this->flashSession->error('<i class="close icon"></i>' . '<div class="ui header">' . __('Error') . '!</div> ' . '<div class="content">We do not have a record of that email address.</div>'); } } } // process and validate the reset form } else { if ($this->request->getPost('action') == 'change_pass') { if ($this->security->checkToken()) { // Reset the password if ($this->request->getPost('c')) { $dec = rawurldecode($this->request->getPost('c')); $decr = $this->getDI()->getShared('crypt')->decrypt($dec); $decar = json_decode($decr); // get the decrypted user info from form $user_id = $decar->user_id; $user_name = $decar->username; $time = $decar->time; $key = $decar->key; if ($time > time() - 7200) { // link expires after 2 hours // validate $user = Users::findFirst(array('id=:user_id: AND username=:username:'******'bind' => array('user_id' => $user_id, 'username' => $user_name))); if ($user == TRUE) { $hash = md5($user->id . $user->email . $user->password . $this->config->auth->hash_key); if ($key == $hash) { $this->view->setVar('username', $user->username); $this->view->setVar('c', $this->request->getPost('c')); $validation = new \Baseapp\Extension\Validation(); $validation->add('pass', new \Baseapp\Extension\Password()); $validation->add('pass_conf', new \Phalcon\Validation\Validator\Confirmation(array('with' => 'pass'))); $validation->setLabels(array('pass' => 'Password', 'pass_conf' => 'Confirm password')); $messages = $validation->validate($_POST); if (count($messages)) { $this->view->setVar('errors', $validation->getMessages()); } else { // update user's password $new_pass = $this->auth->hashPass($this->request->getPost('pass')); $user->password = $new_pass; if ($user->update() == TRUE) { $this->flashSession->success('<i class="close icon"></i>' . '<div class="ui header">' . __('Password updated') . '!</div> ' . '<div class="content">Your password has been successfully updated. Please login.</div>'); $this->view->setVar('completed', '1'); $this->response->redirect('user/signin'); } else { echo 'Update failed'; exit; } } } else { $this->flashSession->error('<i class="close icon"></i>' . '<div class="ui header">' . __('Error') . '!</div> ' . '<div class="content">Invalid key.</div>'); } } else { $this->flashSession->error('<i class="close icon"></i>' . '<div class="ui header">' . __('Error') . '!</div> ' . '<div class="content">Invalid user.</div>'); } } else { $this->flashSession->error('<i class="close icon"></i>' . '<div class="ui header">' . __('Error') . '!</div> ' . '<div class="content">The password reset link is invalid or has expired.</div>'); } } } else { // CSRF check failed $this->flashSession->warning('<i class="close icon"></i>' . '<div class="ui header">Form expired!</div> ' . '<div class="content">The form has expired. Please try again.</div>'); } } } } else { // show the initial form where user enters email } } }
/** * Sign up User method * */ public function signup() { $validation = new \Baseapp\Extension\Validation(); $validation->add('username', new \Phalcon\Validation\Validator\PresenceOf()); $validation->add('username', new \Baseapp\Extension\Uniqueness(array('model' => '\\Baseapp\\Models\\Users'))); $validation->add('username', new \Phalcon\Validation\Validator\StringLength(array('min' => 4, 'max' => 24))); $validation->add('username', new \Phalcon\Validation\Validator\Regex(array('pattern' => '/^[[:alnum:]_]+( [[:alnum:]]+)*$/', 'message' => 'User name must only contain letters, numbers and space'))); $validation->add('password', new \Baseapp\Extension\Password()); $validation->add('repeatPassword', new \Phalcon\Validation\Validator\Confirmation(array('with' => 'password'))); $validation->add('email', new \Phalcon\Validation\Validator\PresenceOf()); $validation->add('email', new \Phalcon\Validation\Validator\Email()); $validation->add('email', new \Baseapp\Extension\Uniqueness(array('model' => '\\Baseapp\\Models\\Users'))); // agree to terms - Note "value" replaces "accepted" for backward compatibility // with older versions of Phalcon. E.g. on 2.0.3 this validation works backwards // if "accepted" is used! $validation->add('agree', new \Phalcon\Validation\Validator\Identical(array('value' => 'yes', 'message' => 'You must accept the terms and conditions'))); // Recaptcha validation if ($this->getDI()->getShared('config')->recaptcha->enabled == '1') { $validation->add('g-recaptcha-response', new \Baseapp\Extension\Recaptcha()); } $validation->setLabels(array('username' => __('Username'), 'password' => __('Password'), 'repeatPassword' => __('Repeat password'), 'email' => __('Email'), 'repeatEmail' => __('Repeat email'))); $messages = $validation->validate($_POST); // Check for validation messages or Recaptcha error if (count($messages)) { return $validation->getMessages(); } else { $this->username = $this->request->getPost('username'); $this->password = $this->getDI()->getShared('auth')->hashPass($this->request->getPost('password')); $this->email = $this->request->getPost('email'); $this->logins = 0; if ($this->create() === true) { $hash = md5($this->id . $this->email . $this->password . $this->getDI()->getShared('config')->auth->hash_key); $this->setUserRole($this->id, 'unconfirmed'); // log new user in $login = $this->getDI()->getShared('auth')->login($this->request->getPost('username'), $this->request->getPost('password'), FALSE); $email = new Email(); $email->prepare(__('Activation'), $this->request->getPost('email'), 'activation', array('username' => $this->request->getPost('username'), 'hash' => $hash)); if ($email->Send() === true) { unset($_POST); return $this; } else { \Baseapp\Bootstrap::log($email->ErrorInfo); return false; } } else { \Baseapp\Bootstrap::log($this->getMessages()); return false; } } }
/** * Contact Action */ public function contactAction() { $this->tag->setTitle(__('Contact')); $this->assets->addJs('js/forms.js'); if ($this->request->isPost() === true) { $validation = new \Baseapp\Extension\Validation(); $validation->add('fullName', new \Phalcon\Validation\Validator\PresenceOf()); $validation->add('content', new \Phalcon\Validation\Validator\PresenceOf()); $validation->add('content', new \Phalcon\Validation\Validator\StringLength(array('max' => 5000, 'min' => 10))); $validation->add('email', new \Phalcon\Validation\Validator\PresenceOf()); $validation->add('email', new \Phalcon\Validation\Validator\Email()); $validation->add('repeatEmail', new \Phalcon\Validation\Validator\Confirmation(array('with' => 'email'))); // Recaptcha validation if ($this->config->recaptcha->enabled == '1') { $validation->add('g-recaptcha-response', new \Baseapp\Extension\Recaptcha()); } $validation->setLabels(array('fullName' => __('Full name'), 'content' => __('Content'), 'email' => __('Email'), 'repeatEmail' => __('Repeat email'))); $messages = $validation->validate($_POST); if (count($messages)) { $this->view->setVar('errors', $validation->getMessages()); $this->flashSession->warning('<i class="close icon"></i><div class="header">' . __('Warning') . '!</div> ' . __("Please correct the errors.")); } else { $this->flashSession->success('<i class="close icon"></i><div class="header">' . __('Success') . '!</div> ' . __("Message was sent")); $email = new \Baseapp\Library\Email(); $email->prepare(__('Contact'), $this->config->app->admin, 'contact', array('fullName' => $this->request->getPost('fullName'), 'email' => $this->request->getPost('email'), 'content' => $this->request->getPost('content'))); $email->addReplyTo($this->request->getPost('email')); if ($email->Send() === true) { unset($_POST); } else { \Baseapp\Bootstrap::log($email->ErrorInfo); } } } }