public function handleCallback($driver, Request $req)
 {
     $socialuser = \Socialize::with($driver)->user();
     $user = User::where('email', $socialuser->email)->first();
     if (count($user) < 1) {
         $user = new User();
         $user->id = (string) Uuid::generate();
         $user->email = $socialuser->email;
         $user->name = $socialuser->name;
         $user->avatar = $socialuser->avatar;
         $user->save();
     }
     $user = \Auth::loginUsingId($user->id);
     $authcookie = \Cookie::queue('authenticated', true, 20, null, "www.thinkmerit.in", false, false);
     $username = \Cookie::queue('name', $user->name, 20, null, "www.thinkmerit.in", false, false);
     $avatar = \Cookie::queue('avatar', $user->avatar, 20, null, "www.thinkmerit.in", false, false);
     $email = \Cookie::queue('email', $user->email, 20, null, "www.thinkmerit.in", false, false);
     if (app()->environment() == "production") {
         return \Redirect::to("http://www.thinkmerit.in");
     } else {
         return \Redirect::to("http://www.dev.thinkmerit.in");
     }
     /* ->withCookie($authcookie)
        ->withCookie($username)
        ->withCookie($avatar)
        ->withCookie($email);*/
     // ;
 }
 public function postRing($uuid, Request $req)
 {
     try {
         $bell = Bell::where('uuid', $uuid)->first();
         $user = $bell->user;
         $file = '';
         if ($req->hasFile('image')) {
             $image = $req->file('image');
             if ($image->isValid()) {
                 $file = Uuid::generate(1)->string;
                 $image->move(public_path() . '/img/uploads/', $file);
             }
         }
         $ring = Ring::create(['user_id' => $user->id, 'bell_id' => $bell->id, 'file' => $file]);
         $ring->save();
         $clients = $user->push_clients;
         if (!$clients->isEmpty() && $bell->active == 1) {
             $token = [];
             foreach ($clients as $client) {
                 $token[] = $client->token;
             }
             $http = new \GuzzleHttp\Client();
             $res = $http->request('POST', 'https://android.googleapis.com/gcm/send', ['headers' => ['Authorization' => 'key=' . env('SMARTBELL_GCM')], 'json' => ["registration_ids" => $token, "data" => ["image" => $file, "name" => $bell->name]]]);
         }
         return ['success'];
     } catch (\Exception $e) {
         return ['failure'];
     }
 }
