Exemplo n.º 1
0
 public function mergeStreetNumberAndAddressUser()
 {
     $users = User::all()->toArray();
     foreach ($users as $user) {
         $this_user = User::find($user['id']);
         $this_user->street_name = $user['street_number'] . ' ' . $user['street_name'];
         $this_user->street_number = '';
         $this_user->save();
     }
 }
Exemplo n.º 2
0
 public function getReceiverAttribute()
 {
     $user_id = $this->receiver_id;
     $company = Company::with('company_logo_detail')->where('user_id', '=', $user_id)->first();
     $data = [];
     $type = 'user';
     if (!empty($company)) {
         $data = $company;
         $type = 'employer';
     } else {
         $data = User::with('profile_image_detail')->where('id', '=', $user_id)->first();
     }
     return ['type' => $type, 'data' => $data];
 }
Exemplo n.º 3
0
 public function getWorkDistanceAttribute()
 {
     if (Session::has('user_id')) {
         $user_id = Session::get('user_id');
         $lat = $this->job_locations->lat;
         $lng = $this->job_locations->lng;
         $user = User::where('id', '=', $user_id)->within((int) $this->search_radius, 'kilometers', $lat, $lng)->where('lat', '!=', '')->where('lng', '!=', '')->first();
         if (empty($user) || count($user) == 0) {
             return 0;
         }
         return $user->toArray()['distance'];
     }
     return 0;
 }
Exemplo n.º 4
0
 public function update(GoogleApiService $google, $user_id)
 {
     try {
         $input = Request::all();
         $address = $input['street_name'] . ', ' . $input['city_town'] . ', ' . $input['zip_code'] . ', ' . $input['country'];
         $input['lat'] = 0;
         $input['lng'] = 0;
         $geocode = $google->geoCoding($address);
         if ($geocode['status'] == 'OK') {
             $input['lat'] = $geocode['lat'];
             $input['lng'] = $geocode['lng'];
             $birthday = $input['birth_year'] . '-' . $input['birth_month'] . '-' . $input['birth_date'];
             $input['birth_date'] = date('Y-m-d', strtotime($birthday));
             unset($input['password_confirmation']);
             unset($input['birth_year']);
             unset($input['birth_month']);
             User::where('id', '=', $user_id)->update($input);
             $response = User::where('id', '=', $user_id)->first()->toArray();
             if (!empty($response)) {
                 return $this->json_response->success($response);
             }
             return $this->json_response->error($response);
         } else {
             return $this->json_response->error(['validation_message' => $geocode['status']]);
         }
     } catch (Exception $e) {
         return $this->json_response->error(['error' => $e->getMessage()]);
     }
 }
Exemplo n.º 5
0
 public function updateCompanyV2(CompanyService $company, GoogleApiService $google, $company_id)
 {
     $retrieve = ['email', 'user_id', 'name', 'employee_count', 'tax_vat_number', 'description', 'street_name', 'street_number', 'building_name', 'building_floor', 'building_room', 'city_town', 'province', 'region_state', 'zip_code', 'country', 'founded_date', 'founded_month', 'founded_year', 'contact_first_name', 'contact_last_name', 'contact_title', 'contact_phone', 'contact_email', 'status_message'];
     try {
         $input = Request::only($retrieve);
         $user_id = $input['user_id'];
         $user = ['email' => $input['email']];
         User::whereId($user_id)->update($user);
         unset($input['email']);
         unset($input['user_id']);
         if (!empty($response)) {
             return $this->json_response->success($response);
         }
         $address = $input['street_name'] . ', ' . $input['city_town'] . ', ' . $input['zip_code'] . ', ' . $input['country'];
         $input['lat'] = 0;
         $input['lng'] = 0;
         $geocode = $google->geoCoding($address);
         if ($geocode['status'] == 'OK') {
             $input['lat'] = $geocode['lat'];
             $input['lng'] = $geocode['lng'];
             $response = $company->updateCompany($user_id, $company_id, $input);
             if (!empty($response)) {
                 return $this->json_response->success($response);
             }
             return $this->json_response->error($response);
         } else {
             return $this->json_response->error(['validation_message' => $geocode['status']]);
         }
         return $this->json_response->error($response);
     } catch (Exception $e) {
         return $this->json_response->error(['error' => $e->getMessage()]);
     }
 }
Exemplo n.º 6
0
 public function getUserImageInfo($user_id)
 {
     $user_image = User::where('id', '=', $user_id)->first();
     $file_info = File::where('id', '=', $user_image->profile_image)->first()->toArray();
     return $file_info;
 }
Exemplo n.º 7
0
 public function processVerification($verification_code)
 {
     $logged = false;
     $verified = false;
     $expired = false;
     $verification_info = UserVerify::where('verification_code', '=', $verification_code)->first();
     //code cannot be found
     if (empty($verification_info)) {
         return 'not-found';
     }
     if (!empty(JWTAuth::getToken())) {
         $logged = true;
     }
     $verification_info = $verification_info->toArray();
     $end = date('Y-m-d H:i:s', strtotime($verification_info['created_at'] . '+1 hour'));
     $now = date('Y-m-d H:i:s');
     //checks if user has been verified
     if ($this->getUserById($verification_info['user_id'])['verified'] == 1) {
         $verified = true;
     }
     //if not verified check if the code already expired
     if (!$verified) {
         if (strtotime($now) >= strtotime($end) || $verification_info['status'] == 2) {
             if ($verification_info['status'] != 2) {
                 UserVerify::where('verification_code', '=', $verification_code)->update(['status' => 2]);
             }
             $expired = true;
         }
     }
     // checks if user logged in is the same user using verification code
     if ($logged) {
         $user = $this->getUserByToken()->toArray();
         if ($user['id'] != $verification_info['user_id']) {
             if ($verified) {
                 return 'already-verified-user-not-logged';
             }
             if ($expired) {
                 return 'expired-user-not-logged';
             }
             return 'user-not-logged';
         }
     }
     UserVerify::where('verification_code', '=', $verification_code)->update(['status' => 1]);
     User::where('id', '=', $verification_info['user_id'])->update(['verified' => 1]);
     $this->sendValidatedEmail($verification_info['user_id']);
     if ($expired) {
         return 'expired';
     }
     if ($logged) {
         if ($verified) {
             return 'already-verified-logged';
         }
         return 'success-logged';
     }
     if ($verified) {
         return 'already-verified-not-logged';
     }
     return 'success-not-logged';
 }
Exemplo n.º 8
0
 /**
  * Create a new user instance after a valid registration.
  *
  * @param  array  $data
  * @return User
  */
 protected function create(array $data)
 {
     return User::create(['name' => $data['name'], 'email' => $data['email'], 'password' => bcrypt($data['password'])]);
 }
Exemplo n.º 9
0
 public function approveCompany($company_id)
 {
     try {
         $company = Company::find($company_id);
         $company->company_status = 'approved';
         if ($company->save()) {
             $company_name = $company->name;
             $data = ['user_type' => 'company', 'message_type' => 'approved', 'company' => $company_name];
             $user = User::find($company->user_id);
             $email = $user->email;
             $sent = Mail::queue('worklemon.email.company.approved', $data, function ($message) use($email, $company_name) {
                 $message->to($email, $company_name);
                 $message->subject($company_name . ' has been approved by Worklemon');
                 $message->priority(1);
             });
             if ($sent) {
                 return true;
             }
             return false;
         }
         return false;
     } catch (Exception $e) {
         return Response::json(['error' => $e->getMessage()]);
     }
 }