Пример #1
0
 public function login()
 {
     try {
         $passwordMatch = false;
         $userDeviceUpdated = false;
         $access_token = '';
         $input = Request::all();
         $user = User::where('email', $input['email'])->first();
         if ($user) {
             if (crypt($input['password'], $user->password) == $user->password) {
                 $passwordMatch = true;
             }
         }
         if ($passwordMatch) {
             $userDevice = UserDevice::where('device_id', $input['device_id'])->first();
             $access_token = Uuid::uuid1()->toString();
             if ($userDevice) {
                 $userDeviceUpdated = $userDevice->update(['device_id' => $input['device_id'], 'rest_access_token' => $access_token, 'rest_access_token_expires' => Carbon::now()->addDays(360), 'rest_notification_id' => $input['notification_id'], 'os_type' => $input['os_type'], 'os_version' => $input['os_version'], 'hardware' => $input['hardware'], 'rest_app_version' => $input['app_version'], 'user_id' => $user->id]);
             } else {
                 $userDeviceUpdated = UserDevice::create(['device_id' => $input['device_id'], 'rest_access_token' => $access_token, 'rest_access_token_expires' => Carbon::now()->addDays(360), 'rest_notification_id' => $input['notification_id'], 'os_type' => $input['os_type'], 'os_version' => $input['os_version'], 'hardware' => $input['hardware'], 'rest_app_version' => $input['app_version'], 'user_id' => $user->id]);
             }
         }
         if ($userDeviceUpdated) {
             $vendorLocationContact = VendorLocationContact::where('user_id', $user->id)->first();
             $vendorLocation = VendorLocation::where('id', $vendorLocationContact->vendor_location_id)->first();
             $vendor = Vendor::where('id', $vendorLocation->vendor_id)->first();
             return response()->json(['id' => $user->id, 'access_token' => $access_token, 'full_name' => $user->full_name, 'email' => $user->email, 'phone_number' => $user->phone_number, 'role' => $user->role->name, 'vendor_name' => $vendor->name], 200);
         } else {
             return response()->json(['action' => 'Check if the email address and password match', 'message' => 'There is an email password mismatch. Please check and try again'], 227);
         }
     } catch (\Exception $e) {
         return response()->json(['message' => 'An application error occured.', 'error' => $e->getMessage()], 500);
     }
 }
Пример #2
0
 public function getByRestaurantId($id)
 {
     $vendorWithAttributes = Vendor::with('attributesBoolean', 'attributesDate', 'attributesInteger', 'attributesFloat', 'attributesText', 'attributesVarChar', 'attributesSingleSelect', 'attributesMultiSelect')->findOrFail($id);
     /*->wherehas('vendorType',function($q) {
           $q->where('type','Restaurants');
       })->first();*/
     $this->populateVendorAttributes($vendorWithAttributes->attributesBoolean);
     $this->populateVendorAttributes($vendorWithAttributes->attributesInteger);
     $this->populateVendorAttributes($vendorWithAttributes->attributesFloat);
     $this->populateVendorAttributes($vendorWithAttributes->attributesDate);
     $this->populateVendorAttributes($vendorWithAttributes->attributesText);
     $this->populateVendorAttributes($vendorWithAttributes->attributesVarChar);
     $this->populateVendorAttributes($vendorWithAttributes->attributesSingleSelect);
     $this->populateVendorAttributes($vendorWithAttributes->attributesMultiSelect);
     //return [ 'restaurant' => Vendor::find($id), 'attributes' => $this->attributes];
     return ['restaurant' => Vendor::find($id)];
 }