示例#3
0
 protected static function boot()
 {
     parent::boot();
     static::creating(function ($model) {
         $model->{$model->getKeyName()} = Uuid::generate(4);
     });
 }
 /**
  *
  */
 public function run()
 {
     $faker = Faker::create('en_US');
     /*
      * Base User Accounts
      */
     // Mike's account
     $michael = User::create(['name' => 'Michael Norris', 'email' => '*****@*****.**', 'password' => bcrypt('password'), 'created_at' => Carbon::now(), 'updated_at' => Carbon::now()]);
     //$michaelProfile = Profile::create([
     //    'user_id'    => $michael->id,
     //    'nick_name'  => 'Mike',
     //    'photo_url'  => 'https://placeholdit.imgix.net/~text?txt=Mike&txtsize=80&bg=eceff1&txtclr=607d8b&w=640&h=640', //'/profile_photos/mike.jpg',
     //    'created_at' => Carbon::now(),
     //    'updated_at' => Carbon::now()
     //]);
     //
     //$michael->profile()->save($michaelProfile);
     unset($photos);
     $photos = [];
     foreach (range(1, 20) as $index) {
         $photos[] = ['id' => Uuid::generate(4), 'path' => $index . '.jpeg'];
         //echo $photos[$index + 1] . "\r\n";
     }
     Photo::insert($photos);
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param  CreatePostRequest $request
  * @return Response
  */
 public function store(CreatePostRequest $request, $category_id)
 {
     // save post
     $post = new Post();
     $post->fill($request->all());
     $post->category_id = $category_id;
     $post->save();
     // if have attachment, create the attachment record
     if ($request->hasFile('attachment')) {
         // generate filename based on UUID
         $filename = Uuid::generate();
         $extension = $request->file('attachment')->getClientOriginalExtension();
         $fullfilename = $filename . '.' . $extension;
         // store the file
         Image::make($request->file('attachment')->getRealPath())->resize(null, 640, function ($constraint) {
             $constraint->aspectRatio();
             $constraint->upsize();
         })->save(public_path() . '/attachments/' . $fullfilename);
         // attachment record
         $attachment = new Attachment();
         $attachment->post_id = $post->id;
         $attachment->original_filename = $request->file('attachment')->getClientOriginalName();
         $attachment->filename = $fullfilename;
         $attachment->mime = $request->file('attachment')->getMimeType();
         $attachment->save();
     }
     return redirect('category/' . $category_id . '/posts');
 }
示例#6
0
 /**
  * Sobreescribimos lo que sucede al momento de crear un nuevo usuario
  */
 public static function boot()
 {
     parent::boot();
     static::creating(function ($model) {
         $model->uuid = Uuid::generate(4);
     });
 }
 /**
  * Update the model in the database.
  *
  * @param  array  $attributes
  * @return bool|int
  */
 public function update(array $attributes = [])
 {
     if (isset($attributes['alias']) && empty($attributes['alias'])) {
         $name = $this->name;
         if (isset($attributes['name'])) {
             $name = $attributes['name'];
         }
         $attributes['alias'] = Str::slug($name) . '-' . Uuid::generate(4);
     }
     if (isset($attributes['galleries'])) {
         if (empty($attributes['galleries'])) {
             $attributes['galleries'] = [];
         }
         $attributes['galleries'] = json_encode($attributes['galleries']);
     }
     if (isset($attributes['attributes'])) {
         if (empty($attributes['attributes'])) {
             $attributes['attributes'] = [];
         }
         $attributes['attributes'] = json_encode($attributes['attributes']);
     }
     if (!parent::update($attributes)) {
         throw new Exception('Cannot update product.');
     }
     return $this;
 }
示例#8
0
 /**
  * {@inheritDoc}
  */
 protected static function boot()
 {
     parent::boot();
     // Here we add the UUID formatted client ID and secret during creation.
     static::creating(function ($model) {
         $model->{$model::CLIENT_ID} = (string) Uuid::generate(4);
         $model->{$model::CLIENT_SECRET} = (string) Uuid::generate(4);
     });
 }
 public static function bootUuidableTrait()
 {
     static::registerModelEvent('creating', function ($model) {
         $model->incrementing = false;
         if (!$model->exists && empty($model->{$model->getKeyName()})) {
             $model->{$model->getKeyName()} = (string) \Webpatser\Uuid\Uuid::generate(4);
         }
     });
 }
示例#10
0
 /**
  * The "booting" method of the model.
  *
  * We'll use this method to register event listeners.
  *
  * Events:
  *
  * 1. "creating": Before creating a new UUID we'll add the generated UUID namespace.
  */
 protected static function boot()
 {
     parent::boot();
     static::creating(function ($model) {
         // We generate a UUID v5 namespace using the name.
         // Casting it to a string creates a string using the toString()
         // method from Webpatser\Uuid\Uuid class.
         $model->setUuid((string) UuidFactory::generate(5, $model->getName(), UuidFactory::NS_DNS));
     });
 }
示例#11
0
 public static function generate($model = null)
 {
     do {
         $uuid = (string) Uuid::generate(4);
         if (!$model) {
             return $uuid;
         }
     } while (!static::isValidUuid($uuid, $model));
     return $uuid;
 }
示例#12
0
 /**
  * Create Product
  * 
  * @param  array  $attributes        Attributes
  * @return PhpSoft\Illuminate\ShoppingCart\Model\Product
  */
 public static function create(array $attributes = [])
 {
     if (empty($attributes['alias'])) {
         $attributes['alias'] = Str::slug($attributes['title']) . '-' . Uuid::generate(4);
     }
     if (empty($attributes['galleries'])) {
         $attributes['galleries'] = [];
     }
     $attributes['galleries'] = json_encode($attributes['galleries']);
     return parent::create($attributes)->fresh();
 }
 /**
  * This function overwrites the default boot static method of Eloquent models. It will hook
  * the creation event with a simple closure to insert the UUID
  */
 public static function bootUuidBinaryModelTrait()
 {
     static::creating(function ($model) {
         // This is necessary because on \Illuminate\Database\Eloquent\Model::performInsert
         // will not check for $this->getIncrementing() but directly for $this->incrementing
         $model->incrementing = false;
         $uuidVersion = !empty($model->uuidVersion) ? $model->uuidVersion : 4;
         // defaults to 4
         $uuid = Uuid::generate($uuidVersion);
         $model->attributes[$model->getKeyName()] = property_exists($model, 'uuidOptimization') && $model::$uuidOptimization ? $model::toOptimized($uuid->string) : $uuid->bytes;
     }, 0);
 }
 /**
  * This function overwrites the default boot static method of Eloquent models. It will hook
  * the creation event with a simple closure to insert the UUID
  */
 public static function bootUuid32ModelTrait()
 {
     static::creating(function ($model) {
         // This is necessary because on \Illuminate\Database\Eloquent\Model::performInsert
         // will not check for $this->getIncrementing() but directly for $this->incrementing
         $model->incrementing = false;
         $uuidVersion = !empty($model->uuidVersion) ? $model->uuidVersion : 4;
         // defaults to 4
         $uuid = Uuid::generate($uuidVersion);
         $model->attributes[$model->getKeyName()] = str_replace('-', '', $uuid->string);
     }, 0);
 }
 public function manualregister(Request $request)
 {
     $validator = $this->validator($request->all());
     if ($validator->fails()) {
         $this->throwValidationException($request, $validator);
     }
     $arr = $request->all();
     $arr['id'] = (string) Uuid::generate();
     $arr['password'] = bcrypt($arr['password']);
     $user = new User($arr);
     $user->save();
     \Auth::loginUsingId($user->id);
     return Response::json(['msg' => 'Succsfully registered!'], 200);
 }
示例#16
0
 public function postRegisterAjax(Request $request)
 {
     // try {
     $firstname = $request->input('firstname');
     $lastname = $request->input('lastname');
     $email = $request->input('email');
     $username = $request->input('email');
     $password = $request->input('password');
     try {
         $user = User::where('email', '=', $email)->first();
         if ($user) {
             return ['success' => '0', 'results' => '', 'messages' => 'The account already exists in weDonate.', 'redirect' => ''];
         }
     } catch (Exception $e) {
         Log::error($e);
     }
     // TODO: create a globa function to create a user
     $user = new User();
     $user->uuid = Uuid::generate(4);
     $user->registered_ip = $_SERVER['REMOTE_ADDR'];
     $user->registered_provider = 'email';
     $user->last_login_ip = null;
     $user->last_login_datetime = date('Y-m-d H:i:s');
     $user->email = $email;
     $user->username = $email;
     $user->password = Hash::make($password);
     $user->referrer_code = Uuid::generate(1, '0123456');
     $user->save();
     $profile = new UserProfile();
     $profile->user_id = $user->id;
     $profile->firstname = $firstname;
     $profile->lastname = $lastname;
     if ($request->has('referrer')) {
         $profile->referrer_id = User::where('referrer_code', '=', $request->has('referrer_code'))->first();
     }
     $profile->ranking = (int) User::all()->count();
     $profile->save();
     $role = Role::where('name', '=', 'donator')->first();
     $user->attachRole($role);
     if (Auth::attempt(['username' => $email, 'password' => $password])) {
         Log::info('USer registered, id=' . $user->id);
         return ['success' => '1', 'results' => '', 'messages' => 'Successfully connected.', 'redirect' => route('getDash')];
     } else {
         return ['success' => '0', 'results' => '', 'messages' => 'An errorred occurred.', 'redirect' => ''];
     }
     // } catch (Exception $e) {
     return ['success' => '0', 'results' => '', 'messages' => 'An errorred occurred.', 'redirect' => ''];
     // }
 }
 public function testCreateWithGalleries()
 {
     $user = factory(App\User::class)->make(['hasRole' => true]);
     Auth::login($user);
     $galleries = [\Webpatser\Uuid\Uuid::generate(4) . '.jpg', \Webpatser\Uuid\Uuid::generate(4) . '.jpg', \Webpatser\Uuid\Uuid::generate(4) . '.jpg'];
     $res = $this->call('POST', '/products', ['title' => 'Example Product', 'galleries' => $galleries]);
     $this->assertEquals(201, $res->getStatusCode());
     $results = json_decode($res->getContent());
     $this->assertObjectHasAttribute('entities', $results);
     $this->assertInternalType('array', $results->entities);
     $this->assertInternalType('array', $results->entities[0]->galleries);
     $this->assertEquals($galleries[0], $results->entities[0]->galleries[0]);
     $this->assertEquals($galleries[1], $results->entities[0]->galleries[1]);
     $this->assertEquals($galleries[2], $results->entities[0]->galleries[2]);
 }
示例#18
0
 public function store(Request $request)
 {
     $extension = Input::file('avatar')->getClientOriginalExtension();
     // getting image extension
     $fileName = Uuid::generate() . '.' . $extension;
     // renameing image
     \Intervention\Image\Facades\Image::make(Input::file('avatar'))->resize(1000, 220)->save(public_path('elmphoto/sliders/' . $fileName));
     //resmi kuçult
     $image = new Slider();
     $image->title = $request->title;
     $image->name = $fileName;
     $image->user_id = Auth::user()->id;
     $image->save();
     flash('Güncelleme işlemi başarıyla gercekleşti.', 'info');
     return redirect()->back();
 }
示例#19
0
 public function anyManageShop()
 {
     $product_types = ProductTypes::where('hidden', 0)->orderBy('name', 'ASC')->get();
     $success_msg = [];
     $error_msg = [];
     $rules = ['product_name' => 'required', 'product_category' => 'required', 'short_description' => 'required', 'product_description' => 'required', 'price' => 'required', 'quantity' => 'required|numeric'];
     $validator = Validator::make(Input::all(), $rules);
     if (Request::method() == 'POST') {
         if (!$validator->fails()) {
             $category_select = Input::get('product_category');
             $category = ProductTypes::find($category_select);
             if ($category) {
                 /** @var Products $product */
                 $product = new Products();
                 $product->uid = Uuid::generate()->string;
                 $product->name = Input::get('product_name');
                 $product->short_description = Input::get('short_description');
                 $product->description = Input::get('product_description');
                 $product->price_in_cents = Input::get('price') * 100;
                 $product->quantity = Input::get('quantity');
                 $product->product_type_id = $category->id;
                 $product->allow_review = 1;
                 $product->save();
                 if ($product->save()) {
                     if (Input::file('main_product_image')) {
                         $filename = Input::file('main_product_image')->getClientOriginalName();
                         $destination = storage_path() . '/app/upload/';
                         $file_path = Input::file('main_product_image')->move($destination, $filename);
                         //                            $diskLocal = Storage::disk('local');
                         $product_image = new ProductImages();
                         $product_image->url = $filename;
                         $product_image->product_id = $product->id;
                         $product_image->name = $filename;
                         $product_image->is_primary = 1;
                         $product_image->save();
                     }
                 }
                 $success_msg[] = 'Product Added!';
             } else {
                 $error_msg[] = 'Whoops! Sorry, product category not found';
             }
         } else {
             return Redirect::back()->withErrors($validator->messages())->withInput(Input::all());
         }
     }
     return View::make('shop.manage_store', ['product_types' => $product_types, 'success_msg' => $success_msg, 'error_msg' => $error_msg]);
 }
示例#20
0
 public function store(Request $request)
 {
     if (!$request->id) {
         $content = new Content();
         $content->title = $request->title;
         $content->alias = str_slug($request->title);
         $content->fulltext = $request->editor;
         $content->introtext = str_limit($request->editor, 250);
         $content->state = isset($request->ispublish);
         if ($request->hasFile('file')) {
             $extension = Input::file('file')->getClientOriginalExtension();
             // getting image extension
             $fileName = \Webpatser\Uuid\Uuid::generate() . '.' . $extension;
             // renameing image
             \Intervention\Image\Facades\Image::make(Input::file('file'))->resize(200, 220)->save(public_path('elmphoto/thumb/' . $fileName));
             //resmi kuçult
             $content->file = $fileName;
         }
         $content->catid = $request->kategori;
         $content->publish_up = Carbon::parse($request->publishdate);
         $content->user_id = Auth::user()->id;
         $content->save();
         return redirect()->back();
     } else {
         $content = Content::find($request->id);
         if ($request->hasFile('file')) {
             $extension = Input::file('file')->getClientOriginalExtension();
             // getting image extension
             $fileName = \Webpatser\Uuid\Uuid::generate() . '.' . $extension;
             // renameing image
             \Intervention\Image\Facades\Image::make(Input::file('file'))->resize(200, 220)->save(public_path('elmphoto/thumb/' . $fileName));
             //resmi kuçult
             $content->file = $fileName;
         }
         $content->title = $request->title;
         $content->alias = str_slug($request->title);
         $content->fulltext = $request->editor;
         $content->introtext = str_limit($request->editor, 250);
         $content->state = isset($request->ispublish);
         $content->catid = $request->kategori;
         $content->publish_up = Carbon::parse($request->publishdate);
         $content->user_id = Auth::user()->id;
         $content->save();
         return redirect()->back();
     }
 }
示例#21
0
 public function newItem($what, $request)
 {
     $item = null;
     if ($what === 'sticky') {
         $item = new Sticky();
     } else {
         if ($what === 'todo') {
             $item = new Todo();
         }
     }
     $item->id = (string) Uuid::generate();
     $item->user_id = $request->user()->id;
     $item->title = Input::get('title');
     $item->body = Input::get('body');
     //dd($item);
     $item->save();
     return $item;
 }
示例#22
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     // Add transaction to secure against faulty errors
     DB::beginTransaction();
     // Reset table
     DB::table('positions')->truncate();
     $names = ['left', 'center', 'right'];
     // We use models to avoid null constraint violations
     // in the timestamp columns
     foreach ($names as $name) {
         $position = new Position();
         $position->id = Uuid::generate(4);
         $position->name = $name;
         $position->save();
     }
     DB::commit();
     $this->command->info('Box positions seeded');
 }
