public function test_data_storage()
 {
     Status_msg::success('Success message.');
     Status_msg::error('Error message.');
     Status_msg::warning('Warning message.', TRUE);
     // Execution is fast enough that the time won't vary.
     $time = time();
     $msg = Status_msg::get();
     $expected = array(array('level' => 'success', 'msg' => 'Success message.', 'sticky' => FALSE, 'time' => $time), array('level' => 'error', 'msg' => 'Error message.', 'sticky' => TRUE, 'time' => $time), array('level' => 'warning', 'msg' => 'Warning message.', 'sticky' => TRUE, 'time' => $time));
     $this->assertEquals($msg, $expected);
     // After getting the first get the messages should be cleared.
     $msg = Status_msg::get();
     $expected = NULL;
     $this->assertEquals($msg, $expected);
 }
<?php

/**
 * Toast messages file.
 * This file is being included in footer_scripts.php
 * 
 * Shows toasts for the various 'levels':
 * - notice
 * - success
 * - warning
 * - error
 * 
 * Success toasts are the only ones not sticky due to its nature.
 */
$messages = Status_msg::get();
if ($messages) {
    ?>
  <script>
  <?php 
    foreach ($messages as $index => $msg) {
        ?>
  $().toastmessage('showToast', {
    sticky   : <?php 
        echo $msg['sticky'] ? 'true' : 'false';
        ?>
,
    text     : "<?php 
        echo $msg['msg'];
        ?>
",
    type     : '<?php 
Example #3
0
 /**
  * Form to reset password. Only accessible through url sent to email.
  * 
  * Route:
  * /user/reset_password
  */
 public function user_reset_password($hash)
 {
     $this->load->model('recover_password_model');
     $user_email = $this->recover_password_model->validate($hash);
     if ($user_email) {
         $this->form_validation->set_rules('user_new_password', 'New Password', 'trim|required');
         $this->form_validation->set_rules('user_new_password_confirm', 'New Password Confirm', 'trim|required|callback__cb_check_confirm_password');
         $this->form_validation->set_error_delimiters('<small class="error">', '</small>');
         if ($this->form_validation->run() == FALSE) {
             $this->load->view('base/html_start');
             $this->load->view('users/user_reset_password');
             $this->load->view('base/html_end');
         } else {
             $user = $this->user_model->get_by_email($user_email);
             if ($user) {
                 $user->set_password(hash_password($this->input->post('user_new_password')));
                 if ($this->user_model->save($user)) {
                     $this->recover_password_model->invalidate($hash);
                     Status_msg::success('Password successfully changed. You can now login.', TRUE);
                     redirect('login');
                 } else {
                     Status_msg::error("Error saving your new password. Try again later.");
                 }
             } else {
                 // This could happen if the email stored with the hash doesn't return a user.
                 // Maybe the user was deleted before the link was clicked?
                 // During normal usage this is improbable.
                 show_error("An error occurred while getting user from the hash. Try again later.");
             }
         }
     } else {
         // Hash expired.
         show_error('Sorry, this link is no longer valid.', 404);
     }
 }
Example #4
0
 /**
  * Change the status of the surveys
  * @param $sid
  *   Survey sid
  * @param $status
  *  The survey new status.
  *
  * Route - /survey/:sid/change_status/:status
  */
 public function survey_change_status($sid, $status)
 {
     verify_csrf_get();
     $survey = $this->survey_model->get($sid);
     if (!$survey) {
         show_404();
     } else {
         if (!has_permission('change status any survey')) {
             show_403();
         }
     }
     if (!$survey->is_allowed_status_change($status)) {
         show_error('Invalid status.');
     }
     $survey->status = (int) $status;
     // Save.
     if ($this->survey_model->save($survey)) {
         Status_msg::success('Status successfully changed.');
     } else {
         Status_msg::error('An error occurred when saving the survey. Please try again.');
     }
     redirect($survey->get_url_view());
 }