public function facebook() { if (Session::has('flash_notification.message')) { return view('auth.facebook'); } $config = config('services.facebook'); session_start(); FacebookSession::setDefaultApplication($config['id'], $config['secret']); $helper = new FacebookRedirectLoginHelper(route('facebook')); if (!Input::has('code')) { return redirect($helper->getLoginUrl(['email'])); } try { $session = $helper->getSessionFromRedirect(); $profile = (new FacebookRequest($session, 'GET', '/me'))->execute()->getGraphObject(GraphUser::className()); } catch (FacebookRequestException $e) { flash('Ne pare rău dar a apărut o eroare. <a href="' . route('facebook') . '">Încearcă din nou</a>.', 'danger'); return redirect()->route('facebook'); } if ($user = $this->userRepo->getByFacebook($profile->getId())) { return $this->loginUser($user); } if (empty($profile->getProperty('email'))) { flash('<p>Nu am putut citi adresa de email asociată contului tău de Facebook.</p> <p>Va trebui să te <a href="' . route('register') . '">înregistezi</a> pe site cu o adresă de email validă</p>', 'danger'); return redirect()->route('facebook'); } if ($this->userRepo->getByEmail($profile->getProperty('email'))) { flash('<p>Adresa de email asociată contului tău de Facebook este deja folosită pe site de altcineva.</p> <p>Va trebui să te <a href="' . route('register') . '">înregistezi</a> pe site cu o altă adresă de email.</p>', 'danger'); return redirect()->route('facebook'); } $user = User::create(['email' => $profile->getProperty('email'), 'first_name' => $profile->getFirstName(), 'last_name' => $profile->getLastName(), 'avatar' => $this->getFacebookPictureUrl($session), 'role_id' => config('auth.default_role_id'), 'confirmed' => 1, 'county_id' => 20]); $user->setMeta('facebook', $profile->getId()); $user->save(); return $this->loginUser($user); }
public function run() { DB::table('users')->truncate(); $users = [['email' => '*****@*****.**', 'password' => 'eusebiu', 'confirmed' => 1, 'first_name' => 'Cretu', 'last_name' => 'Eusebiu', 'avatar' => 'https://graph.facebook.com/480215022112954/picture?width=200&height=200', 'role_id' => 1], ['email' => '*****@*****.**', 'password' => 'robert', 'confirmed' => 1, 'first_name' => 'Pamfile', 'last_name' => 'Robert', 'avatar' => 'https://graph.facebook.com/100000534791864/picture?width=200&height=200', 'role_id' => 1]]; foreach ($users as $user) { $user = User::create($user); } }
public function update($_, $groupId, $id) { $primary = Input::has('primary') ? 1 : 0; $order = (int) Input::get('display_order'); if ($user = User::find($id)) { $this->updateTrainer($groupId, $id, ['is_primary' => $primary, 'display_order' => $order]); } return json(1); }
/** * Create a new user. * * @return Response */ public function store() { $input = Input::only('email', 'password', 'first_name', 'last_name', 'county_id', 'g-recaptcha-response'); $this->registrationForm->validate($input); $user = User::create(['email' => $input['email'], 'password' => $input['password'], 'first_name' => $input['first_name'], 'last_name' => $input['last_name'], 'role_id' => config('auth.default_role_id'), 'county_id' => 20]); $user->regenerateConfirmationToken(); $this->mailer->sendConfirmationLink($user); flash(true); return json(true); }
public function showUser($group, $userId) { $user = User::findOrFail($userId); $query = Response::join('quiz', 'quiz.id', '=', 'quiz_id')->where('user_id', $user->id)->where('area_id', $group->area_id); if ($group->category_id) { $query->where('category_id', $group->category_id); } if (!($response = $query->first(['response.id']))) { return abort(404); } return view('admin.members.user', compact('user', 'response', 'group')); }
public function store($_, $groupId) { $group = Group::findOrFail($groupId); $userId = Input::get('user_id'); if (!($user = User::find($userId))) { return back(); } if ($group->users()->count('id') >= (int) $group->available) { flash('Nu mai poți adăuga utilizatori în aceasă grupă (nu mai sunt locuri).', 'danger'); } elseif (!in_array($user->id, $group->users()->lists('id'))) { $group->users()->attach($user->id); $this->query($userId, $groupId)->update(['confirmed' => 1]); flash("<b>{$user->full_name}</b> a fost adăugat cu success."); } return back(); }
/** * Run the database seeds. * * @return void */ public function run() { Eloquent::unguard(); UserMeta::where('key', 'area-email-notification')->update(['key' => 'notifications']); $users = User::all(); foreach ($users as $user) { $user->full_name = $user->present()->fullName; $user->phone = $user->getMeta('phone'); $user->school = $user->getMeta('school'); $user->setMeta('notifications', ['area', 'comment']); $user->deleteMeta('county_id'); $user->deleteMeta('phone'); $user->deleteMeta('school'); $user->deleteMeta('comment-email-notification'); $user->save(); } //UserMeta::where('key', 'comment-email-notification')->update(['key' => 'comment-notification']); }
/** * @return Response */ public function api() { $data = []; $groups = User::find($this->userId, ['id'])->trainerGroups()->get(['area_id', 'category_id', 'name']); foreach ($groups as $group) { $key = $group->area_id . ($group->category_id ? '_' . $group->category_id : ''); if (isset($data[$key])) { continue; } $area = Area::findOrFail($group->area_id, ['id', 'name']); $category = null; $query = Response::join('quiz', 'response.quiz_id', '=', 'quiz.id')->join('users', 'response.user_id', '=', 'users.id'); if ($group->category_id) { $category = Category::findOrFail($group->category_id, ['id', 'name']); $query->where('category_id', $category->id); } else { $query->where('area_id', $area->id); } $applicants = $query->get(['response.id', 'response.created_at', 'full_name', 'email', 'school']); foreach ($applicants as $key => $applicant) { $applicants[$key]->id = (int) $applicant->id; $response = Response::findOrFail($applicant->id); $choices = $applicant->trainerchoices()->lists('choice', 'trainer_id'); $choice = isset($choices[$this->userId]) ? (int) $choices[$this->userId] : null; if ($choice !== 1 && !is_null($choice)) { $applicants->forget($key); continue; } $responses = []; foreach ($response->questions as $rquestion) { if (!$rquestion->question) { continue; } $answers = []; $roptions = $rquestion->options->lists('response', 'quiz_question_option_id'); foreach ($rquestion->question->options as $option) { if (array_key_exists($option->id, $roptions)) { if ($rquestion->question->type == 'text' || $rquestion->question->type == 'textbox') { $answer = html_entity_decode($roptions[$option->id]); } else { $answer = true; } } else { $answer = false; } $answers[] = ['option' => $option->option ? html_entity_decode($option->option) : null, 'answer' => $answer]; } $responses[] = ['question' => $rquestion->question->question, 'question_type' => $rquestion->question->type, 'answers' => $answers]; } $applicant->responses = $responses; } $applicants->values(); $data[$key] = ['applicants' => $applicants, 'area' => $area, 'category' => $category]; } return json(array_values($data), 200); }
public function addTrainer($_, $id) { $group = Group::findOrFail($id); $userId = Input::get('user_id'); if (!($user = User::find($userId))) { return back(); } if ((int) $user->role->id === $this->trainerRoleId) { if (!in_array($user->id, $group->trainers->lists('id'))) { $group->trainers()->attach($user->id); flash("Trainerul <b>{$user->present()->fullName}</b> a fost adăugat."); } } return back(); }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { $role = Role::findOrFail($id); $role->delete(); if (Input::has('assign_role')) { $id = Input::get('role_id'); if (Role::find($id)) { User::where('role_id', $role->id)->update(['role_id' => $id]); } } flash("Rolul <b>{$role->name}</b> a fost șters.", 'warning'); return back(); }
/** * Register user observer. * * @return void */ protected static function boot() { parent::boot(); User::observe(new UserObserver()); }
/** * Execute the console command. * * @return mixed */ public function fire() { $listName = $this->argument('list'); $tid = config('auth.trainer_role_id'); $users = User::where('county_id', 20)->get(); foreach ($users as $user) { if (!$user->responses()->count() && (int) $user->role_id !== $tid) { echo $user->email . "\n"; try { $this->list->subscribeTo($listName, $user->email); } catch (\Mailchimp_ValidationError $e) { echo $e->getMessage(); } } } // $emails = []; // $failed = []; // foreach (Response::all() as $respoonse) // { // $email = $respoonse->user->email; // if (in_array($email, $emails)) continue; // if ( ! $respoonse->user->groups()->count('id')) // { // $emails[] = $email; // echo $email . "\n"; // try // { // $this->list->subscribeTo($listName, $email); // } // catch (\Mailchimp_ValidationError $e) // { // echo $e->getMessage(); // $failed[] = $email; // } // } // } // echo count($emails)." users added.\n".count($failed)." failed."; // $list = $this->list->getList(); // $listId = $this->list->getListId($listName); // //print_r( $list->interestGroupings($listId) ); // //exit; // $options = [ // 'list_id' => $listId, // 'subject' => 'Test campaign', // 'from_name' => 'FII Practic', // 'from_email' => '*****@*****.**', // 'to_name' => 'Utilizator FII Practic' // ]; // $content = [ // 'html' => 'This is a test campaign', // 'text' => 'This is a test campaign' // ]; // $segmentOpts = [ // 'match'=>'all', // 'conditions' => [ // [ // 'field' => 'interests-2113', // 'op' => 'one', // 'value' => 'GrupaA' // ] // ] // ]; //$mailchimp = new \Mailchimp; //$campaign = $mailchimp->campaigns->create('regular', $options, $content, $segmentOpts); // $mailchimp->campaigns->send($campaign['id']); // $this->list->getList()->interestGroupingAdd($listId, 'Test group', 'checkboxes', ['GrupaA', 'GroupB']); // $this->list->subscribeTo($listName, '*****@*****.**', [ // 'groupings' => [ // 'name' => 'Test group', // 'groups' => ['GrupaA'], // ] // ]); }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { with(User::findOrFail($id))->delete(); return json(1); }