Example #1
0
 /**
  * Create or Update a User for authentication for use with ldap.
  *
  * @param array $credentials
  *
  * @return \Cartalyst\Sentry\Users\Eloquent\User
  */
 public function createOrUpdateLdapUser(array $credentials)
 {
     $loginAttribute = $this->config->setPrefix('cartalyst.sentry')->get('users.login_attribute');
     $username = $credentials[$loginAttribute];
     $password = $credentials['password'];
     // If a user is found, update their password to match active-directory
     $user = $this->model->where('username', $username)->first();
     if ($user) {
         $this->sentry->updatePasswordById($user->id, $password);
     } else {
         // If a user is not found in the database, create their web account
         $ldapUser = $this->ldap->user($username);
         $fullName = explode(',', $ldapUser->name);
         $lastName = array_key_exists(0, $fullName) ? $fullName[0] : null;
         $firstName = array_key_exists(1, $fullName) ? $fullName[1] : null;
         $data = ['email' => $ldapUser->email ? $ldapUser->email : $username, 'username' => $username, 'password' => $password, 'last_name' => (string) $lastName, 'first_name' => (string) $firstName, 'activated' => 1];
         // Default all group
         $roles = ['all'];
         if (in_array($ldapUser->group, config('maintenance.groups.ldap.administrators'))) {
             $roles[] = 'administrators';
         } else {
             if (in_array($ldapUser->group, config('maintenance.groups.ldap.workers'))) {
                 $roles[] = 'workers';
             } else {
                 $roles[] = 'client';
             }
         }
         $user = $this->sentry->createUser($data, $roles);
     }
     return $user;
 }
 /**
  * Applies site wide variables to main layout.
  *
  * @param $view
  */
 public function compose(View $view)
 {
     $siteTitle = $this->config->get('site.title.main');
     $currentUser = $this->sentry->getCurrentUser();
     $view->with('siteTitle', $siteTitle);
     $view->with('currentUser', $currentUser);
 }
 /**
  * Creates a new inventory stock record.
  *
  * @return bool|static
  */
 public function create()
 {
     $this->dbStartTransaction();
     try {
         $insert = ['user_id' => $this->sentry->getCurrentUserId(), 'stock_id' => $this->getInput('stock_id'), 'before' => $this->getInput('before'), 'after' => $this->getInput('after'), 'cost' => $this->getInput('cost'), 'reason' => $this->getInput('reason', 'Stock Adjustment', true)];
         /*
          * Only create a record if the before and after quantity differ
          * if enabled in config
          */
         if ($this->config->setPrefix('inventory')->get('allow_duplicate_movements')) {
             if ($insert['before'] != $insert['after']) {
                 $record = $this->model->create($insert);
                 $this->dbCommitTransaction();
                 return $record;
             } else {
                 /*
                  * Return true if before and after quantity are the same
                  * and prevent duplicate movements is enabled
                  */
                 return true;
             }
         } else {
             /*
              * Prevent duplicate movements is disabled, create the record
              */
             $record = $this->model->create($insert);
             $this->dbCommitTransaction();
             return $record;
         }
     } catch (\Exception $e) {
         $this->dbRollbackTransaction();
     }
     return false;
 }
 /**
  * Sends an email to the user with their password reset link.
  */
 public function postRequest()
 {
     if ($this->requestResetValidator->passes()) {
         $user = $this->sentry->findUserByLogin($this->input('email'));
         if ($user) {
             $sent = $this->mail->send('maintenance::emails.reset-password', ['user' => $user, 'code' => $user->getResetPasswordCode()], function ($message) use($user) {
                 $adminEmail = $this->config->get('mail.from.address');
                 $adminName = $this->config->get('mail.from.name');
                 $message->to($user->email, $user->first_name)->from($adminEmail, $adminName)->subject('Reset Your Password');
             });
             if ($sent) {
                 $this->message = "We've sent you an email to reset your password.";
                 $this->messageType = 'success';
                 $this->redirect = route('maintenance.login.forgot-password');
             } else {
                 $this->message = 'There was an issue trying to send your password reset request. Please try again later.';
                 $this->messageType = 'danger';
                 $this->redirect = route('maintenance.login.forgot-password');
             }
         } else {
             $this->message = 'The email/username you entered does not exist, please try again';
             $this->messageType = 'danger';
             $this->redirect = route('maintenance.login.forgot-password');
         }
     } else {
         $this->errors = $this->requestResetValidator->getErrors();
         $this->redirect = route('maintenance.login.forgot-password');
     }
     return $this->response();
 }
 /**
  * Creates a user work request.
  *
  * @param WorkRequest $request
  *
  * @return bool|\Stevebauman\Maintenance\Models\WorkRequest
  */
 public function create(WorkRequest $request)
 {
     $attributes = ['subject' => $request->input('subject'), 'description' => $request->clean($request->input('description')), 'best_time' => $request->input('best_time')];
     $workRequest = $this->model()->create($attributes);
     if ($workRequest) {
         $autoGenerate = $this->config->setPrefix('maintenance')->get('rules.work-orders.auto_generate_from_request', true);
         if ($autoGenerate) {
             $this->workOrder->createFromWorkRequest($workRequest);
         }
         return $workRequest;
     }
     return false;
 }
