예제 #1
0
 public function social()
 {
     $social_id = Input::get('id');
     if (Auth::check()) {
         $user_id = Auth::user()->id;
         $user = User::find($user_id);
         $user->social_id = $social_id;
         $user->save();
         $store = StoreLocation::where('zipcode', Auth::user()->zipcode)->first();
         if ($store) {
             $store_id = $store->id;
         } else {
             $store_id = 0;
         }
         $cart = Cart::where('user_id')->orderBy('updated_at', 'desc')->first();
         if ($cart) {
             $cart_id = $cart->id;
         } else {
             $cart = new Cart();
             $cart->cart_url = "";
             $cart->user_id = Auth::user()->id;
             $cart->save();
             $cart_id = $cart->id;
             $cart_user = new CartUser();
             $cart_user->cart_id = $cart_id;
             $cart_user->user_id = Auth::user()->id;
             $cart_user->save();
         }
         Session::put('zipcode', Auth::user()->zipcode);
         Session::put('store_id', $store_id);
         Session::put('cart_id', $cart_id);
         return Redirect::to('/user');
     } else {
         $user = User::where('social_id', $social_id)->first();
         if ($user) {
             $already = 'there';
             Auth::login($user);
         } else {
             $already = '';
             $zipcode = Session::get('zipcode');
             if ($zipcode == null) {
                 return Redirect::to("/")->with('message', 'Please Select the Zipcode and proceed');
             } else {
                 $social_id = Input::get('id');
                 $first_name = Input::get('first_name');
                 $last_name = Input::get('last_name');
                 $email = Input::get('email');
                 $user = User::add($first_name, $last_name, '', $email, '', $zipcode, $social_id, '');
             }
         }
         Auth::login($user);
         $store = StoreLocation::where('zipcode', Auth::user()->zipcode)->first();
         if ($store) {
             $store_id = $store->id;
         } else {
             $store_id = 0;
         }
         $cart = Cart::where('user_id')->orderBy('updated_at', 'desc')->first();
         if ($cart) {
             $cart_id = $cart->id;
         } else {
             $cart = new Cart();
             $cart->cart_url = "";
             $cart->user_id = Auth::user()->id;
             $cart->save();
             $cart_id = $cart->id;
             $cart_user = new CartUser();
             $cart_user->cart_id = $cart_id;
             $cart_user->user_id = Auth::user()->id;
             $cart_user->save();
         }
         // dd(Session::get('zipcode'));
         Session::put('zipcode', Auth::user()->zipcode);
         Session::put('store_id', $store_id);
         Session::put('cart_id', $cart_id);
         if ($already == 'there') {
             return Redirect::to("/store/{$store_id}");
         } else {
             return Redirect::to("/login");
         }
     }
     $response = Response::json($response_array, $response_code);
     return $response;
 }
예제 #2
0
 public function delete_location()
 {
     $id = Request::segment(4);
     $city = City::find($id);
     City::where('id', $id)->delete();
     StoreLocation::where('zipcode', $city->zipcode)->delete();
     $message = "Successfully deleted the city";
     $type = "success";
     return Redirect::to('/admin/locations')->with('type', $type)->with('message', $message);
 }