Beispiel #1
0
 /**
  * Construct the (base) controller. This happens when a real controller is constructed, like in
  * the constructor of IndexController when it says: parent::__construct();
  */
 function __construct(LoggerInterface $logger = null)
 {
     // always initialize a session
     Session::init();
     // user is not logged in but has remember-me-cookie ? then try to login with cookie ("remember me" feature)
     if (!Session::userIsLoggedIn() and Request::cookie('remember_me')) {
         header('location: ' . Config::get('URL') . 'login/loginWithCookie');
     }
     // create a view object to be able to use it inside a controller, like $this->View->render();
     $this->View = new View();
     //initialize the logger object
     $this->logger = $logger;
 }
Beispiel #2
0
 public function __construct($title, $data, $headers, $sizes, $max_lengths)
 {
     parent::__construct();
     $this->header_text = $title;
     $this->footer_text = "Generated by [" . Session::get('user_name') . "] on [" . date("l jS \\of F Y h:i:s A") . "] - " . Config::get('VERSION');
     $this->data = $data;
     $this->col_headers = $headers;
     $this->col_sizes = $sizes;
     $this->col_max_lengs = $max_lengths;
     $this->SetTitle($title);
     $this->SetAuthor(Session::get('user_name'));
     $this->AliasNbPages();
     $this->SetFont('Arial', '', 8);
     $this->AddPage();
     $this->renderTable();
 }
Beispiel #3
0
<?php

use Ssg\Core\Session;
use Ssg\Core\Text;
// get the feedback (they are arrays, to make multiple positive/negative messages possible)
$feedback_positive = Session::get('feedback_positive');
$feedback_negative = Session::get('feedback_negative');
// echo out positive messages
if (isset($feedback_positive)) {
    foreach ($feedback_positive as $feedback) {
        echo '<div class="alert alert-success alert-dismissible" role="alert"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>' . $feedback . '</div>';
    }
}
// echo out negative messages
if (isset($feedback_negative)) {
    foreach ($feedback_negative as $feedback) {
        echo '<div class="alert alert-danger alert-dismissible" role="alert"><button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>' . $feedback . '</div>';
    }
}
 /**
  * Validate the password submission
  *
  * @param $user_name
  * @param $user_password_reset_hash
  * @param $user_password_new
  * @param $user_password_repeat
  *
  * @return bool
  */
 public static function validateNewPassword($user_name, $user_password_reset_hash, $user_password_new, $user_password_repeat)
 {
     if (empty($user_name)) {
         Session::add('feedback_negative', Text::get('FEEDBACK_USERNAME_FIELD_EMPTY'));
         return false;
     } else {
         if (empty($user_password_new) || empty($user_password_repeat)) {
             Session::add('feedback_negative', Text::get('FEEDBACK_PASSWORD_FIELD_EMPTY'));
             return false;
         } else {
             if ($user_password_new !== $user_password_repeat) {
                 Session::add('feedback_negative', Text::get('FEEDBACK_PASSWORD_REPEAT_WRONG'));
                 return false;
             } else {
                 if (strlen($user_password_new) < 6) {
                     Session::add('feedback_negative', Text::get('FEEDBACK_PASSWORD_TOO_SHORT'));
                     return false;
                 }
             }
         }
     }
     return true;
 }