Example #6
0
 /**
  * Processes updating the site configuration.
  *
  * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse
  */
 public function store()
 {
     $this->redirect = routeBack('maintenance.admin.settings.site.index');
     if ($this->siteValidator->passes()) {
         if ($this->config->setInput($this->inputAll())->updateSite()) {
             $this->message = 'Successfully updated site configuration';
             $this->messageType = 'success';
         } else {
             $this->message = 'There was an issue updating the site configuration. Please try again.';
             $this->messageType = 'danger';
         }
     } else {
         $this->errors = $this->siteValidator->getErrors();
     }
     return $this->response();
 }
 /**
  * Creates a work order from the specified work request.
  *
  * @param WorkRequest $workRequest
  *
  * @return WorkOrder|bool
  */
 public function createFromWorkRequest(WorkRequest $workRequest)
 {
     $this->dbStartTransaction();
     /*
      * We'll make sure the work request doesn't already have a
      * work order attached to it before we try and create it
      */
     if (!$workRequest->workOrder) {
         try {
             // Retrieve the default submission status for work orders
             $statusData = $this->config->get('rules.work-requests.submission_status');
             // Create or find the status if it doesn't exist
             $status = $this->status->setInput($statusData)->firstOrCreate();
             // Retrieve the default submission priority for work orders
             $priorityData = $this->config->get('rules.work-requests.submission_priority');
             // Create or find the priority if it doesn't exist
             $priority = $this->priority->setInput($priorityData)->firstOrCreate();
             // Set the work order insert data
             $insert = ['status_id' => $status->id, 'priority_id' => $priority->id, 'request_id' => $workRequest->id, 'user_id' => $workRequest->user_id, 'subject' => $workRequest->subject, 'description' => $workRequest->description];
             // Create the work order
             $workOrder = $this->model->create($insert);
             if ($workOrder) {
                 // Commit the transaction on success
                 $this->dbCommitTransaction();
                 return $workOrder;
             }
         } catch (\Exception $e) {
             $this->dbRollbackTransaction();
         }
     }
     return false;
 }
Example #8
0
 /**
  * Creates a new work request.
  *
  * @param Request $request
  *
  * @return bool|WorkRequest
  */
 public function create(Request $request)
 {
     $workRequest = $this->model();
     $workRequest->user_id = $this->sentry->getCurrentUserId();
     $workRequest->subject = $request->input('subject');
     $workRequest->best_time = $request->input('best_time');
     $workRequest->description = $request->clean($request->input('description'));
     if ($workRequest->save()) {
         $autoGenerate = $this->config->setPrefix('maintenance')->get('rules.work-orders.auto_generate_from_request', true);
         if ($autoGenerate) {
             $this->workOrder->createFromWorkRequest($workRequest);
         }
         return $workRequest;
     }
     return false;
 }
 /**
  * Creates a work request.
  *
  * @return bool|WorkRequest
  */
 public function create()
 {
     $this->dbStartTransaction();
     try {
         $workRequest = new $this->model();
         $workRequest->user_id = $this->sentry->getCurrentUserId();
         $workRequest->subject = $this->getInput('subject', null, true);
         $workRequest->best_time = $this->getInput('best_time', null, true);
         $workRequest->description = $this->getInput('description', null, true);
         if ($workRequest->save()) {
             $autoGenerate = $this->config->setPrefix('maintenance')->get('rules.work-orders.auto_generate_from_request', true);
             if ($autoGenerate) {
                 $this->workOrder->createFromWorkRequest($workRequest);
             }
             $this->dbCommitTransaction();
             return $workRequest;
         }
     } catch (\Exception $e) {
         $this->dbRollbackTransaction();
     }
     return false;
 }
 public function store($asset_id, $meter_id)
 {
     if ($this->meterReadingValidator->passes()) {
         $asset = $this->asset->find($asset_id);
         $meter = $this->meter->find($meter_id);
         $data = $this->inputAll();
         $data['meter_id'] = $meter->id;
         /*
          * Check if duplicate reading entries are enabled
          */
         if ($this->config->get('rules.meters.prevent_duplicate_entries')) {
             /*
              * If the last reading is the same as the reading being inputted
              */
             if ($this->input('reading') === $meter->last_reading) {
                 /*
                  * Return warning message
                  */
                 $this->message = 'Please enter a reading different from the last reading';
                 $this->messageType = 'warning';
                 $this->redirect = route('maintenance.assets.meters.show', [$asset->id, $meter->id]);
                 return $this->response();
             }
         }
         if ($this->meterReading->setInput($data)->create()) {
             $this->message = 'Successfully updated reading';
             $this->messageType = 'success';
             $this->redirect = route('maintenance.assets.show', [$asset->id]);
         } else {
             $this->message = 'There was an error trying to update this meter. Please try again';
             $this->messageType = 'danger';
             $this->redirect = route('maintenance.assets.show', [$asset->id]);
         }
     } else {
         $this->errors = $this->meterReadingValidator->getErrors();
     }
     return $this->response();
 }
