/** * Turn this item object into a generic array * * @return array */ public function transform(User $user) { $def = ['id' => $user->id, 'first_name' => $user->first_name, 'last_name' => $user->last_name, 'username' => $user->username, 'email' => $user->email, 'gravatar' => $user->present()->gravatar(50), 'last_message_read' => $user->meta->last_message_read, 'last_notification_read' => $user->getMeta()->last_notification_read]; // TODO: move to an include if ($user->skills) { foreach ($user->skills as $skill) { $def['skills'][] = ['id' => $skill->id, 'name' => $skill->name, 'description' => $skill->pivot->description, 'level' => $skill->pivot->level]; } } return $def; }
/** * Create Agent * @return \Illuminate\Http\JsonResponse */ public function create() { $success = false; if ($this->validator->validate(\Input::all()) && $this->userValidator->validate(['email' => \Input::get('email'), 'password' => \Str::random(8)])) { $user = User::create(['email' => \Input::get('email'), 'username' => \Input::get('name'), 'password' => \Str::random(8)]); $agentData = \Input::all(); $agentData['user_id'] = $user->id; // TODO: save uploaded image :| // Destination path for uplaoded files which is at /public/uploads $destinationPath = public_path() . '/uploads/img/'; // Handle profile Picture if (Input::hasFile('profile_pic_filename')) { $file = Input::file('profile_pic_filename'); $propic_filename = str_random(6) . '_' . str_replace(' ', '_', $file->getClientOriginalName()); $uploadSuccess = $file->move($destinationPath, $propic_filename); if ($uploadSuccess) { $agentData['profile_pic_filename'] = $propic_filename; } } $agent = Agent::create($agentData); // Send Invitation Email $invitation_code = bin2hex(openssl_random_pseudo_bytes(16)); $invite = Invite::create(['code' => $invitation_code, 'email' => Input::get('email'), 'user_id' => $user->id, 'user_type' => 'Agent']); Mail::send('emails.invitation.invite', ['confirmation' => $invitation_code, 'client_base_url' => 'http://d.motibu-head.com/'], function ($message) { $message->to(Input::get('email'))->subject('You have been invited to motibu.com'); }); $user->roles()->attach(Role::findByName('Agent')->id); $success = $user && $agent; } return \Response::json(['success' => $success, 'data' => $agent->getTransformed(new AgentTransformer())]); }
private function createUserWithRoles() { if ($this->user) { return $this->user; } $user = User::create(['username' => 'testUser', 'email' => '*****@*****.**', 'password' => 'password']); with(new RolesTableSeeder())->run(); $user->roles()->attach(Role::lists('id')); $this->user = $user; return $user; }
public function showWelcome() { Auth::login(User::find(1)); dd(Auth::user()->hasMtmRole(Role::findByName('Agency Admin'))); dd(Agency::findByName('Dietrich, Koelpin and Weissnat')); $model = Agency::first(); echo $model->hasMtmUser(User::find(1), 'admins'); // dd($this->get_class()); // dd($this->getActionPermissions(get_class($this))); // return View::make('hello'); }
public function run() { // users 11 to 20 are candidates $faker = Faker::create(); $users = User::all(); foreach (range(11, 20) as $userId) { foreach (range(1, 5) as $index) { // number of skills/jobs \DB::table('candidate_to_job')->insert(['user_id' => $userId, 'job_id' => $faker->numberBetween(1, 50)]); $users[$userId - 1]->skills()->attach([$faker->numberBetween(1, 6000) => ['description' => $faker->paragraph(), 'level' => $faker->numberBetween(1, 100)]]); } } }
public function claim() { Log::info('Inside Claim'); Log::info(Input::all()); $code = trim(Input::get('code')); $user_type = trim(Input::get('user_type')); $password = trim(Input::get('password')); $confirm_password = trim(Input::get('confirm_password')); $invite = Invite::where('code', '=', trim($code))->where('user_type', '=', $user_type)->where('claimed_at', '=', null)->first(); if ($invite && $password == $confirm_password) { $user = User::find($invite->user_id); $user->password = $password; $user->confirmed = 1; $user->save(); $this->respondWithArray(['success' => true, 'message' => 'Password Updated successfully. You can now login.']); } else { $this->respondWithArray(['success' => false, 'message' => 'Please make sure you clicked on the correct link and you put two identical password.']); } }
public function run() { $faker = Faker::create(); $candidates = Candidate::lists('id'); User::create(['username' => "demoguy", 'first_name' => "demo", 'last_name' => "guy", 'email' => "*****@*****.**", 'password' => 'secret', 'confirmed' => 1, 'userable_type' => 'Motibu\\Models\\Candidate', 'userable_id' => 1]); foreach (range(2, 10) as $index) { User::create(['username' => $faker->userName(), 'first_name' => $faker->firstName, 'last_name' => $faker->lastName, 'email' => $faker->email(), 'password' => 'secret', 'confirmed' => 1, 'userable_type' => 'Motibu\\Models\\Candidate', 'userable_id' => $faker->randomElement($candidates)]); } $users = User::all(); foreach (range(1, 10) as $index) { $users[$index - 1]->agencies()->attach($index); $users[$index - 1]->roles()->attach(4); // agency admin } $locations = [['location' => "Piarco International Airport (POS), Golden Grove Road, Piarco, Trinidad and Tobago", 'latitude' => 10.5976964, 'longitude' => -61.339527], ['location' => "Pos, Jalan Semeru Selatan, Dampit, Malang 65181, Republic of Indonesia", 'latitude' => -8.2109083, 'longitude' => 112.7520661], ['location' => "Pos, Jalan W. Monginsidi, Kendari, Kota Kendari 93127, Republic of Indonesia", 'latitude' => -3.970164, 'longitude' => 122.588356], ['location' => "Pos, Jalan Raya Sumorame, Candi, Kabupaten Sidoarjo 61271, Republic of Indonesia", 'latitude' => -7.4936845, 'longitude' => 112.7057069], ['location' => "New Delhi, Delhi, India", 'latitude' => 28.6139391, 'longitude' => 77.2090212], ['location' => "Delhi, Haixi, Qinghai, China", 'latitude' => 37.369436, 'longitude' => 97.360985], ['location' => "Delhi, NY 13753, USA", 'latitude' => 42.27814009999999, 'longitude' => -74.91599459999999]]; // create candidates foreach (range(1, 10) as $index) { $randLoc = $faker->randomElement($locations); $user = User::create(['username' => $faker->userName(), 'first_name' => $faker->firstName, 'last_name' => $faker->lastName, 'email' => $index == 1 ? "*****@*****.**" : $faker->email(), 'password' => 'secret', 'confirmed' => 1]); $user->roles()->attach(3); // candidate Candidate::create(['user_id' => 10 + $index, 'residency' => $faker->city . ', ' . $faker->state . ' ' . $faker->country, 'telephone' => '5553882838', 'about' => $faker->paragraph(), 'location_name' => $randLoc['location'], 'location_latitude' => $randLoc['latitude'] * 1000, 'location_longitude' => $randLoc['longitude'] * 1000]); } // create agents foreach (range(1, 10) as $index) { foreach (range(1, 2) as $bleh) { $user = User::create(['username' => $faker->userName(), 'first_name' => $faker->firstName, 'last_name' => $faker->lastName, 'email' => $faker->email(), 'password' => 'secret', 'confirmed' => 1]); $user->roles()->attach(5); // agent Agent::create(['user_id' => $user->id, 'telephone' => '5553882838', 'agency_id' => $index, 'name' => $user->first_name . ' ' . $user->last_name]); // \DB::table('agent_to_job')->insert( [ // 'user_id' => $user->id, // 'job_id' => $faker->numberBetween(1, 50) // ]); } } // Create a Super Admin $super = User::create(['username' => "demosuper", 'first_name' => "demo", 'last_name' => "guy", 'email' => "*****@*****.**", 'password' => 'secret', 'confirmed' => 1, 'userable_type' => 'Motibu\\Models\\Candidate', 'userable_id' => 1]); $super->roles()->attach(1); Plan::create(['title' => 'Basic', 'description' => 'Monthly Basic Plan', 'duration' => '30', 'cost_in_cents' => 2000, 'meta' => '{"can_contact_candidates": "true", "number_of_jobs_per_month": "5"}']); }
/** * List Jobs * @return \Illuminate\Http\JsonResponse */ public function jobs($candidateId) { $candidate = Candidate::findOrFail($candidateId); $user = User::find($candidate->user_id); $jobs = $user->jobsAppliedTo()->with('skills')->paginate(); return $this->respondWithCollection($jobs, new JobTransformer(), ['skills']); }
public function register_agency() { $success = false; $user = Input::only('email', 'password', 'confirm_password', 'first_name', 'last_name'); $user['username'] = $user['email']; // $user['confirmation_code'] = $confirmation_code = str_random(30); Log::info(print_r($user, true)); try { if ($this->userValidator->validate($user)) { $newUser = User::create($user); $success = $newUser == true; $newUser->roles()->attach(Role::findByName('Agency Admin')->id); $agency['name'] = Input::get('agency_name'); $agency['description'] = 'new agency'; // try { if ($this->agencyValidator->validate($agency)) { Log::info($agency); $newAgency = Agency::create($agency); $newAgency->admins()->attach($newUser->id); } // } catch (FormValidationException $e) { // Log::info(print_r($e->getErrors())); // return \Response::json(['success' => false, 'error' => $e->getErrors()]); // } } } catch (FormValidationException $e) { return \Response::json(['success' => false, 'errors' => $e->getErrors(), 400]); } Log::info(print_r($user, true)); if ($success) { $newUser->confirmation_code = Hash::make($newUser->id . str_random(30)); $newUser->save(); Mail::send('emails.registration.confirmation', ['confirmation' => base64_encode($newUser->confirmation_code) . '?next_step=3&user_id=' . $newUser->id, 'client_base_url' => Input::get('client_base_url')], function ($message) { $message->to(Input::get('email'))->subject('Verify your email address'); }); } return \Response::json(['success' => $success]); }