Beispiel #5
0
 /**
  * Handles what happens when user moves to URL/service/all. This returns all servives in the system. 
  */
 public function delete($service_id)
 {
     //get request data
     $id = '';
     $service_name = '';
     $service_type = '';
     $short_code = '';
     $criteria = '';
     $service_endpoint = '';
     $delivery_notification_endpoint = '';
     $interface_name = '';
     $data = array('id' => $id, 'service_id' => $service_id, 'service_name' => $service_name, 'service_type' => $service_type, 'short_code' => $short_code, 'criteria' => $criteria, 'service_endpoint' => $service_endpoint, 'delivery_notification_endpoint' => $delivery_notification_endpoint, 'interface_name' => $interface_name);
     //log the event
     $this->logger->debug('{class_mame}|{method_name}|{service_id}|request-data', array('class_mame' => __CLASS__, 'method_name' => __FUNCTION__, 'request-data' => json_encode($data)));
     if (null !== Request::post('action', true)) {
         //form submitted, processing to happen below
         $service_model = new ServiceModel($this->logger);
         $result = $service_model->deleteService($service_id);
         $data['result'] = $result;
         //success
         if ($result['result'] == 0) {
             Session::add('feedback_positive', 'Service deleted successfully');
         } else {
             Session::add('feedback_negative', 'Service deletion failed. Error: ' . $result['result'] . ' - ' . $result['resultDesc']);
         }
         //log the event
         $this->logger->debug('{class_mame}|{method_name}|{service_id}|edit-service-result|result:{result}|result_desc:{result_desc}', array('class_mame' => __CLASS__, 'method_name' => __FUNCTION__, 'result' => $result['result'], 'result_desc' => $result['resultDesc'], 'result_desc' => json_encode($result)));
     } else {
         //load servive data from windows
         $service_model = new ServiceModel($this->logger);
         $result = $service_model->getService($service_id);
         $data['result'] = $result;
         //successful loading of service
         if ($result['result'] == 0) {
             $data = json_decode(json_encode($result['service']), true);
         } else {
             Session::add('feedback_negative', 'Service ' . $service_id . ' loading failed. Error: ' . $result['result'] . ' - ' . $result['resultDesc']);
         }
         //log the event
         $this->logger->debug('{class_mame}|{method_name}|{service_id}|result|{result}|{result_desc}', array('class_mame' => __CLASS__, 'method_name' => __FUNCTION__, 'result' => $result['result'], 'result_desc' => $result['resultDesc']));
     }
     $this->View->render('servicemanager/delete', $data);
 }
Beispiel #6
0
 /**
  * Returns the current state of the user's login
  *
  * @return bool user's login status
  */
 public static function isUserLoggedIn()
 {
     return Session::userIsLoggedIn();
 }
Beispiel #7
0
                            <li><a href="<?php 
    echo Config::get('URL');
    ?>
reports/subscriptions/">Report</a></li>
                        </ul>
                    </li>
                  </ul>
                  <ul class="nav navbar-nav navbar-right">
                    <li class="dropdown">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false"><span class="glyphicon glyphicon-user" aria-hidden="true"></span> My Account</a>
                        <ul class="dropdown-menu" role="menu">
                            <li class="active"><a href="<?php 
    echo Config::get('URL');
    ?>
login/logout/">Logout <strong><?php 
    echo Session::get('user_name');
    ?>
</strong></a></li>
                            <li><a href="<?php 
    echo Config::get('URL');
    ?>
login/changePassword/">Change Password</a></li>
                        </ul>
                    </li>
                  </ul>
                <?php 
}
?>
        
          
          
Beispiel #8
0
 /**
  * Set the new password
  * Please note that this happens while the user is not logged in. The user identifies via the data provided by the
  * password reset link from the email, automatically filled into the <form> fields. See verifyPasswordReset()
  * for more. Then (regardless of result) route user to index page (user will get success/error via feedback message)
  * POST request !
  * TODO this is an _action
  */
 public function setNewPassword()
 {
     if (Session::userIsLoggedIn()) {
         PasswordResetModel::setNewPassword(Request::post('user_name'), Request::post('user_password_reset_hash'), Request::post('user_password_new'), Request::post('user_password_repeat'));
         $user_name = Session::get('user_name');
         $this->View->render('login/set_new_password', array('user_name' => $user_name));
     } else {
         Redirect::to('login/index');
     }
 }