Example #11
0
 /**
  * Creates or updates a user using LDAP and Sentry.
  *
  * @param array $credentials
  *
  * @return mixed
  */
 public function createOrUpdateLdapUser(array $credentials)
 {
     $loginAttribute = $this->config->setPrefix('cartalyst.sentry')->get('users.login_attribute');
     $username = $credentials[$loginAttribute];
     $password = $credentials['password'];
     // If a user is found, update their password to match active-directory
     $user = $this->model()->where('username', $username)->first();
     if ($user) {
         $this->sentry->updatePasswordById($user->id, $password);
     } else {
         // If a user is not found, create their web account
         $ldapUser = $this->ldap->user($username);
         $fullName = explode(',', $ldapUser->name);
         $lastName = array_key_exists(0, $fullName) ? $fullName[0] : null;
         $firstName = array_key_exists(1, $fullName) ? $fullName[1] : null;
         $data = ['email' => $ldapUser->email, 'password' => $password, 'username' => $username, 'last_name' => (string) $lastName, 'first_name' => (string) $firstName, 'activated' => 1];
         $user = $this->sentry->createUser($data, ['all_users', 'customers', 'workers']);
     }
     return $user;
 }
Example #12
0
 /**
  * Retrieves the seed data from the maintenance configuration.
  *
  * @return mixed
  */
 private function getSeedData()
 {
     return $this->config->get('seed.priorities');
 }
Example #13
0
 /**
  * Retrieves the seed data from the maintenance configuration.
  *
  * @return mixed
  */
 private function getSeedData()
 {
     return $this->config->get('seed.metrics');
 }
Example #14
0
 /**
  * Returns config option of whether or not sync filters are enabled.
  *
  * @return bool
  */
 private function syncFiltersEnabled()
 {
     return $this->config->get('site.ldap.user_sync.filters.enabled');
 }
 /**
  * @param $view
  */
 public function compose(View $view)
 {
     $siteTitle = $this->config->get('site.title.public', 'Maintenance');
     $view->with('siteTitle', $siteTitle);
 }
Example #16
0
 /**
  * Retrieves the seed data from the maintenance configuration.
  *
  * @return mixed
  */
 private function getSeedData()
 {
     return $this->config->get('seed.statuses');
 }
 /**
  * @param $view
  *
  * @return mixed
  */
 public function compose(View $view)
 {
     /*
      * Stores all the routes for selection, defaults are stored in config
      */
     $allRoutes = $this->config->get('permissions.default');
     /*
      * Get all the routes in the application
      */
     $routes = Route::getRoutes();
     foreach ($routes as $route) {
         $routeName = $route->getName();
         /*
          * Make sure the route has a name
          */
         if ($routeName) {
             /*
              * Get the route filters
              */
             $filters = $route->beforeFilters();
             /*
              * Make sure only routes guarded by the permission filter are shown
              * in the route selection box
              */
             if (array_key_exists('maintenance.permission', $filters)) {
                 /*
                  * Explode the route into segments
                  */
                 $segments = explode('.', $routeName);
                 if (count($segments) >= 1) {
                     /*
                      * Pop the last segment off the route name
                      * so we can append a sentry wildcard to it ('*')
                      */
                     array_pop($segments);
                     /*
                      * Set the array pointer to the last element
                      */
                     end($segments);
                     /*
                      * Add the last element with the wildcard
                      */
                     $segments[] = '*';
                     /*
                      * Implode the array back into dot notation
                      */
                     $routeStar = implode('.', $segments);
                     /*
                      * Insert the route into the allRoutes array
                      */
                     $allRoutes[$segments[0]][$routeStar] = $routeStar;
                 }
                 /*
                  * We'll use the first segment entry to group the routes together
                  * for easier navigation
                  */
                 $allRoutes[$segments[0]][$routeName] = $routeName;
             }
         }
     }
     /*
      * Return the view with the routes for selection
      */
     return $view->with('allRoutes', $allRoutes);
 }
Example #18
0
 /**
  * Returns the seed data to be inserted into
  * the database.
  *
  * @return array
  */
 public function getSeedData()
 {
     return $this->config->get('permissions', []);
 }