示例#23
0
 public function store(Request $request)
 {
     $destinationPath = 'elmphoto/photos';
     // upload path
     $extension = Input::file('avatar')->getClientOriginalExtension();
     // getting image extension
     $fileName = Uuid::generate() . '.' . $extension;
     // renameing image
     \Intervention\Image\Facades\Image::make(Input::file('avatar'))->resize(300, 200)->save(public_path('elmphoto/thumb/' . $fileName));
     //resmi kuçult
     Input::file('avatar')->move($destinationPath, $fileName);
     // uploading file to given path
     $image = new Image();
     $image->title = $request->title;
     $image->galery_id = $request->galery;
     $image->desc = $request->desc;
     $image->name = $fileName;
     $image->user_id = Auth::user()->id;
     $image->save();
     flash('Güncelleme işlemi başarıyla gercekleşti.', 'info');
     return redirect()->back();
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     /*$user=new User;
             $user->id=Uuid::generate();
             $user->name="Marungsha";
             $user->email="*****@*****.**";
             $user->password=bcrypt("783347ki");
     
             if(!User::where('email', $user->email)->get()){
                 $user->save();
                 $user->roles()->attach([1,2]);
             }*/
     $user = User::firstOrCreate(['id' => Uuid::generate(), 'name' => "Marungsha", 'email' => "*****@*****.**", 'password' => bcrypt("783347ki")]);
     $user->roles()->attach([1, 2]);
     $user = User::firstOrCreate(['id' => Uuid::generate(), 'name' => "Milton", 'email' => "*****@*****.**", 'password' => bcrypt("783347ki")]);
     $user->roles()->attach([1]);
     /* $admin=new UserAdmin;
        $admin->user_id=$user->id;
        $admin->is_admin=1;
        $admin->is_super_admin=1;
        $admin->save();*/
 }
