Exemplo n.º 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;
 }
 /**
  * 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;
 }
 /**
  * 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;
 }
Exemplo n.º 4
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;
 }
Exemplo n.º 5
0
 /**
  * @param AssetService          $asset
  * @param MeterService          $meter
  * @param ReadingService        $meterReading
  * @param ConfigService         $config
  * @param ReadingValidator      $meterReadingValidator
  */
 public function __construct(AssetService $asset, MeterService $meter, ReadingService $meterReading, ConfigService $config, ReadingValidator $meterReadingValidator)
 {
     $this->asset = $asset;
     $this->meter = $meter;
     $this->meterReading = $meterReading;
     $this->meterReadingValidator = $meterReadingValidator;
     $this->config = $config->setPrefix('maintenance');
 }
Exemplo n.º 6
0
 /**
  * Constructor.
  *
  * @param WorkOrder                  $workOrder
  * @param SentryService              $sentry
  * @param PriorityService            $priority
  * @param StatusService              $status
  * @param ConfigService              $config
  */
 public function __construct(WorkOrder $workOrder, SentryService $sentry, PriorityService $priority, StatusService $status, ConfigService $config)
 {
     $this->model = $workOrder;
     $this->sentry = $sentry;
     $this->priority = $priority;
     $this->status = $status;
     $this->config = $config->setPrefix('maintenance');
 }
Exemplo n.º 7
0
 /**
  * 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;
 }
Exemplo n.º 8
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;
 }
Exemplo n.º 9
0
 /**
  * Constructor.
  *
  * @param PriorityRepository $priority
  * @param ConfigService      $config
  */
 public function __construct(PriorityRepository $priority, ConfigService $config)
 {
     $this->priority = $priority;
     $this->config = $config->setPrefix('maintenance');
 }
Exemplo n.º 10
0
 /**
  * Constructor.
  *
  * @param LdapService   $ldap
  * @param SentryService $sentry
  * @param ConfigService $config
  */
 public function __construct(LdapService $ldap, SentryService $sentry, ConfigService $config)
 {
     $this->ldap = $ldap;
     $this->sentry = $sentry;
     $this->config = $config->setPrefix('maintenance');
 }
Exemplo n.º 11
0
 /**
  * @param ConfigService $config
  */
 public function __construct(ConfigService $config)
 {
     $this->config = $config->setPrefix('maintenance');
 }
Exemplo n.º 12
0
 /**
  * Constructor.
  *
  * @param StatusRepository $status
  * @param ConfigService $config
  */
 public function __construct(StatusRepository $status, ConfigService $config)
 {
     $this->status = $status;
     $this->config = $config->setPrefix('maintenance');
 }
Exemplo n.º 13
0
 /**
  * Constructor.
  *
  * @param MetricRepository $metric
  * @param ConfigService    $config
  */
 public function __construct(MetricRepository $metric, ConfigService $config)
 {
     $this->metric = $metric;
     $this->config = $config->setPrefix('maintenance');
 }