Beispiel #1
0
 public function __construct()
 {
     parent::__construct();
     if (!Sentry::check()) {
         $this->message->set('danger', 'You must login to access this module', TRUE, 'message');
         redirect(website_url('auth'));
     }
 }
 /**
  * {@inheritdoc}
  */
 public function register(Application $app)
 {
     // Create a new Database connection
     $database = new Capsule();
     $database->addConnection(array('driver' => 'mysql', 'host' => $app->config('database.host'), 'database' => $app->config('database.database'), 'username' => $app->config('database.user'), 'password' => $app->config('database.password'), 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci'));
     // Makes the new "capsule" the global static instance.
     $database->setAsGlobal();
     // Boots Eloquent to be used by Sentry.
     $database->bootEloquent();
     $app['sentry'] = $app->share(function ($app) {
         $hasher = new \Cartalyst\Sentry\Hashing\NativeHasher();
         $userProvider = new \Cartalyst\Sentry\Users\Eloquent\Provider($hasher);
         $groupProvider = new \Cartalyst\Sentry\Groups\Eloquent\Provider();
         $throttleProvider = new \Cartalyst\Sentry\Throttling\Eloquent\Provider($userProvider);
         $session = new SymfonySentrySession($app['session']);
         $cookie = new \Cartalyst\Sentry\Cookies\NativeCookie(array());
         $sentry = new \Cartalyst\Sentry\Sentry($userProvider, $groupProvider, $throttleProvider, $session, $cookie);
         Sentry::setupDatabaseResolver($app['db']);
         $throttleProvider->disable();
         return $sentry;
     });
 }
Beispiel #3
0
 function getApp()
 {
     if (isset($this->_app)) {
         return $this->_app;
     }
     // Initialize out Silex app and let's do it
     $app = new \Silex\Application();
     if ($this->getConfig('twig.debug')) {
         $app['debug'] = $this->getConfig('twig.debug');
     }
     // Register our session provider
     $app->register(new \Silex\Provider\SessionServiceProvider());
     $app->before(function ($request) use($app) {
         $app['session']->start();
     });
     $app['url'] = $this->getConfig('application.url');
     $app['uploadPath'] = $this->getConfig('upload.path');
     $app['confAirport'] = $this->getConfig('application.airport');
     $app['arrival'] = $this->getConfig('application.arrival');
     $app['departure'] = $this->getConfig('application.departure');
     // Register the Twig provider and lazy-load the global values
     $app->register(new \Silex\Provider\TwigServiceProvider(), array('twig.path' => APP_DIR . $this->getConfig('twig.template_dir')));
     $that = $this;
     $app['twig'] = $app->share($app->extend('twig', function ($twig, $app) use($that) {
         $twig->addGlobal('site', array('url' => $that->getConfig('application.url'), 'title' => $that->getConfig('application.title'), 'email' => $that->getConfig('application.email'), 'eventurl' => $that->getConfig('application.eventurl'), 'enddate' => $that->getConfig('application.enddate')));
         return $twig;
     }));
     // Register our use of the Form Service Provider
     $app->register(new \Silex\Provider\FormServiceProvider());
     $app->register(new \Silex\Provider\ValidatorServiceProvider());
     $app->register(new \Silex\Provider\TranslationServiceProvider(), array('translator.messages' => array()));
     $app['db'] = $this->getDb();
     $app['spot'] = $this->getSpot();
     $app['purifier'] = $this->getPurifier();
     // We're using Sentry, so make it available to app
     $app['sentry'] = $app->share(function () use($app) {
         $hasher = new \Cartalyst\Sentry\Hashing\NativeHasher();
         $userProvider = new \Cartalyst\Sentry\Users\Eloquent\Provider($hasher);
         $groupProvider = new \Cartalyst\Sentry\Groups\Eloquent\Provider();
         $throttleProvider = new \Cartalyst\Sentry\Throttling\Eloquent\Provider($userProvider);
         $session = new \OpenCFP\SymfonySentrySession($app['session']);
         $cookie = new \Cartalyst\Sentry\Cookies\NativeCookie(array());
         $sentry = new \Cartalyst\Sentry\Sentry($userProvider, $groupProvider, $throttleProvider, $session, $cookie);
         \Cartalyst\Sentry\Facades\Native\Sentry::setupDatabaseResolver($app['db']);
         $throttleProvider->disable();
         return $sentry;
     });
     $app['twig'] = $app->share($app->extend('twig', function ($twig, $app) {
         $twig->addGlobal('user', $app['sentry']->getUser());
         return $twig;
     }));
     // Configure our flash messages functionality
     $app->before(function () use($app) {
         $flash = $app['session']->get('flash');
         $app['session']->set('flash', null);
         if (!empty($flash)) {
             $app['twig']->addGlobal('flash', $flash);
         }
     });
     // Add current page global
     $app->before(function (Request $request) use($app) {
         $app['twig']->addGlobal('current_page', $request->getRequestUri());
     });
     // Define error template paths
     if (!$app['debug']) {
         $app->error(function (\Exception $e, $code) use($app) {
             switch ($code) {
                 case 401:
                     $message = $app['twig']->render('error/401.twig');
                     break;
                 case 403:
                     $message = $app['twig']->render('error/403.twig');
                     break;
                 case 404:
                     $message = $app['twig']->render('error/404.twig');
                     break;
                 default:
                     $message = $app['twig']->render('error/500.twig');
             }
             return new Response($message, $code);
         });
     }
     $app = $this->defineRoutes($app);
     // Add the starting date for submissions
     $app['cfpdate'] = $this->getConfig('application.cfpdate');
     return $app;
 }
Beispiel #4
0
    public function add()
    {
        $data = array();
        // add page title
        $this->output->append_title('Add New Client');
        // add breadcrumbs
        $this->breadcrumb->populate(array('Dashboard' => parent::$module . '/dashboard', 'users' => parent::$module . '/clients', 'Add Client'));
        // process form
        if ($this->input->post()) {
            // set validation rules
            $this->form_validation->set_rules('client_first_name', 'First Name', 'trim|required');
            $this->form_validation->set_rules('client_last_name', 'Last Name', 'trim|required');
            $this->form_validation->set_rules('client_address', 'Client Address', 'trim|required');
            $this->form_validation->set_rules('client_url', '', 'trim');
            $this->form_validation->set_rules('email', 'Email', 'trim|edit_unique[users.email]');
            $this->form_validation->set_rules('client_phone_number', 'Phone Number', 'trim|required');
            $this->form_validation->set_rules('client_fb_page_url', '', 'trim');
            $this->form_validation->set_rules('client_twitter_page_url', '', 'trim');
            $this->form_validation->set_rules('client_website_url', '', 'trim');
            $this->form_validation->set_rules('client_timezone', 'Client Timezone', 'trim|required');
            // validate form
            if ($this->form_validation->run() == TRUE) {
                // Create client
                $user = Sentry::createUser(array('first_name' => $this->input->post('client_first_name'), 'last_name' => $this->input->post('client_last_name'), 'address' => $this->input->post('client_address'), 'email' => $this->input->post('email'), 'password' => $this->input->post('password'), 'country_code' => $this->input->post('client_country_code'), 'phone_number' => $this->common->formatPhoneNumber($this->input->post('client_country_code'), $this->input->post('client_phone_number'), true), 'timezone' => $this->input->post('client_timezone'), 'activated' => true));
                $user_id = $user->getId();
                // get user id
                // Find the group using the group id
                $adminGroup = Sentry::findGroupById(CLIENT_GROUP_ID);
                //
                // Assign the group to the user
                $user->addGroup($adminGroup);
                $data = array('client_url' => prep_url($this->input->post('client_url')), 'client_fb_page_url' => prep_url($this->input->post('client_fb_page_url')), 'client_twitter_page_url' => prep_url($this->input->post('client_twitter_page_url')), 'client_website_url' => prep_url($this->input->post('client_website_url')), 'user_id' => $user_id, 'created_on' => CURRENT_DATETIME, 'updated_on' => CURRENT_DATETIME);
                $data = $this->security->xss_clean($data);
                // filter data & remove malicious code
                $this->client_model->insert($data);
                $url = website_url('admin');
                $subject = 'Client Account Creation';
                $template_data = array('email_title' => 'Client Account Creation', 'email_heading' => 'Hello ' . $this->input->post('client_first_name') . ' ' . $this->input->post('client_last_name'), 'email_body' => 'Your account has been created.<br/>
					Your account details are:<br/>
					Email: ' . $this->input->post('email') . '<br/>
					Password: '******'password') . '<br/>
					<br/>Please click on the following link to login:<br/> <a href="' . $url . '">' . $url . '</a><br/>
					If clicking the link does not work, please copy and paste the URL into your browser instead.<br/>
					');
                $body = $this->parser->parse('emails/user_registration', $template_data, TRUE);
                if ($this->common->sendEmail($email, $subject, $body)) {
                    $this->message->set('success', 'Client added successfully.', TRUE, 'message');
                } else {
                    $this->message->set('warning', 'Unable to send email, please try again later.', TRUE, 'message');
                }
                redirect(website_url('users'));
            } else {
                $this->message->set('danger', $this->message->validation_errors());
            }
        }
        // create form fields
        $data['client_first_name'] = array('name' => 'client_first_name', 'autofocus' => 'autofocus', 'id' => 'client_first_name', 'placeholder' => 'First Name', 'class' => 'form-control', 'maxlength' => 50, 'value' => $this->form_validation->set_value('client_first_name'));
        $data['client_last_name'] = array('name' => 'client_last_name', 'id' => 'client_last_name', 'placeholder' => 'Last Name', 'class' => 'form-control', 'maxlength' => 50, 'value' => $this->form_validation->set_value('client_last_name'));
        $data['client_url'] = array('name' => 'client_url', 'id' => 'client_url', 'placeholder' => 'Client URL', 'class' => 'form-control', 'maxlength' => 100, 'value' => $this->form_validation->set_value('client_url'));
        $data['client_address'] = array('name' => 'client_address', 'id' => 'client_address', 'placeholder' => 'Client Address', 'class' => 'form-control', 'maxlength' => 300, 'rows' => 5, 'value' => $this->form_validation->set_value('client_address'));
        $data['client_phone_number'] = array('name' => 'client_phone_number', 'id' => 'client_phone_number', 'placeholder' => 'Phone Number', 'class' => 'form-control international-number', 'maxlength' => 15, 'type' => 'tel', 'value' => $this->form_validation->set_value('client_phone_number'));
        $data['client_fb_page_url'] = array('name' => 'client_fb_page_url', 'id' => 'client_fb_page_url', 'placeholder' => 'Facebook Page URL', 'class' => 'form-control', 'maxlength' => 100, 'value' => $this->form_validation->set_value('client_fb_page_url'));
        $data['client_twitter_page_url'] = array('name' => 'client_twitter_page_url', 'id' => 'client_twitter_page_url', 'placeholder' => 'Twitter Page URL', 'class' => 'form-control', 'maxlength' => 100, 'value' => $this->form_validation->set_value('client_twitter_page_url'));
        $data['client_website_url'] = array('name' => 'client_website_url', 'id' => 'client_website_url', 'placeholder' => 'Website URL', 'class' => 'form-control', 'maxlength' => 100, 'value' => $this->form_validation->set_value('client_website_url'));
        $timezones = $this->timezone->get_timezone_list();
        $list = array('' => 'Select Timezone');
        foreach ($timezones as $key => $value) {
            $list[$value] = $key;
        }
        //echo '<pre>'; print_r($list);die;
        $data['client_timezone'] = array('name' => 'client_timezone', 'additional' => array('id' => 'client_timezone', 'class' => 'form-control'), 'value' => $list, 'selected' => $this->form_validation->set_value('client_timezone'));
        $data['client_country_code'] = array('name' => 'client_country_code', 'id' => 'client_country_code', 'type' => 'hidden', 'value' => $this->form_validation->set_value('client_country_code'));
        $data['email'] = array('name' => 'email', 'id' => 'email', 'placeholder' => 'Email', 'class' => 'form-control', 'type' => 'text', 'value' => $this->form_validation->set_value('email'));
        $data['password'] = array('name' => 'password', 'id' => 'password', 'placeholder' => 'Password', 'class' => 'form-control', 'type' => 'password', 'value' => $this->form_validation->set_value('password'));
        // load view
        $this->load->view(parent::$module . '/edit', $data);
    }
Beispiel #5
0
 /**
  * seed the database with initial value
  */
 public function seed()
 {
     try {
         Sentry::createUser(array('email' => '*****@*****.**', 'password' => 'password', 'first_name' => 'Website', 'last_name' => 'Administrator', 'activated' => 1, 'permissions' => array('admin' => 1)));
     } catch (Exception $e) {
         echo $e->getMessage() . "\n";
     }
 }
Beispiel #6
0
 public function logout()
 {
     Sentry::logout();
     redirect(website_url('auth'));
 }