示例#25
0
 public function anyBooking()
 {
     $error_msg = [];
     $success_msg = [];
     $service_types = ServiceTypes::all();
     if (Request::isMethod('POST')) {
         $rules = ['first_name' => 'required', 'last_name' => 'required', 'email' => 'required', 'phone' => 'required', 'address' => 'required', 'suburb' => 'required', 'city' => 'required', 'booking_date' => 'required', 'service_type_id' => 'required'];
         $validator = Validator::make(Input::all(), $rules);
         if (!$validator->fails()) {
             $booking_date = Input::get('booking_date');
             $user_booking_count = Bookings::where('user_id', User::get()->id)->where('pending', 1)->where('booking_date', date('Y-m-d', strtotime($booking_date)))->count();
             if ($user_booking_count >= 1) {
                 $error_msg[] = 'Sorry. Our system shows you have a pending booking. We are currently processing your service booking
                     and will contact you within 48 hours.';
             } else {
                 $booking = new Bookings(Input::all());
                 $booking->uid = Uuid::generate()->string;
                 $booking->user_id = User::get()->id;
                 $booking->pending = 1;
                 $booking->booking_date = date('Y-m-d', strtotime(Input::get('booking_date')));
                 $booking->save();
                 if ($booking) {
                     $success_msg[] = 'Great! We have received your service booking. You should be able to hear from us in the next 48 hours.';
                 } else {
                     $error_msg[] = 'Whoops! There was an error in your booking. Please try again.';
                 }
             }
         } else {
             return Redirect::back()->withErrors($validator->messages())->withInput(Input::all());
         }
     }
     if (User::check()) {
         return View::make('booking.booking', ['user' => User::get(), 'service_types' => $service_types, 'error_msg' => $error_msg, 'success_msg' => $success_msg]);
     } else {
         return Redirect::to('/user/login');
     }
 }
 public function postcreate()
 {
     $test = new Test();
     $test->id = Uuid::generate();
     $test->name = Input::get('name');
     $test->description = Input::get('description');
     $test->duration = Input::get('duration');
     $test->testday = Input::get('testday');
     $test->testtime = Input::get('testtime');
     $test->createdby = \Auth::user()->id;
     $v = \Validator::make(Input::all(), ['name' => 'required|unique:tests', 'description' => 'required', 'duration' => 'required|min:1|max:4']);
     if ($v->fails()) {
         return back()->withInput()->withErrors($v);
     } else {
         $test->save();
         foreach ((array) Input::get('ratings') as $key => $rating) {
             $testRating = new TestRating();
             $testRating->id = $test->id;
             $testRating->rating = intval($rating);
             $testRating->save();
         }
     }
     return redirect("/admin/test");
 }