Beispiel #9
0
 /**
  * Edit the user's email
  *
  * @param $new_user_email
  *
  * @return bool success status
  */
 public static function editUserEmail($new_user_email)
 {
     // email provided ?
     if (empty($new_user_email)) {
         Session::add('feedback_negative', Text::get('FEEDBACK_EMAIL_FIELD_EMPTY'));
         return false;
     }
     // check if new email is same like the old one
     if ($new_user_email == Session::get('user_email')) {
         Session::add('feedback_negative', Text::get('FEEDBACK_EMAIL_SAME_AS_OLD_ONE'));
         return false;
     }
     // user's email must be in valid email format, also checks the length
     // @see http://stackoverflow.com/questions/21631366/php-filter-validate-email-max-length
     // @see http://stackoverflow.com/questions/386294/what-is-the-maximum-length-of-a-valid-email-address
     if (!filter_var($new_user_email, FILTER_VALIDATE_EMAIL)) {
         Session::add('feedback_negative', Text::get('FEEDBACK_EMAIL_DOES_NOT_FIT_PATTERN'));
         return false;
     }
     // strip tags, just to be sure
     $new_user_email = substr(strip_tags($new_user_email), 0, 254);
     // check if user's email already exists
     if (UserModel::doesEmailAlreadyExist($new_user_email)) {
         Session::add('feedback_negative', Text::get('FEEDBACK_USER_EMAIL_ALREADY_TAKEN'));
         return false;
     }
     // write to database, if successful ...
     // ... then write new email to session, Gravatar too (as this relies to the user's email address)
     if (UserModel::saveNewEmailAddress(Session::get('user_id'), $new_user_email)) {
         Session::set('user_email', $new_user_email);
         Session::set('user_gravatar_image_url', AvatarModel::getGravatarLinkByEmail($new_user_email));
         Session::add('feedback_positive', Text::get('FEEDBACK_EMAIL_CHANGE_SUCCESSFUL'));
         return true;
     }
     Session::add('feedback_negative', Text::get('FEEDBACK_UNKNOWN_ERROR'));
     return false;
 }
Beispiel #10
0
 public function subscriptions_pdf()
 {
     /*
     	Initialize the request data
     */
     //get request data
     $subscriber_id = Request::get('subscriber_id');
     $service_id = Request::get('service_id');
     $product_id = Request::get('product_id');
     $update_type = Request::get('update_type');
     $start_date = Request::get('start_date');
     $end_date = Request::get('end_date');
     //set default start date - 1 month ago
     if (!isset($start_date) || $start_date == '') {
         $date = date_create(date('Y-m-d'));
         date_sub($date, date_interval_create_from_date_string('1 months'));
         $start_date = date_format($date, 'Y-m-d');
     }
     //set default end date  - current day
     if (!isset($end_date) || $end_date == '') {
         $end_date = date('Y-m-d');
     }
     //request data to be used in calling the model
     $data = array('subscriber_id' => $subscriber_id, 'service_id' => $service_id, 'product_id' => $product_id, 'update_type' => $update_type, 'start_date' => $start_date, 'end_date' => $end_date);
     //log the event
     $this->logger->debug('{class_mame}|{method_name}|request|request-data:{data}', array('class_mame' => __CLASS__, 'method_name' => __FUNCTION__, 'data' => json_encode($data)));
     //call the model
     $model = new MessageModel($this->logger);
     $result = $model->getSubscriptionMessages($start_date . ' 00:00:00', $end_date . ' 23:59:59', $subscriber_id, $service_id, $product_id, $update_type, 0, Config::get('MAX_RECORDS_PDF'));
     //add result
     $data['result'] = $result;
     //print_r($result);
     //request data to be used in calling the model
     $data = array('subscriber_id' => $subscriber_id, 'service_id' => $service_id, 'product_id' => $product_id, 'update_type' => $update_type, 'start_date' => $start_date, 'end_date' => $end_date);
     $title = "Subscription Requests Extract - Subscriber: {$subscriber_id}, Service ID: {$service_id}, Product ID: {$product_id}, Update Type: {$update_type}, Start Date: {$start_date}, End Date: {$end_date}";
     $headers = array('#', 'Subscriber', 'Service ID', 'Product ID', 'Update Type', 'Effective Time', 'Expiry Time', 'Processing Time');
     $sizes = array(15, 43, 40, 40, 35, 35, 35, 35);
     $max_sizes = array(10, 30, 28, 28, 30, 25, 25, 25);
     $data = array();
     $filename = __FUNCTION__ . '_' . Session::get('user_name') . '_' . date('YmdHis') . '.pdf';
     $i = 0;
     foreach ($result['messages'] as $message) {
         $data[$i] = array($message->id, $message->subscriber_id, $message->service_id, $message->product_id, $message->update_desc, $message->effective_time, $message->expiry_time, $message->created_on);
         $i++;
     }
     $pdf = new PDF($title, $data, $headers, $sizes, $max_sizes);
     $pdf->Output($filename, 'I');
     //log the event
     $this->logger->info('{class_mame}|{method_name}|result|{result}|result_desc:{result_desc}', array('class_mame' => __CLASS__, 'method_name' => __FUNCTION__, 'result' => $result['result'], 'result_desc' => $result['resultDesc']));
 }