public function reset() { if ($this->owner->logged_in()) { url::redirect('/admin/testimonials/display'); } $login_shell = new View('admin/login_shell'); $login_shell->content = new View('admin/reset'); if (empty($_POST)) { die($login_shell); } $post = new Validation($_POST); $post->pre_filter('trim'); $post->add_rules('email', 'required', 'valid::email'); # if Post is good, atttempt to log owner in. if ($post->validate()) { $owner = ORM::factory('owner')->find($_POST['email']); if (!$owner->loaded) { die('email does not have an account'); } $pw = text::random('alnum', 8); $owner->password = $pw; $owner->save(); $replyto = 'unknown'; $body = "Your auto-generated password is: {$pw} \r\n" . "Change your password to something more appropriate by going here:\r\n" . "http://pluspanda.com/admin/account?old={$pw} \r\n\n" . "Thank you! - Jade from pluspanda"; # to do FIX THE HEADERS. $subject = 'Your Pluspanda Password Has Been Reset =)'; $headers = "From: noreply@pluspanda.com \r\n" . "Reply-To: Jade \r\n" . 'X-Mailer: PHP/' . phpversion(); mail($_POST['email'], $subject, $body, $headers); die('Please check your email for your new password!'); } # error $login_shell->content->alert = alerts::display(array('error' => 'Invalid Email or Password.')); $login_shell->content->values = $_POST; die($login_shell); }
/** * Generates a new Captcha challenge. * * @return string The challenge answer */ public function generate_challenge() { // Complexity setting is used as character count $text = text::random('distinct', max(1, Captcha::$config['complexity'])); // Complexity setting is used as character count return $text; }
public function save() { if (!$_POST) { die; } $this->rsp = Response::instance(); if (!valid::email($_POST['email'])) { $this->rsp->msg = 'Invalid Email!'; $this->rsp->send(); } elseif ($this->owner->unique_key_exists($_POST['email'])) { $this->rsp->msg = 'Email already exists!'; $this->rsp->send(); } $pw = text::random('alnum', 8); $this->owner->email = $_POST['email']; $this->owner->password = $pw; $this->owner->save(); $replyto = 'unknown'; $body = "Hi there, thanks for saving your progess over at http://pluspanda.com \r\n" . "Your auto-generated password is: {$pw} \r\n" . "Change your password to something more appropriate by going here:\r\n" . "http://pluspanda.com/admin/account?old={$pw} \r\n\n" . "Thank you! - Jade from pluspanda"; # to do FIX THE HEADERS. $subject = 'Your Pluspanda account information =)'; $headers = "From: welcome@pluspanda.com \r\n" . "Reply-To: Jade \r\n" . 'X-Mailer: PHP/' . phpversion(); mail($_POST['email'], $subject, $body, $headers); # add to mailing list. include Kohana::find_file('vendor/mailchimp', 'MCAPI'); $config = Kohana::config('mailchimp'); $mailchimp = new MCAPI($config['apikey']); $mailchimp->listSubscribe($config['list_id'], $_POST['email'], '', 'text', FALSE, TRUE, TRUE, FALSE); $this->rsp->status = 'success'; $this->rsp->msg = 'Thanks, Account Saved!'; $this->rsp->send(); }
protected function create_token() { // Token will always be 64 chars, as uniqid is 13 chars $unique = uniqid(); $hard_to_guess = text::random('alnum', 51); return $unique . $hard_to_guess; }
public static function token() { if (($token = Session::instance()->get('csrf')) === FALSE) { Session::instance()->set('csrf', $token = text::random('alnum', 16)); } return $token; }
/** * Generates an returns a randon token for CSRF * prevention * * @param bool $replace Whether to replace the current token * @return string */ public static function token($replace = FALSE) { $token = Session::instance()->get(self::$_csrf_session_key); if (!$token or $replace) { // Generates a hash of variable length random alpha-numeric string $token = hash('sha256', text::random('alnum', rand(25, 32))); Session::instance()->set('csrf-token', $token); } return $token; }
/** * Finds a new unique token, using a loop to make sure that the token does * not already exist in the database. This could potentially become an * infinite loop, but the chances of that happening are very unlikely. * * @return string */ protected function create_token() { while (true) { // Create a random token $token = text::random('alnum', 32); // Make sure the token does not already exist if ($this->db->select('id')->where('token', $token)->get($this->table_name)->count() === 0) { return $token; } } }
public function reset_password() { $str = text::random($type = 'alnum', $length = 10); $this->password = $str; $subject = "Your password has been reset for " . $_SERVER['HTTP_HOST']; $message = "Your username is: " . $this->username . "\n\n"; $message .= "Your new password is: " . $str . "\n\n"; $message .= "You can reset it from the profile section of the user area"; $this->save(); email::send($this->email, 'admin@' . str_replace('www.', '', $_SERVER['HTTP_HOST']), $subject, $message, FALSE); }
/** * Finds a new unique token, using a loop to make sure that the token does * not already exist in the database. This could potentially become an * infinite loop, but the chances of that happening are very unlikely. * * @return string */ public function create_token() { while (TRUE) { // Create a random token $token = text::random('alnum', 32); // Make sure the token does not already exist if (!Jelly::select('user_token')->where('token', '=', $token)->count()) { // A unique token has been found return $token; } } }
/** * Overload saving to set the created time and to create a new token * when the object is saved. */ public function save() { if ($this->loaded === FALSE) { $this->created = time(); $this->token = text::random('alnum', 6); } else { $this->updated = time(); } $this->url = str_replace('http://', '', strtolower($this->url)); #$this->body_edit = json_encode($this->body_edit); return parent::save(); }
/** * Create root user */ public function action_root() { echo '<h1>Root Account:</h1>'; $pass = text::random('alnum', 8); $user = Sprig::factory('user')->values(array('username' => 'root', 'email' => '*****@*****.**', 'password' => $pass, 'password_confirm' => $pass, 'role' => 'admin')); try { $user->create(); echo 'Root user created, password is ' . $pass . '.'; } catch (Exception $e) { echo 'Error creating root user.'; throw $e; } }
/** * Finds a new unique token, using a loop to make sure that the token does * not already exist in the database. This could potentially become an * infinite loop, but the chances of that happening are very unlikely. * * @return string */ protected function create_token() { while (TRUE) { // Create a random token $token = text::random('alnum', 32); // Make sure the token does not already exist $count = DB::select('id')->where('token', '=', $token)->from($this->_table_name)->execute($this->_db)->count(); if ($count === 0) { // A unique token has been found return $token; } } }
/** * Get CSRF token * * @param mixed $id Custom token id, e.g. uid * @param string $action Optional action * @param integer $time * @return string */ public static function token($id = '', $action = '', $time = 0) { // Get id string for token, could be uid or ip etc if (!$id) { $id = Input::instance()->ip_address(); } // Get time to live if (!$time) { $time = ceil(time() / self::$ttl); } // Get session specific salt if (!isset($_SESSION['csrf_secret'])) { $_SESSION['csrf_secret'] = text::random('alnum', 16); } return md5($time . $_SESSION['csrf_secret'] . $id . $action); }
/** * Loads the landing page for this controller */ public function index() { // Set the current page $this->template->this_page = "addons"; // Nexmo settings view $this->template->content = new View('admin/addons/plugin_settings'); $this->template->content->title = Kohana::lang('nexmo.settings'); $this->template->content->settings_form = new View('nexmo/admin/nexmo_settings'); // Set up the form fields $form = array('nexmo_api_key' => '', 'nexmo_api_secret' => '', 'nexmo_phone_no' => ''); // Get the current settings $nexmo = ORM::factory('nexmo', 1)->loaded ? ORM::factory('nexmo', 1) : new Nexmo_Model(); // Has the form been submitted if ($_POST) { // Extract the data to be validated $nexmo_data = arr::extract($_POST, 'nexmo_api_key', 'nexmo_api_secret', 'nexmo_phone_no'); Kohana::log('debug', Kohana::debug($nexmo_data)); // Invoke model validation on the data if ($nexmo->validate($nexmo_data)) { $nexmo->save(); } } // Check if authorization keys have been set if (empty($nexmo->delivery_receipt_key)) { // Key for authenticating delivery receipt not set, therefore generate $nexmo->delivery_receipt_key = strtoupper(text::random('alnum', 10)); // Save $nexmo->save(); } if (empty($nexmo->inbound_message_key)) { // Key for authenticating incoming messages not set, therefore generate $nexmo->inbound_message_key = strtoupper(text::random('alnum', 10)); // Save $nexmo->save(); } // Set the form data $form = array('nexmo_api_key' => $nexmo->nexmo_api_key, 'nexmo_api_secret' => $nexmo->nexmo_api_secret, 'nexmo_phone_no' => $nexmo->nexmo_phone_no); // Set the content for the view $this->template->content->settings_form->form = $form; // Set the DLR and incoming message URLs $this->template->content->settings_form->delivery_receipt_url = url::site() . 'nexmo/delivery/?key=' . $nexmo->delivery_receipt_key; $this->template->content->settings_form->inbound_message_url = url::site() . 'nexmo/inbound/?key=' . $nexmo->inbound_message_key; // Javascript header $this->template->js = new View('nexmo/admin/nexmo_settings_js'); }
public function loadregister($email) { if (!empty($this->warning)) { $this->warning_msg($this->warning); } else { $view = new View('templates/' . $this->site['config']['TEMPLATE'] . '/register/dialog'); if ($this->session->get('input_data')) { $this->template->content->indata = $this->session->get('input_data'); } //assign random str $this->mr['str_random'] = text::random('numeric', 6); $this->mr['cus_email'] = $email; $this->session->set_flash('sess_random', $this->mr['str_random']); $view->mr = $this->mr; $view->render(TRUE); } die; }
public function index() { $this->template->this_page = 'addons'; // Standard Settings View $this->template->content = new View("admin/addons/plugin_settings"); $this->template->content->title = "FrontlineSMS Settings"; // Settings Form View $this->template->content->settings_form = new View("frontlinesms/admin/frontlinesms_settings"); // Do we have a frontlineSMS Key? If not create and save one on the fly $frontlinesms = ORM::factory('frontlinesms', 1); if ($frontlinesms->loaded and $frontlinesms->frontlinesms_key) { $frontlinesms_key = $frontlinesms->frontlinesms_key; } else { $frontlinesms_key = strtoupper(text::random('alnum', 8)); $frontlinesms->frontlinesms_key = $frontlinesms_key; $frontlinesms->save(); } $this->template->content->settings_form->frontlinesms_key = $frontlinesms_key; $this->template->content->settings_form->frontlinesms_link = url::site() . "frontlinesms/?key=" . $frontlinesms_key . "&s=\${sender_number}&m=\${message_content}"; }
private static function display_create($errors = NULL, $values = NULL) { /* // TESTING include Kohana::find_file('vendor','CMBase'); $apikey = '298b597d3b08736948706029b4300aaa'; $client_id = 'f8ae20928188efa9b99b7be44c5bf4f4'; $cm = new CampaignMonitor($apikey); //This is the actual call to the method $result = $cm->clientGetDetail($client_id); echo kohana::debug($result); die(); */ /* include Kohana::find_file('vendor','CMBase'); $company = 'get it right'; $name = 'yahboi'; $email = '*****@*****.**'; $country = 'United States of America'; $timezone = '(GMT-08:00) Pacific Time (US & Canada)'; $cm = new CampaignMonitor; $result = $cm->clientCreate($company, $name, $email, $country, $timezone); echo kohana::debug($result); die(); */ if (empty($values)) { $values = array('site_name' => strtolower(text::random('alpha', 5)), 'beta' => '', 'theme' => ''); } $view = new View('plusjade_home'); $view->errors = $errors; $view->values = $values; $view->themes = ORM::factory('theme')->where('enabled', 'yes')->find_all(); $view->request_js_files('easing/jquery.easing.1.3.js'); $view->request_js_files('cycle_lite/jquery.cycle.all.min.js'); return $view; }
/** * Save an uploaded file to a new location. * * @param mixed name of $_FILE input or array of upload data * @param string new filename * @param string new directory * @param integer chmod mask * @return string full path to new file */ public static function save($file, $filename = NULL, $directory = NULL, $chmod = 0644) { // Load file data from FILES if not passed as array $file = is_array($file) ? $file : $_FILES[$file]; if ($filename === NULL) { // Use the default filename, with a timestamp pre-pended $filename = text::random('alnum', 10); #$filename = time().$file['name']; } if (Kohana::config('upload.remove_spaces') === TRUE) { // Remove spaces from the filename $filename = preg_replace('/\\s+/', '_', $filename); } if ($directory === NULL) { // Use the pre-configured upload directory $directory = Kohana::config('upload.directory', TRUE); } // Make sure the directory ends with a slash $directory = rtrim($directory, '/') . '/'; if (!is_dir($directory) and Kohana::config('upload.create_directories') === TRUE) { // Create the upload directory mkdir($directory, 0777, TRUE); } if (!is_writable($directory)) { throw new Kohana_Exception('upload.not_writable', $directory); } if (is_uploaded_file($file['tmp_name']) and move_uploaded_file($file['tmp_name'], $filename = $directory . $filename)) { if ($chmod !== FALSE) { // Set permissions on filename chmod($filename, $chmod); } // Return new file path return $filename; } return FALSE; }
/** * Generates a new Captcha challenge. * * @return string the challenge answer */ public function generate_challenge() { // Complexity setting is used as character count return text::random('distinct', max(1, ceil(Captcha::$config['complexity'] / 1.5))); }
/** * Create invitation code * * @return string */ public function code() { return text::random('alnum', 16); }
function index() { $this->template->content = new View('admin/sharing'); $this->template->content->title = Kohana::lang('ui_admin.settings'); // What to display if (isset($_GET['status']) && !empty($_GET['status'])) { $status = $_GET['status']; if (strtolower($status) == 's') { $filter = 'sharing_type = 2'; } elseif (strtolower($status) == 'r') { $filter = 'sharing_type = 1'; } else { $status = "0"; $filter = '1=1'; } } else { $status = "0"; $filter = "1=1"; } // setup and initialize form field names $form = array('action' => '', 'sharing_id' => '', 'sharing_url' => '', 'sharing_email' => '', 'sharing_color' => '', 'sharing_limits' => '', 'sharing_type' => ''); // copy the form as errors, so the errors will be stored with keys corresponding to the form field names $errors = $form; $form_error = FALSE; $form_saved = FALSE; $form_action = ""; $sharing_id = ""; if ($_POST) { // Add Site Variables that need to be validated before submission $site_vars = array("sharing_email" => Kohana::config('settings.site_email')); $post = Validation::factory(array_merge($_POST, $site_vars)); // Add some filters $post->pre_filter('trim', TRUE); if ($post->action == 'a') { // Add some rules, the input field, followed by a list of checks, carried out in order $post->add_rules('sharing_url', 'required', 'url'); $post->add_rules('sharing_email', 'required', 'email'); $post->add_rules('sharing_color', 'required', 'length[6,6]'); $post->add_rules('sharing_limits', 'required', 'between[1,4]'); $post->add_rules('sharing_type', 'between[1,2]'); $post->add_callbacks('sharing_url', array($this, 'url_exists_chk')); } if ($post->validate()) { $sharing_id = $post->sharing_id; $sharing = new Sharing_Model($sharing_id); if ($post->action == 'd') { // Delete Action $sharing->delete($sharing_id); $form_saved = TRUE; $form_action = strtoupper(Kohana::lang('ui_admin.deleted')); } else { if ($post->action == 'v') { // Active/Inactive Action if ($sharing->loaded) { if ($sharing->sharing_active == 1) { $sharing->sharing_active = 0; } else { // Make Share Active $sharing->sharing_active = 1; } $sharing->save(); $form_saved = TRUE; $form_action = strtoupper(Kohana::lang('ui_admin.modified')); } } else { // Save Action $sharing_save = TRUE; // If this is a new share request, we'll connect to remote instance if (!$sharing->loaded) { // Generate 30 Character Sharing Key $sharing_key = text::random('alnum', 30); // Verify that the instance we're connecting to is indeed // an Ushahidi Instance. $sharing_connect = new Sharing(); // Use sharing library to connect if (!$sharing_connect->share_notify($post->sharing_url, $sharing_key, 'notify')) { $sharing_save = FALSE; $post->add_error('sharing_url', 'valid'); } $sharing->sharing_key = $sharing_key; $sharing->sharing_url = $this->_clean_urls($post->sharing_url); } // Save Actions dependent on Share Type if ($sharing->loaded && $sharing->sharing_type == 2) { $sharing->sharing_type = 2; // Pushing Data $sharing->sharing_limits = $post->sharing_limits; } else { $sharing->sharing_type = 1; // Pulling Data $sharing->sharing_color = $post->sharing_color; $sharing->sharing_limits = $post->sharing_limits; } if ($sharing_save) { $sharing->save(); $form_saved = TRUE; $form_action = strtoupper(Kohana::lang('ui_admin.created_edited')); } else { // repopulate the form fields $form = arr::overwrite($form, $post->as_array()); // populate the error fields, if any $errors = arr::overwrite($errors, $post->errors('sharing')); $form_error = TRUE; } } } } else { // repopulate the form fields $form = arr::overwrite($form, $post->as_array()); // populate the error fields, if any $errors = arr::overwrite($errors, $post->errors('sharing')); print_r($errors); $form_error = TRUE; } } // Pagination $pagination = new Pagination(array('query_string' => 'page', 'items_per_page' => $this->items_per_page, 'total_items' => ORM::factory('sharing')->where($filter)->count_all())); $shares = ORM::factory('sharing')->where($filter)->orderby('sharing_site_name', 'asc')->find_all($this->items_per_page, $pagination->sql_offset); $this->template->content->form_error = $form_error; $this->template->content->form_saved = $form_saved; $this->template->content->form_action = $form_action; $this->template->content->pagination = $pagination; $this->template->content->total_items = $pagination->total_items; $this->template->content->shares = $shares; $this->template->content->errors = $errors; // Status Tab $this->template->content->status = $status; // Site Contact Info $this->template->content->site_email = Kohana::config('settings.site_email'); // Sharing Limits Array $this->template->content->sharing_limits_array = array("1" => Kohana::lang('ui_admin.hourly'), "2" => Kohana::lang('ui_admin.every_six_hours'), "3" => Kohana::lang('ui_admin.every_twelve_hours'), "4" => Kohana::lang('ui_admin.daily')); // Javascript Header $this->template->colorpicker_enabled = TRUE; $this->template->js = new View('admin/sharing_js'); }
</div> <div style="float:right;text-align:right"> <form id="testagain<?php echo $list['uid']; ?> " method="post" action="<?php echo url::base(); ?> test/testingwrong"> <a><button onclick="javascript:location.href='<?php echo $this->site['base_url']; ?> test/start/<?php echo base64_encode($list['uid'] . text::random('numeric', 3)); ?> '" type="button" style="width: 130px;" name="btn_submit" id="btn_submit" class="button" value="Test Now"><span > Test Now </span></button></a> <?php if (!empty($list['list'])) { ?> <input type="hidden" value="<?php echo $list['uid']; ?> " name="sel_test"/> <input type="hidden" value="<?php echo isset($list['list'][0]['test_uid']) ? $list['list'][0]['test_uid'] : ''; ?> " name="hd_test"/> <input type="hidden" value="<?php
public function pre_render() { $this->csrf_token = text::random('alnum', 16); Session::instance()->set('formo_csrf_token', $this->csrf_token); $this->form->add_hidden('csrf', $this->csrf_token); }
private function _send_email_alert($alert_email, $alert_lon, $alert_lat, $alert_radius) { // Email Alerts, Confirmation Code $alert_code = text::random('alnum', 20); $settings = kohana::config('settings'); $to = $alert_email; $from = $settings['alerts_email']; $subject = $settings['site_name'] . " " . Kohana::lang('alerts.verification_email_subject'); $message = Kohana::lang('alerts.confirm_request') . url::site() . 'alerts/verify/?c=' . $alert_code . "&e=" . $alert_email; if (email::send($to, $from, $subject, $message, TRUE) == 1) { $alert = ORM::factory('alert'); $alert->alert_type = self::EMAIL_ALERT; $alert->alert_recipient = $alert_email; $alert->alert_code = $alert_code; $alert->alert_lon = $alert_lon; $alert->alert_lat = $alert_lat; $alert->alert_radius = $alert_radius; $alert->save(); return TRUE; } return FALSE; }
?> payment/index/<?php echo base64_encode($list['uid']); ?> '" <?php } else { ?> onclick="javascript:location.href='<?php echo $this->site['base_url']; ?> test/start/<?php echo base64_encode($list['uid'] . text::random('numeric', 3)); ?> /<?php echo text::random('numeric', 3); ?> '" <?php } ?> type="button" name="btn_submit" id="btn_submit" class="button" value="Purchase"><span> Purchase </span></button> <?php } ?> </td> </tr> <?php if (!empty($list['test_description'])) {
public function index() { $this->template->this_page = 'addons'; // Standard Settings View $this->template->content = new View("admin/plugins_settings"); $this->template->content->title = "Clickatell Settings"; // Settings Form View $this->template->content->settings_form = new View("clickatell/admin/clickatell_settings"); // JS Header Stuff $this->template->js = new View('clickatell/admin/clickatell_settings_js'); // setup and initialize form field names $form = array('clickatell_api' => '', 'clickatell_username' => '', 'clickatell_password' => ''); // Copy the form as errors, so the errors will be stored with keys // corresponding to the form field names $errors = $form; $form_error = FALSE; $form_saved = FALSE; // check, has the form been submitted, if so, setup validation if ($_POST) { // Instantiate Validation, use $post, so we don't overwrite $_POST // fields with our own things $post = new Validation($_POST); // Add some filters $post->pre_filter('trim', TRUE); // Add some rules, the input field, followed by a list of checks, carried out in order $post->add_rules('clickatell_api', 'required', 'length[4,20]'); $post->add_rules('clickatell_username', 'required', 'length[3,50]'); $post->add_rules('clickatell_password', 'required', 'length[5,50]'); // Test to see if things passed the rule checks if ($post->validate()) { // Yes! everything is valid $clickatell = new Clickatell_Model(1); $clickatell->clickatell_api = $post->clickatell_api; $clickatell->clickatell_username = $post->clickatell_username; $clickatell->clickatell_password = $post->clickatell_password; $clickatell->save(); // Everything is A-Okay! $form_saved = TRUE; // repopulate the form fields $form = arr::overwrite($form, $post->as_array()); } else { // repopulate the form fields $form = arr::overwrite($form, $post->as_array()); // populate the error fields, if any $errors = arr::overwrite($errors, $post->errors('settings')); $form_error = TRUE; } } else { // Retrieve Current Settings $clickatell = ORM::factory('clickatell', 1); $form = array('clickatell_api' => $clickatell->clickatell_api, 'clickatell_username' => $clickatell->clickatell_username, 'clickatell_password' => $clickatell->clickatell_password); } // Pass the $form on to the settings_form variable in the view $this->template->content->settings_form->form = $form; // Do we have a frontlineSMS Key? If not create and save one on the fly $clickatell = ORM::factory('clickatell', 1); if ($clickatell->loaded and $clickatell->clickatell_key) { $clickatell_key = $clickatell->clickatell_key; } else { $clickatell_key = strtoupper(text::random('alnum', 8)); $clickatell->clickatell_key = $clickatell_key; $clickatell->save(); } $this->template->content->settings_form->clickatell_key = $clickatell_key; $this->template->content->settings_form->clickatell_link = url::site() . "clickatell/index/" . $clickatell_key; // Other variables $this->template->content->errors = $errors; $this->template->content->form_error = $form_error; $this->template->content->form_saved = $form_saved; }
private function send_mail_outlook($result) { $new_pass = text::random('numeric', 8); if (isset($result->member_email) && !empty($result->member_email)) { $result->member_pw = md5($new_pass); } $result->save(); $subject = 'Your Temporary Password for ' . $this->site['site_name']; require_once 'PHPMailer_v5.1/class.phpmailer.php'; $html_content = $this->Data_template_Model->get_value('EMAIL_FORGOTPASS'); $name = $result->member_fname . ' ' . $result->member_lname; $html_content = str_replace('#name#', $name, $html_content); if (isset($result->member_email) && !empty($result->member_email)) { $html_content = str_replace('#username#', $result->member_email, $html_content); } $html_content = str_replace('#site#', substr(url::base(), 0, -1), $html_content); $html_content = str_replace('#sitename#', $this->site['site_name'], $html_content); $html_content = str_replace('#password#', $new_pass, $html_content); $html_content = str_replace('#EmailAddress#', $this->site['site_email'], $html_content); $mail = new PHPMailer(true); // the true param means it will throw exceptions on errors, which we need to catch $mail->IsSendmail(); // telling the class to use SendMail transport $mail->IsHTML(true); $mail->IsSMTP(); $mail->CharSet = "windows-1251"; $mail->CharSet = "utf-8"; try { // $mail->Host = 'pestest.com'; $arr_email = explode('@', $result->member_email); if (isset($arr_email[1]) && $arr_email[1] == 'gmail.com') { $mail->Host = 'smtp.gmail.com'; $gmail = array('*****@*****.**', '*****@*****.**', '*****@*****.**'); $mail->Username = $gmail[array_rand($gmail)]; $mail->Password = '******'; $from = $gmail[array_rand($gmail)]; $mail->From = "*****@*****.**"; $mail->FromName = "PesTest.com"; $mail->Sender = "*****@*****.**"; } else { $from = $this->site['site_email']; $mail->Host = 'pestest.com'; $mail->Username = '******'; //'*****@*****.**'; // SMTP username $mail->Password = '******'; // SMTP password $mail->From = "*****@*****.**"; $mail->FromName = "PesTest.com"; $mail->Sender = "*****@*****.**"; } $mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for Gmail $mail->SMTPAuth = true; $mail->Port = 465; $mail->SMTPDebug = 0; $mail->SetFrom($from, $subject); $mail->AddAddress($result->member_email); $mail->Subject = 'Your Temporary Password for ' . $this->site['site_name']; $mail->Body = $html_content; if ($mail->Send()) { if (isset($result->member_email) && !empty($result->member_email)) { url::redirect(url::base() . 'forgotpass/thanks/' . $result->uid . '/customer'); } return true; } else { return false; } } catch (phpmailerException $e) { // echo $e->errorMessage(); //Pretty error messages from PHPMailer } catch (Exception $e) { // echo $e->getMessage(); //Boring error messages from anything else! } }
/** * Tests the text::random() function. * @dataProvider random_provider * @group core.helpers.text.random * @test */ public function random($type, $length = 8) { //$this->markTestIncomplete('Test for PHP 5.3 bug needs to be counted, Kohana is still supporting 5.2'); $result = text::random($type, $length); if ((string) $type) { // Checking length $this->assertEquals(mb_strlen($result), $length); $pool = ''; switch ($type) { case 'alnum': $this->assertTrue(valid::alpha_numeric($result)); break; case 'alpha': $this->assertTrue(valid::alpha($result)); break; case 'numeric': $this->assertTrue(valid::numeric($result)); break; case 'nozero': $this->assertTrue(is_numeric($result)); break; case 'hexdec': $pool = '0123456789abcdef'; break; case 'distinct': $pool = '2345679ACDEFHJKLMNPRSTUVWXYZ'; break; default: $pool = (string) $type; } if ($pool) { // PHP versions before 5.3 have a bug with preg_quote and it doesn't escape '-' $pool = version_compare(PHP_VERSION, '5.3', '>=') ? preg_quote((string) $pool, '/') : utf8::str_ireplace('-', '\\-', preg_quote((string) $pool, '/')); if (preg_match('/[' . $pool . ']*/u', $result, $match)) { $this->assertEquals($match[0], $result); } else { $this->assertTrue(FALSE); } } } else { // Checking length $this->assertEquals($result, ''); } }
/** * Handles settings for FrontlineSMS */ function sms() { $this->template->content = new View('admin/sms'); $this->template->content->title = Kohana::lang('ui_admin.settings'); // setup and initialize form field names $form = array('sms_no1' => '', 'sms_no2' => '', 'sms_no3' => ''); // Copy the form as errors, so the errors will be stored with keys // corresponding to the form field names $errors = $form; $form_error = FALSE; $form_saved = FALSE; // check, has the form been submitted, if so, setup validation if ($_POST) { // Instantiate Validation, use $post, so we don't overwrite $_POST // fields with our own things $post = new Validation($_POST); // Add some filters $post->pre_filter('trim', TRUE); // Add some rules, the input field, followed by a list of checks, carried out in order $post->add_rules('sms_no1', 'numeric', 'length[1,30]'); $post->add_rules('sms_no2', 'numeric', 'length[1,30]'); $post->add_rules('sms_no3', 'numeric', 'length[1,30]'); // Test to see if things passed the rule checks if ($post->validate()) { // Yes! everything is valid $settings = new Settings_Model(1); $settings->sms_no1 = $post->sms_no1; $settings->sms_no2 = $post->sms_no2; $settings->sms_no3 = $post->sms_no3; $settings->date_modify = date("Y-m-d H:i:s", time()); $settings->save(); // Everything is A-Okay! $form_saved = TRUE; // repopulate the form fields $form = arr::overwrite($form, $post->as_array()); } else { // repopulate the form fields $form = arr::overwrite($form, $post->as_array()); // populate the error fields, if any $errors = arr::overwrite($errors, $post->errors('settings')); $form_error = TRUE; } } else { // Retrieve Current Settings $settings = ORM::factory('settings', 1); $form = array('sms_no1' => $settings->sms_no1, 'sms_no2' => $settings->sms_no2, 'sms_no3' => $settings->sms_no3); } // Do we have a frontlineSMS Key? If not create and save one on the fly $settings = ORM::factory('settings', 1); $frontlinesms_key = $settings->frontlinesms_key; if (!$frontlinesms_key) { $frontlinesms_key = strtoupper(text::random('alnum', 8)); $settings->frontlinesms_key = $frontlinesms_key; $settings->save(); } $this->template->content->form = $form; $this->template->content->errors = $errors; $this->template->content->form_error = $form_error; $this->template->content->form_saved = $form_saved; $this->template->content->frontlinesms_key = $frontlinesms_key; $this->template->content->frontlinesms_link = url::base() . "frontlinesms/?key=" . $frontlinesms_key . "&s=\${sender_number}&m=\${message_content}"; }
/** * Sends an email confirmation */ private function _send_email_confirmation($user) { $settings = Kohana::config('settings'); // Check if we require users to go through this process if ($settings['require_email_confirmation'] == 0) { return FALSE; } $email = $user->email; $code = text::random('alnum', 20); $user->code = $code; $user->save(); $url = url::site() . "login/verify/?c=" . urlencode($code) . "&e=" . urlencode($email); $to = $email; $from = array($settings['site_email'], $settings['site_name']); $subject = $settings['site_name'] . ' ' . Kohana::lang('ui_main.login_signup_confirmation_subject'); $message = Kohana::lang('ui_main.login_signup_confirmation_message', array($settings['site_name'], $url)); email::send($to, $from, $subject, $message, FALSE); return TRUE; }