本文整理汇总了PHP中Sentinel::findById方法的典型用法代码示例。如果您正苦于以下问题:PHP Sentinel::findById方法的具体用法?PHP Sentinel::findById怎么用?PHP Sentinel::findById使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sentinel
的用法示例。
在下文中一共展示了Sentinel::findById方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: is_admin
/**
* extending hieu-le/active function
*
* @param int $user_id
*
* @return bool
*/
function is_admin($user_id = null)
{
if ($user_id) {
$user = Sentinel::findById($user_id);
} else {
if (Sentinel::check()) {
$user = Sentinel::getUser();
} else {
return false;
}
}
$admin = Sentinel::findRoleByName('Administrator');
return $user && $user->inRole($admin);
}
示例2: processReset
/**
* Handle posting of the form for the password reminder confirmation.
*
* @param int $id
* @param string $code
* @return \Illuminate\Http\RedirectResponse
*/
public function processReset($id, $code)
{
$rules = ['password' => 'required|confirmed'];
$validator = Validator::make(Input::get(), $rules);
if ($validator->fails()) {
return Redirect::back()->withInput()->withErrors($validator);
}
if (!($user = Sentinel::findById($id))) {
return Redirect::back()->withInput()->withErrors('The user no longer exists.');
}
try {
if (!Reminder::complete($user, $code, Input::get('password'))) {
return Redirect::route('user.login')->withErrors('Invalid or expired reset code.');
}
return Redirect::route('user.login')->withSuccess('Password was successfully resetted.');
} catch (NotUniquePasswordException $e) {
return Redirect::back()->withErrors($e->getMessage());
}
}
示例3: run
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
// ---------------------------------------------------------------------
// CONFERENCE 1
// ---------------------------------------------------------------------
$faker = Faker::create();
$user = Sentinel::findById(6);
$conference = Conference::find(1);
$countries = ['Canada', 'France', 'India', 'United States'];
$genders = ['female', 'male'];
for ($i = 0; $i < 100; ++$i) {
$profile = ['first_name' => $faker->firstName, 'last_name' => $faker->lastName, 'city' => $faker->city, 'country' => $countries[rand(0, 3)], 'birthdate' => $faker->date($format = 'Y-m-d', $max = 'now'), 'gender' => $genders[rand(0, 1)]];
$profile = new Profile($profile);
$profile->user()->associate($user);
$profile->save();
$profile->conferences()->attach($conference->id, ['birthdate' => $profile->birthdate, 'country' => $profile->country, 'gender' => $profile->gender, 'status' => 'approved']);
$conference->increment('attendee_count');
}
// ---------------------------------------------------------------------
// CONFERENCE 2
// ---------------------------------------------------------------------
$conference = Conference::find(2);
$event = $conference->events()->first();
$room = $conference->accommodations()->first()->rooms()->first();
$conferenceVehicle = $conference->vehicles()->first();
$eventVehicle = $event->vehicles()->first();
for ($i = 1; $i <= 7; ++$i) {
$profile = Profile::find($i);
$attendee = ['email' => $profile->email, 'phone' => $profile->phone, 'first_name' => $profile->first_name, 'middle_name' => $profile->middle_name, 'last_name' => $profile->last_name, 'city' => $profile->city, 'country' => $profile->country, 'birthdate' => $profile->birthdate, 'gender' => $profile->gender, 'accommodation_req' => true, 'accommodation_pref' => 1, 'arrv_ride_req' => true, 'arrv_date' => '2016-04-08', 'arrv_time' => '21:30', 'arrv_airport' => 'DEL', 'arrv_flight' => 'AC2273', 'dept_ride_req' => false, 'status' => 'approved'];
$profile->conferences()->attach($conference, $attendee);
$conference->increment('attendee_count');
$profile->events()->attach($event);
$profile->rooms()->attach($room);
$room->increment('guest_count');
$profile->conferenceVehicles()->attach($conferenceVehicle);
$conferenceVehicle->increment('passenger_count');
$profile->eventVehicles()->attach($eventVehicle);
$eventVehicle->increment('passenger_count');
}
}
示例4: login
/**
* process the login submit.
*
* @return Response
*/
public function login()
{
$potential_user = \Pinom\Models\User::where('email', 'LIKE', \Input::has('email') ? \Input::get('email') : '')->first();
if (!is_null($potential_user) && trim($potential_user->password) == '') {
//echo "isnull password!";
$user = \Sentinel::findById($potential_user->id);
$password = ['password' => $potential_user->id . '.' . $potential_user->email];
$user = \Sentinel::update($user, $password);
$activation = \Activation::create($user);
$activation = \Activation::complete($user, $activation->code);
}
$credentials = ['email' => \Input::has('email') ? \Input::get('email') : '', 'password' => \Input::has('passw') ? \Input::get('passw') : ''];
//echo '<pre>';
//return redirect('/');
$user = \Sentinel::authenticate($credentials);
//print_R($user);
if ($user = \Sentinel::check()) {
return redirect('/login');
} else {
return redirect('/login');
}
}
示例5: run
public function run()
{
/* move all groups to roles table */
$groups = DB::select('select * from groups');
foreach ($groups as $group) {
$id = $group->id;
$name = $group->name;
$slug = str_slug($name);
if ($group->id == '1') {
$permissions = array('admin' => 1);
} else {
$permissions = array();
}
Sentinel::getRoleRepository()->createModel()->create(['id' => $id, 'name' => $name, 'slug' => $slug, 'permissions' => $permissions]);
}
/* move users_groups data into role_users table */
$users_groups = DB::select('select * from users_groups');
foreach ($users_groups as $user_group) {
$user = Sentinel::findById($user_group->user_id);
$group = DB::table('groups')->where('id', '=', $user_group->group_id)->first();
$role_current = DB::table('roles')->where('name', '=', $group->name)->first();
$role = Sentinel::findRoleById($role_current->id);
$role->users()->attach($user);
}
$this->command->info('groups, users_groups successfully migrated to roles, role_users tables');
/* insert each user into activations table */
$users = DB::select('select * from users');
foreach ($users as $user) {
$current_user = Sentinel::findById($user->id);
$activation = Activation::create($current_user);
if ($user->activated) {
Activation::complete($current_user, $activation->code);
}
}
$this->command->info('activations created successfully');
}
示例6:
<?php
/**
* Created by PhpStorm.
* User: Dmitriy Pivovarov aka AngryDeer http://studioweb.pro
* Date: 29.12.15
* Time: 18:32
*/
?>
@if($activation = Activation::completed(Sentinel::findById($instance->id)))
@include('widgets.form._formitem_checkbox', ['name' => 'activated', 'title' => 'Активирован', 'checked' => true] )
@else
@include('widgets.form._formitem_checkbox', ['name' => 'activated', 'title' => 'Активирован'] )
@endif
<?php
$user = Sentinel::findById($instance->id);
?>
<label for="role">Роль пользователя</label>
<select name="role" id="role">
@foreach(Sentinel::getRoleRepository()->createModel()->all() as $role)
<option {{ $user->roles->contains($role->id) ? 'selected' : '' }} value="{{ $role->id }}">{{ $role->name }}</option>
@endforeach
</select>
<br><br>
示例7: update
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
// dd($request);
//get user u ant to update
$user = \Sentinel::findById($id);
//get the persons details
$staff = Staff::find($request->user);
$data = $request->except('_token');
$rules = ['password' => 'min:4|required'];
$validator = \Validator::make($data, $rules);
if ($validator->passes()) {
//array to hold final permission values
$array_of_permissions = Helper::prepPermissions($request->exempt_permission, 'false');
$credentials = ['email' => $staff->email, 'password' => $request->password, 'permissions' => $array_of_permissions, 'staff_id' => $staff->id, 'first_name' => $staff->fname, 'last_name' => $staff->lname];
//update user
$user = \Sentinel::update($user, $credentials);
//get the id(s) of the current roles of this user in an array
$current_roles = array();
foreach ($user->roles as $value) {
$current_roles[] = $value->id;
}
//compute role(s) to add
$add_roles = array_diff($request->assign_roles, $current_roles);
//compute role(s) to delete
$delete_roles = array_diff($current_roles, $request->assign_roles);
//update user role(s)
$user = \Sentinel::findById($user->id);
//add ne role(s)
foreach ($add_roles as $role_id) {
$role = \Sentinel::findRoleById($role_id);
$role->users()->attach($user);
}
//delete role(s), if any
foreach ($delete_roles as $role_id) {
\DB::table('role_users')->where('role_id', $role_id)->where('user_id', $user->id)->delete();
}
return \Redirect::to('settings/users/create');
} else {
return \Redirect::back()->withInput()->withErrors($validator);
}
}
示例8: trans
@extends('app')
@section('container')
<div class="center">
<h2>{{ trans('app.title') }}</h2>
</div>
<div class="blog">
<div class="row">
<div class="col-md-8">
<div class="blog-item">
<?php
$user1 = \Sentinel::findById($article->user_id);
?>
<img class="img-responsive img-blog" src="/images/blog/blog1.jpg" width="100%" alt="" />
<div class="row">
<div class="col-xs-12 col-sm-2 text-center">
<div class="entry-meta">
<span id="publish_date">{{ Carbon\Carbon::parse($article->published_at)->format('j M')}}</span>
<span><i class="fa fa-user"></i> {{ $user1->first_name }}</span>
</div>
</div>
<div class="col-xs-12 col-sm-10 blog-content">
<h2>{{ $article->title }}</h2>
{{ $article->body }}
<div class="post-tags">
<strong>Tag:</strong>
@unless ($article->tags->isEmpty())
<ul>
示例9: array
<?php
return array('view' => array('list' => function (array $row) {
}, 'form' => function (array $row) {
// empty if create form
return view('jarboe.c.users::patterns.user_password');
}), 'handle' => array('insert' => function ($idRow, $patternValue, $values) {
$password = trim($patternValue);
if (!$password) {
// FIXME: translations
throw new \Yaro\Jarboe\Exceptions\JarboeValidationException('Пароль обязательное поле');
}
$user = \Sentinel::findById($idRow);
\Sentinel::update($user, compact('password'));
}, 'update' => function ($idRow, $patternValue, $values) {
$password = trim($patternValue);
if (!$password) {
return;
}
$user = \Sentinel::findById($idRow);
\Sentinel::update($user, compact('password'));
}, 'delete' => function ($idRow) {
}));
示例10: fire
public function fire($job, $data)
{
$transaction_id = $data["transaction"];
Log::info("Queue Worker Fired");
Log::info("Transaction-ID: " . $transaction_id);
//Get the transaction from the db
$transaction = SDPaymentTransaction::find($transaction_id);
if (!$transaction) {
Log::warning("Could not load Transaction from Database");
exit;
}
if ($transaction->status != "confirmed") {
Log::error("Transaction" . $transaction->id . "not confirmed - aborting");
}
Log::info("Transaction loaded from DB");
Log::info("Transaction user_id: " . $transaction->user_id);
Log::info("Transaction payment provider: " . $transaction->payment_provider);
Log::info("Transaction Items: " . $transaction->items);
//Get the user from the DB
$user = Sentinel::findById($transaction->user_id);
if (!$user) {
Log::error("Could not find the user " . $transaction->user_id . " in the DB");
exit;
}
//Get the transaction items
$trans_items = json_decode($transaction->items);
if ($trans_items == false) {
Log::error("Invalid Item JSON at the Transaction " . $transaction->id);
exit;
}
//Get the User info from the DB
$user_infos = DB::table('sd_user_infos')->where('user_id', $user->id)->get();
if (!$user_infos) {
Log::error("Could not get the User Infos from the db for transaction: " . $transaction->id);
exit;
}
//Go through the items and assign them to the user
foreach ($trans_items as $trans_item) {
Log::info("Got Trans Item id:" . $trans_item->id);
Log::info("Got Trans Item count:" . $trans_item->count);
//Get the item info from the db
$item = SDItem::find($trans_item->id);
if (!$item) {
Log::error("Could not get SD Item with id " . $trans_item->id . " from the DB");
exit;
}
Log::info("Got SDItem: " . $item->id . " - " . $item->name_short);
//Get the handlers for the item and call them
$handlers = json_decode($item->handlers);
if ($handlers == false) {
Log::error("Invalid Handler JSON at Item: " . $item->id);
}
//Call the item multiple times according to the item count
for ($i = 1; $i == $trans_item->count; $i++) {
foreach ($handlers as $handler) {
Log::info("Got Handler Class: " . $handler->class);
$item_handler = new $handler->class();
$result = $item_handler->add_item($user, $user_infos, $handler->params);
if ($result == true) {
Log::info('Successfully executed ' . $handler->class . ' for ' . $transaction->id);
$sd_user_item = new SDUseritem();
$sd_user_item->user_id = $user->id;
$sd_user_item->item_id = $item->id;
$sd_user_item->save();
} else {
Log::error('Exection of ' . $handler->class . ' for ' . $transaction->id . ' failed');
}
}
}
}
//Update the transaciton
$transaction->status = "completed";
$transaction->save();
//Check for errors
$job->delete();
}
示例11: route
@extends('Centaur::layout')
@section('title', 'Selamat Datang')
@section('content')
@if (!Sentinel::check())
<div class="jumbotron text-center">
<h1>Selamat Datang</h1>
<p>Sila log masuk untuk teruskan.</p>
<p><a class="btn btn-primary btn-lg" href="{{ route('auth.login.form') }}" role="button">Log Masuk</a></p>
</div>
@else
<div class="jumbotron text-center">
<h1>Hello, {{ Sentinel::getUser()->email }}!</h1>
<p>You are now logged in.</p>
</div>
@endif
<?php
$user = Sentinel::findById(1);
// var_dump(Activation::create($user));
?>
@stop
示例12: theActivationHasExpired
/**
* @Given the activation has expired
*/
public function theActivationHasExpired()
{
Activation::remove(Sentinel::findById(1));
}
示例13: loginById
public function loginById($user_id)
{
$user = \Sentinel::findById($user_id);
return \Sentinel::login($user);
}
示例14: destroy
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
$user = Sentinel::findById($id);
$user->delete();
}
示例15: function
Route::group(['middleware' => ['authno']], function () {
Route::get('login', 'UserController@showLogin')->name('login');
Route::post('login', 'UserController@postLogin')->name('login.post');
Route::get('register', 'UserController@showRegister')->name('register');
Route::post('register', 'UserController@postRegister')->name('register.post');
});
# Admin User Section
Route::group(['middleware' => ['admin']], function () {
Route::get('admin/dashboard', 'AdminController@dashboard')->name('dashboard');
Route::post('showunits', 'AdminController@showUnits')->name('units.show');
Route::resource('product', 'ProductController');
// Route::get('admin/product', 'AdminController@productPage')->name('product');
// Route::post('admin/product', 'AdminController@addProduct')->name('product.post');
});
# Authenticated User Section
Route::group(['middleware' => ['auth']], function () {
Route::get('logout', 'UserController@logout')->name('logout');
Route::post('cart/drop', 'HomeController@cartDrop')->name('cart.drop');
Route::post('address', 'HomeController@addAddress')->name('address.add');
Route::group(['namespace' => 'user'], function () {
Route::resource('basket', 'BasketController');
Route::resource('order', 'OrderController');
});
});
Route::get('activate/{id}/{code}', function ($id, $code) {
$user = Sentinel::findById($id);
if (!Activation::complete($user, $code)) {
return Redirect()->to("login")->withErrors('Invalid or expired activation code.');
}
return Redirect()->to('login')->withSuccess('Account activated.');
});