示例#27
0
 /**
  * Store the project to the database
  *
  * @return static
  * @throws Exception
  */
 protected function storeProject()
 {
     return $this->projectRepository->store(['uuid' => (string) Uuid::generate(4), 'video_id' => $this->source()->getId($this->getParam('path')), 'source_id' => $this->getParam('source_id'), 'path' => $this->getParam('path'), 'status_id' => Status::CREATE]);
 }
 /**
  * When creating a user, please set a uuid. and encrypt the password
  * @param $model
  * @throws \Exception
  */
 public function creating($model)
 {
     $model->uuid = Uuid::generate(4);
     $model->password = bcrypt($model->password);
 }
 public function notesupload()
 {
     $chapterid = Input::get('chapteruuid');
     $file = Input::file('notes');
     $notes = Notes::where('chapter_id', $chapterid)->first();
     if (!$notes) {
         $notes = new Notes();
         $notes->id = Uuid::generate();
         $notes->chapter_id = $chapterid;
         $notes->file_path = public_path() . "/notes/";
     }
     $notes->file_name = $file->getClientOriginalName();
     $notes->save();
     if ($file->isValid()) {
         $fileName = $notes->chapter_id . ".zip";
         /* if(env('APP_ENV')==="production"){//give write permission
                chmod($notes->file_path, 0777);
            }*/
         $file->move($notes->file_path, $fileName);
         //\Storage::disk('notes')->put($fileName,File::get($file));
         //$filePath=storage_path()."/thinkmerit/notes/";
         $zip = \Comodojo\Zip\Zip::open($notes->file_path . $fileName);
         $zip->extract($notes->file_path . $chapterid);
         $notes->save();
         $zip->close();
         unlink($notes->file_path . $fileName);
         /*if(env('APP_ENV')==="production"){//exclude write permission
               chmod($notes->file_path, 0444);
           }*/
         //\Storage::disk('notes')->delete($fileName);
         return back()->withErrors(['success' => "File successfully uploaded!"]);
     }
     return back()->withErrors(['error' => "Error uploading file!"]);
 }
 /**
  * @param $model
  * @throws \Exception
  */
 public function creating($model)
 {
     $model->uuid = Uuid::generate(4);
 }