public function __construct($options = array()) { parent::__construct($options); // connect to database $database = Registry::get("database"); $database->connect(); // schedule: load user from session Events::add("framework.router.beforehooks.before", function ($name, $parameters) { $session = Registry::get("session"); $controller = Registry::get("controller"); $user = $session->get("user"); if ($user) { $controller->user = \User::first(array("id = ?" => $user)); } }); // schedule: save user to session Events::add("framework.router.afterhooks.after", function ($name, $parameters) { $session = Registry::get("session"); $controller = Registry::get("controller"); if ($controller->user) { $session->set("user", $controller->user->id); } }); // schedule: disconnect from database Events::add("framework.controller.destruct.after", function ($name) { $database = Registry::get("database"); $database->disconnect(); }); }
public function run() { DB::table('comments')->delete(); $user_id = User::first()->id; $post_id = Post::first()->id; DB::table('comments')->insert(array(array('user_id' => $user_id, 'post_id' => $post_id, 'content' => $this->content1), array('user_id' => $user_id, 'post_id' => $post_id, 'content' => $this->content2), array('user_id' => $user_id, 'post_id' => $post_id, 'content' => $this->content3), array('user_id' => $user_id, 'post_id' => $post_id + 1, 'content' => $this->content1), array('user_id' => $user_id, 'post_id' => $post_id + 1, 'content' => $this->content2), array('user_id' => $user_id, 'post_id' => $post_id + 2, 'content' => $this->content1))); }
public function do_help() { $user = Sentry::getUser(); $subject = "Newsletter Help: " . Input::get('subject'); $emailbody = Input::get('message'); $from_name = $user->first_name . ' ' . $user->last_name; $from_email = $user->email; $admin = User::first(); $to_name = $admin->first_name . ' ' . $admin->last_name; $to_email = $admin->email; $rules = array('subject' => 'required|max:128', 'message' => 'required'); $validator = Validator::make(Input::all(), $rules); if ($validator->fails()) { return Redirect::to('dashboard/help')->withErrors($validator); } else { $browser = new Browser(); $userbrowser = $browser->getBrowser() . ' ' . $browser->getVersion(); $userplatform = $browser->getPlatform(); $userIP = $_SERVER["REMOTE_ADDR"]; $page = URL::current(); $data = array('emailbody' => $emailbody, 'userbrowser' => $userbrowser, 'userplatform' => $userplatform, 'userIP' => $userIP, 'page' => $page); $issent = Mail::send('emails.help-email', $data, function ($message) use($from_email, $from_name, $subject, $to_name, $to_email) { $message->from($from_email, $from_name)->to($to_email, $to_name)->subject($subject); }); if ($issent) { return Redirect::to('dashboard/help')->with('success', 'Success! You will be contacted soon regarding your issue.'); } else { return Redirect::to('dashboard/help')->with('error', 'An error was encountered sending the email. Please try again.'); } } }
public function run() { DB::table('comments')->delete(); $user_id = User::first()->id; $post_id = Post::first()->id; DB::table('comments')->insert(array(array('user_id' => $user_id, 'post_id' => $post_id, 'content' => $this->content1, 'created_at' => new DateTime(), 'updated_at' => new DateTime()), array('user_id' => $user_id, 'post_id' => $post_id, 'content' => $this->content2, 'created_at' => new DateTime(), 'updated_at' => new DateTime()), array('user_id' => $user_id, 'post_id' => $post_id, 'content' => $this->content3, 'created_at' => new DateTime(), 'updated_at' => new DateTime()), array('user_id' => $user_id, 'post_id' => $post_id + 1, 'content' => $this->content1, 'created_at' => new DateTime(), 'updated_at' => new DateTime()), array('user_id' => $user_id, 'post_id' => $post_id + 1, 'content' => $this->content2, 'created_at' => new DateTime(), 'updated_at' => new DateTime()), array('user_id' => $user_id, 'post_id' => $post_id + 2, 'content' => $this->content1, 'created_at' => new DateTime(), 'updated_at' => new DateTime()))); }
/** * Initializes the test step by enabling filters * * @param bool $enableFilters * @return void */ protected function initTestStep($enableFilters = TRUE) { $this->be(User::first()); if ($enableFilters) { Route::enableFilters(); } }
public function login() { if (RequestMethods::post('login')) { $email = RequestMethods::post('email'); $password = RequestMethods::post('password'); $view = $this->getActionView(); $error = false; if (empty($email)) { $view->set('email_error', 'Email is not provided'); $error = true; } if (empty($password)) { $view->set('password_error', 'Password is not provided'); $error = true; } if (!$error) { $user = User::first(array('email=?' => $email, 'password=?' => $password, 'live=?' => true, 'deleted=?' => false)); if (!empty($user)) { $session = Registry::get('session'); $session->set('user', serialize($user)); header("Location: /users/profile.html"); exit; } else { $view->set('password_error', 'Email address and/or password are incorrect'); } exit; } } }
public function fbLogin() { $this->JSONview(); $view = $this->getActionView(); $session = Registry::get("session"); if (RequestMethods::post("action") == "fbLogin" && isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest') { // process the registration $fbid = RequestMethods::post("fbid"); $access_token = RequestMethods::post("access_token"); $user = !$this->user ? User::first(["fbid = ?" => $fbid]) : $this->user; if (!$user) { try { $user = $this->_register(); } catch (\Exception $e) { $view->set("success", false); return; } } $this->setUser($user); $redirect = RequestMethods::post("loc", ""); if ($redirect != '') { $token = Shared\Markup::uniqueString(); $session->set('CampaignAccessToken', $token); $view->set("redirect", "/" . $redirect . "/{$token}"); } $view->set("success", true); } else { $view->set("success", false); } }
public function run() { DB::table('posts')->delete(); $user_id = User::first()->id; Post::create(array('user_id' => $user_id, 'title' => 'Lorem ipsum dolor sit amet', 'slug' => 'lorem-ipsum-dolor-sit-amet', 'content' => $this->content, 'meta_title' => 'meta_title1', 'meta_description' => 'meta_description1', 'meta_keywords' => 'meta_keywords1', 'created_at' => new DateTime(), 'updated_at' => new DateTime())); Post::create(array('user_id' => $user_id, 'title' => 'Vivendo suscipiantur vim te vix', 'slug' => 'vivendo-suscipiantur-vim-te-vix', 'content' => $this->content, 'meta_title' => 'meta_title2', 'meta_description' => 'meta_description2', 'meta_keywords' => 'meta_keywords2', 'created_at' => new DateTime(), 'updated_at' => new DateTime())); Post::create(array('user_id' => $user_id, 'title' => 'In iisque similique reprimique eum', 'slug' => 'in-iisque-similique-reprimique-eum', 'content' => $this->content, 'meta_title' => 'meta_title3', 'meta_description' => 'meta_description3', 'meta_keywords' => 'meta_keywords3', 'created_at' => new DateTime(), 'updated_at' => new DateTime())); }
public function setUp() { parent::setUp(); // Authentication as super user. $user = User::first(); Auth::login($user); $this->createLRS(); }
/** * Tests the update function in the MetricController * @depends testStore * @param void * @return void */ public function testDelete() { $this->be(User::first()); $this->runStore($this->input); $metric = new MetricController(); $metric->delete(1); $metricDeleted = Metric::withTrashed()->find(1); $this->assertNotNull($metricDeleted->deleted_at); }
/** * Tests the update function in the TopUpController * @depends testStore * @param void * @return void */ public function testDelete() { $this->be(User::first()); $this->runStore($this->input); $topup = new TopUpController(); $topup->delete(1); $topupDeleted = TopUpRequest::withTrashed()->find(1); $this->assertNotNull($topupDeleted->deleted_at); }
/** * Tests the update function in the CommodityController * @depends testStore * @param void * @return void */ public function testDelete() { $this->be(User::first()); $this->runStore($this->input); $commodity = new CommodityController(); $commodity->delete(1); $commodityDeleted = Commodity::withTrashed()->find(1); $this->assertNotNull($commodityDeleted->deleted_at); }
/** * Tests the update function in the IssueController * @depends testStore * @param void * @return void */ public function testDelete() { $this->be(User::first()); $this->runStore($this->input); $issue = new IssueController(); $issue->delete(1); $issueDeleted = Issue::withTrashed()->find(1); $this->assertNotNull($issueDeleted->deleted_at); }
public function testUpdateFails() { Factory::create('User', ['first_name' => 'foo']); $user = User::first(); $this->action('PUT', 'Admin\\UsersController@update', $user->id, ['first_name' => null]); $this->assertRedirectedToRoute('admin.users.edit', $user->id); $this->assertHasOldInput(); $this->assertSessionHasErrors(); }
/** * Tests the update function in the SupplierController * @depends testStore * @param void * @return void */ public function testDelete() { $this->be(User::first()); $this->runStore($this->input); $supplier = new SupplierController(); $supplier->delete(1); $supplierDeleted = Supplier::withTrashed()->find(1); $this->assertNotNull($supplierDeleted->deleted_at); }
/** * Testing Lot destroy funciton */ public function testDelete() { $this->be(User::first()); $this->runStore($this->input); $lot = new LotController(); $lot->delete(1); $lotDeleted = lot::withTrashed()->find(1); $this->assertNotNull($lotDeleted->deleted_at); }
/** * Tests the update function in the PatientController * @depends testStore * @param void * @return void */ public function testDelete() { $this->be(User::first()); $this->runStore($this->input); $patientSaved = Patient::orderBy('id', 'desc')->take(1)->get()->toArray(); $patient = new PatientController(); $patient->delete($patientSaved[0]['id']); $patientsDeleted = Patient::withTrashed()->find($patientSaved[0]['id']); $this->assertNotNull($patientsDeleted->deleted_at); }
function testPivotModel() { $pivot = User::first()->messages()->pivot(); $this->assertInstanceOf('\\ORM\\Model', $pivot); $this->assertEquals($pivot::getTable(), 'messages_users'); $this->assertCount(2, $pivot::all()); $pivot->user_id = 2; $pivot->message_id = 1; $pivot->save(); $this->assertCount(3, $pivot::all()); }
public function run() { Bio::truncate(); $author = User::first(); $shortBio = $author->bios()->create(['nickname' => 'Short Bio', 'body' => 'I am short.']); $longBio = $author->bios()->create(['nickname' => 'Long Bio', 'body' => 'I am short and I love being short and this is very long.']); $author->bios()->saveMany([$shortBio, $longBio]); // Add a talk for user 2 for testing purposes $author = User::find(2); $trueBio = $author->bios()->create(['nickname' => 'True Bio', 'body' => 'I am a person.']); $falseBio = $author->bios()->create(['nickname' => 'False Bio', 'body' => 'I am an elephant.']); $author->bios()->saveMany([$trueBio, $falseBio]); }
/** * @before _secure */ public function invoice($order_id) { $this->setLayout("layouts/blank"); $this->seo(array("title" => "Invoice", "view" => $this->getLayoutView())); $view = $this->getActionView(); $order = Order::first(array("id = ?" => $order_id, "user_id = ?" => $this->user->id)); $patient = User::first(array("id = ?" => $order->user_id)); $appointments = Appointment::all(array("order_id = ?" => $order_id)); $instamojo = Instamojo::first(array("purpose = ?" => "order", "purpose_id = ?" => $order_id), array("payment_request_id")); $view->set("order", $order); $view->set("patient", $patient); $view->set("appointments", $appointments); $view->set("instamojo", $instamojo); }
/** * Initializes the test step * * @param bool $authenticate * @param bool $enableFilters * @param bool $flushCaches * @return void */ protected function initTestStep($authenticate = TRUE, $enableFilters = TRUE, $flushCaches = TRUE) { if ($authenticate) { $this->be(User::first()); } else { Auth::logout(); } if ($enableFilters) { Route::enableFilters(); } if ($flushCaches) { Config::flush(); Session::flush(); } }
/** * Find all conversations between 2 users * * @return JSON Ajax */ public function find() { if (Request::ajax()) { $array = array(Auth::id(), new MongoId(Input::get('receiver_id'))); $chat = Chat::whereIn('participants', $array)->first(); if (isset($chat->_id)) { $sender = UserController::getUser(Auth::user()); $receiver = UserController::getUser(User::first(Input::get('receiver_id'))); $sender_name = $sender->name . ' ' . $sender->last_name; $receiver_name = $receiver->name . ' ' . $receiver->last_name; return Response::json(array('chat' => $chat, 'sender' => array('_id' => $sender->_id, 'name' => $sender_name), 'receiver' => array('_id' => $receiver->_id, 'name' => $receiver_name))); } else { return Response::json(array('chat' => "")); } } }
public function setUp() { if (!self::$hasSetup) { echo 'Doing initial setup...'; parent::setUp(); DB::beginTransaction(); self::$character = new Character(); self::$character->user_id = User::first()->id; self::$character->name = "UNIT TEST CHARACTER"; self::$character->save(); self::$version = CharacterVersion::createNewVersion(self::$character); self::$player = new User(); self::$storyteller = User::listStorytellers()->first(); self::$instance = $this; self::$hasSetup = true; } }
public function result($participant_id) { $participant = Participant::first(array("id = ?" => $participant_id)); $user = User::first(array("id = ?" => $participant->user_id), array("name")); $campaign = Campaign::first(array("id = ?" => $participant->campaign_id)); $image = CDN . "uploads/images/" . $participant->image; $info = getimagesize(APP_PATH . "/public/assets/uploads/images/" . $participant->image); $this->seo(array("title" => $campaign->title, "description" => $campaign->description, "photo" => $image, "view" => $this->getLayoutView())); $this->layoutView->set("width", $info[0])->set("height", $info[1]); $view = $this->getActionView(); $domain = Meta::first(array("property = ?" => "domain", "live = ?" => true)); $items = Participant::all(array(), array("DISTINCT campaign_id"), "created", "desc", 3, 1); $view->set("items", $items); $view->set("campaign", $campaign); $view->set("participant", $participant); $view->set("domain", $domain); }
/** * Return index page for /admin if authorized, otherwise go to /auth/login. * * @return View */ public function index() { if (Auth::check()) { $user = User::first(); if (is_null($user)) { $users = User::all(); return Redirect::route('admin.index', compact('users')); } else { $utility = new common\Utilities(); $user['dob'] = $utility->convertMySQLFormatToDatePickerFormat($user['dob']); $paginatedUsers = User::paginate($this->pagination); return View::make('admin.show', compact('user', 'paginatedUsers')); } } else { return View::make('auth.login'); } }
/** * Execute the console command. * * @return mixed */ public function fire() { echo "\n--- Lets create some pet postings! ---\n\n"; echo "| This will create a new pet record with the prompted information,\n"; echo "| a random status, age, and color, and user, species, and breed\n"; echo "| ids that belong to the first record of each in the database.\n\n"; echo "| This command will also get a list of the files in /img/uploads\n"; echo "| and select one at random from the list to create a new image\n"; echo "| object and record to tie to the pet object we just created.\n\n"; echo "name \n> "; $name = $this->ask(''); echo "color\n> "; $color = $this->ask(''); echo "description\n> "; $description = $this->ask(''); $species = ['cat', 'dog', 'other']; $species = $species[array_rand($species)]; $status = ['lost', 'found', 'adoptable']; $status = $status[array_rand($status)]; $age = ['baby', 'young', 'adult', 'senior']; $age = $age[array_rand($age)]; $gender = ['male', 'female', 'unknown']; $gender = $gender[array_rand($gender)]; $a_num = ['342335', '234567', '234412', '123123', '123345', '345345']; $a_num = $a_num[array_rand($a_num)]; $pet = new Pet(); $pet->name = $name; $pet->species_id = Species::first()->id; $pet->status = $status; $pet->color = $color; $pet->age = $age; $pet->description = $description; $pet->gender = $gender; $pet->a_num = $a_num; $pet->breed_id = Breed::first()->id; $pet->user_id = User::first()->id; $pet->save(); $images = explode("\n", trim(`ls public/img/uploads`)); $petImg = $images[array_rand($images)]; $img = new Image(); $img->pet_id = $pet->id; $img->img_path = "/img/uploads/{$petImg}"; $img->save(); $this->info('pet created!'); }
public function run() { TalkRevision::truncate(); Talk::truncate(); $author = User::first(); $greatTalk = $author->talks()->create([]); $terribleTalk = $author->talks()->create([]); $author->talks()->saveMany([$greatTalk, $terribleTalk]); $greatTalk->revisions()->create(['title' => 'My great talk', 'description' => 'Description of the talk', 'type' => 'seminar', 'level' => 'intermediate', 'length' => '45', 'organizer_notes' => 'Organizer notes', 'created_at' => '2013-11-29 15:54:41']); $greatTalk->revisions()->create(['title' => 'My awesome talk', 'description' => 'Description of the talk', 'type' => 'seminar', 'level' => 'intermediate', 'length' => '45', 'organizer_notes' => 'Organizer notes', 'created_at' => '2013-11-27 15:54:41']); $terribleTalk->revisions()->create(['title' => 'My awesome talk', 'description' => 'Description of the talk', 'type' => 'seminar', 'level' => 'intermediate', 'length' => '45', 'organizer_notes' => 'Organizer notes', 'created_at' => '2013-11-28 15:54:41']); // Add a talk for user 2 for testing purposes $author = User::find(2); $superTalk = $author->talks()->create([]); $spiffyTalk = $author->talks()->create([]); $author->talks()->saveMany([$superTalk, $spiffyTalk]); $superTalk->revisions()->create(['title' => 'My Super talk', 'description' => 'Description of the talk', 'type' => 'seminar', 'level' => 'intermediate', 'length' => '45', 'organizer_notes' => 'Organizer notes', 'created_at' => '2013-11-27 15:54:41']); $spiffyTalk->revisions()->create(['title' => 'My Spiffy talk', 'description' => 'Description of the talk', 'type' => 'seminar', 'level' => 'intermediate', 'length' => '45', 'organizer_notes' => 'Organizer notes', 'created_at' => '2013-11-28 15:54:41']); }
/** * @before _secure, _school */ public function enrollments($classroom_id, $grade_id) { $classroom = \Classroom::first(array("id = ?" => $classroom_id), array("id", "organization_id", "grade_id", "educator_id")); if (!$classroom || $classroom->organization_id != $this->organization->id || $classroom->grade_id != $grade_id) { self::redirect("/school"); } $this->setSEO(array("title" => "School | View students in section")); $view = $this->getActionView(); $enrollments = \Enrollment::all(array("classroom_id = ?" => $classroom_id)); $students = array(); foreach ($enrollments as $e) { $student = \Scholar::first(array("id = ?" => $e->scholar_id), array("user_id", "dob", "parent_id")); $parent = \StudentParent::first(array("id = ?" => $student->parent_id), array("name", "relation")); $usr = \User::first(array("id = ?" => $student->user_id)); $students[] = array("name" => $usr->name, "parent_name" => $parent->name, "parent_relation" => $parent->relation, "dob" => $student->dob, "username" => $usr->username); } $students = ArrayMethods::toObject($students); $view->set("students", $students); }
public function run() { Eloquent::unguard(); $user = User::first(); DB::table('tournaments')->truncate(); DB::table('players_tournaments')->truncate(); $tournament = new Tournament(array('user' => $user->id, 'name' => 'Tournois du 26 avril')); $tournament->save(); $tournament2 = new Tournament(array('user' => $user->id, 'name' => 'Tournois du 26 mai')); $tournament2->save(); $it = 0; foreach (Player::where('name', '<>', User::GHOST)->get() as $player) { $tournament->players()->attach($player->id); if ($it % 2 == 0) { $tournament2->players()->attach($player->id); } $it++; } }
public function myaccount() { $view = $this->getActionView(); $states = State::all(); $countries = Country::all(); $view->set('states', $states)->set('countries', $countries); if (RequestMethods::post('update')) { $user = User::first(array('id = ?' => $this->user->id)); $user->full_name = RequestMethods::post('full_name'); $user->country = RequestMethods::post('country'); $user->state = RequestMethods::post('state'); $user->pincode = RequestMethods::post('pin'); $user->address = RequestMethods::post('address'); if ($user->validate) { $user->save(); } else { echo "validation not good"; } } }