Example #1
6
 public static function upload($filepath)
 {
     \DB::beginTransaction();
     try {
         $reader = ReaderFactory::create(Type::XLSX);
         // for XLSX files
         $reader->open($filepath);
         $cnt = 0;
         Store::where('active', 1)->update(['active' => 0]);
         foreach ($reader->getSheetIterator() as $sheet) {
             foreach ($sheet->getRowIterator() as $row) {
                 if ($cnt > 0) {
                     // dd($row);
                     $area = Area::firstOrCreate(['area' => strtoupper($row[0])]);
                     $enrollment = Enrollment::firstOrCreate(['enrollment' => strtoupper($row[1])]);
                     $distributor = Distributor::firstOrCreate(['distributor_code' => strtoupper($row[2]), 'distributor' => strtoupper($row[3])]);
                     $client = Client::firstOrCreate(['client_code' => strtoupper($row[8]), 'client_name' => strtoupper($row[9])]);
                     $channel = Channel::firstOrCreate(['channel_code' => strtoupper($row[10]), 'channel_desc' => strtoupper($row[11])]);
                     $agency = Agency::firstOrCreate(['agency_code' => strtoupper($row[19]), 'agency_name' => strtoupper($row[20])]);
                     $region = Region::firstOrCreate(['region_code' => strtoupper($row[16]), 'region' => strtoupper($row[15]), 'region_short' => strtoupper($row[14])]);
                     $customer = Customer::firstOrCreate(['customer_code' => strtoupper($row[12]), 'customer_name' => strtoupper($row[13])]);
                     $user = User::where('username', strtoupper($row[22]))->first();
                     if (empty($user) && !empty($row[22])) {
                         // dd($row);
                         $user = User::firstOrCreate(['username' => strtoupper($row[22]), 'name' => strtoupper($row[22]), 'email' => strtoupper($row[22]) . '@pcount.com', 'password' => \Hash::make($row[22])]);
                         $user->roles()->attach(2);
                     }
                     $storeExist = Store::where('store_code', strtoupper($row[5]))->first();
                     if (empty($storeExist) && !empty($row[22])) {
                         $store = Store::create(['storeid' => strtoupper($row[4]), 'store_code' => strtoupper($row[5]), 'store_code_psup' => strtoupper($row[6]), 'store_name' => strtoupper($row[7]), 'area_id' => $area->id, 'enrollment_id' => $enrollment->id, 'distributor_id' => $distributor->id, 'client_id' => $client->id, 'channel_id' => $channel->id, 'customer_id' => $customer->id, 'region_id' => $region->id, 'agency_id' => $agency->id, 'active' => 1]);
                         if (!empty($row[22])) {
                             StoreUser::insert(['store_id' => $store->id, 'user_id' => $user->id]);
                         }
                     } else {
                         $storeExist->storeid = strtoupper($row[4]);
                         $storeExist->store_code = strtoupper($row[5]);
                         $storeExist->store_code_psup = strtoupper($row[6]);
                         $storeExist->store_name = strtoupper($row[7]);
                         $storeExist->area_id = $area->id;
                         $storeExist->enrollment_id = $enrollment->id;
                         $storeExist->distributor_id = $distributor->id;
                         $storeExist->client_id = $client->id;
                         $storeExist->channel_id = $channel->id;
                         $storeExist->customer_id = $customer->id;
                         $storeExist->region_id = $region->id;
                         $storeExist->agency_id = $agency->id;
                         $storeExist->active = 1;
                         $storeExist->save();
                         StoreUser::where('store_id', $storeExist->id)->delete();
                         StoreUser::insert(['store_id' => $storeExist->id, 'user_id' => $user->id]);
                     }
                 }
                 $cnt++;
             }
         }
         \DB::commit();
     } catch (Exception $e) {
         dd($e);
         \DB::rollback();
     }
 }
Example #2
0
 public function login($username = '', $password = '', $remember = '')
 {
     $user = $this->find($username);
     if (!$username && !$password && $this->exists()) {
         Session::put($this->_sessionName, $this->data()->id);
     } else {
         $this->find($username);
         if ($user) {
             if ($this->data()->password === Hash::make($password)) {
                 Session::put($this->_sessionName, $this->data()->id);
                 if ($remember) {
                     $hash = Hash::unique();
                     $hashCheck = $this->_db->get('users_session', ['user_id', '=', $this->data()->id]);
                     if (!$hashCheck->count()) {
                         $this->_db->insert('users_session', ['user_id' => $this->data()->id, 'hash' => $hash]);
                     } else {
                         $hash = $hashCheck->first()->hash;
                     }
                     Cookie::put($this->_cookieName, $hash, Config::get('remember/cookie_expiry'));
                 }
                 return true;
             }
         }
     }
     return false;
 }
 function saving($model)
 {
     if (Hash::needsRehash($model->password)) {
         $hashed = Hash::make($model->password);
         $model->password = $hashed;
     }
 }
Example #4
0
 public function save($options = [])
 {
     if ($this->isDirty()) {
         $changed = $this->getDirty();
         if ($changed['password']) {
             $this->password = \Hash::make($changed['password']);
         }
     }
     parent::save($options);
 }
 public function setAPIAccessToken()
 {
     $user = null;
     do {
         $code = md5(\Hash::make($this->id . $this->email . $this->password . time() . mt_rand()));
         $user = static::whereApiAccessToken($code)->first();
     } while (isset($user));
     $this->api_access_token = $code;
     return $code;
 }
Example #6
0
 public static function addOrModify($data, $id = null)
 {
     $d = parent::addOrModify($data, $id);
     $d->nama = $data['nama'];
     $d->password = \Hash::make($data['password']);
     $d->username = $data['username'];
     $d->email = $data['email'];
     $d->role_id = $data['role_id'];
     $d->save();
 }
Example #7
0
 /**
  * This method will set model values
  *
  * @param array $attributes
  */
 public function fill(array $attributes)
 {
     parent::fill($attributes);
     if (!empty($attributes)) {
         if ($this->id == NULL) {
             // ok this is new member, so we need password for it
             $this->password = \Hash::make($attributes['passwd']);
         } else {
             // updating admin
             if (!empty($attributes['changePassword']) && $attributes['changePassword'] == 1) {
                 $this->password = \Hash::make($attributes['passwd']);
             }
         }
     }
 }
 public function getRequestArray($request)
 {
     return array('first_name' => $request->first_name, 'last_name' => $request->last_name, 'email' => $request->email, 'password' => \Hash::make($request->password));
 }
Example #9
0
 public function setPasswordAttribute($password)
 {
     $this->attributes['password'] = \Hash::make($password);
 }
Example #10
0
 public function getRequestArraySignUp($request)
 {
     return array('first_name' => $request->first_name, 'last_name' => $request->last_name, 'company' => $request->company, 'client_url' => $request->client_url, 'email' => $request->email, 'password' => \Hash::make($request->password));
 }
Example #11
0
 public function setPasswordAttribute($value)
 {
     if ($value) {
         $this->attributes['password'] = \Hash::make($value);
     }
 }