필자는 laravel4 응용 프로그램에 Personcontroller와 Festivalcontroller가 있습니다. 이러한 컨트롤러의 작업은 관리자 만 액세스 할 수 있습니다.Searry 2 in Laravel 4 사용 방법
데이터베이스가 [email protected] 인 사용자 만있는 경우 해당 사용자는 해당 2 명의 컨트롤러의 경로에 액세스 할 수 있습니다. 내 데이터베이스에 [email protected]이없는 사용자가 있지만 다른 사용자가있는 경우 다른 사용자는 해당 두 컨트롤러의 경로에 액세스 할 수 없습니다. 그리고 내 데이터베이스에 [email protected]이있는 사용자가 있고 다른 사용자가 있으면 모든 사람이이 두 컨트롤러의 경로에 액세스 할 수 있습니다.
전자 메일 [email protected] 만 있으면 해당 컨트롤러의 경로에 액세스 할 수 있습니다.
내가이 수행하여 Sentry2 설치 : composer.json 파일에서이 필요합니다 응용 프로그램에서
"cartalyst/sentry": "2.0.*"
실행
php composer.phar update
> 설정> app.php :
'Cartalyst\Sentry\SentryServiceProvider',
=> 공급자 배열
'Sentry' => 'Cartalyst\Sentry\Facades\Laravel\Sentry',
=> 나는 SentrySeeder 파일을 만들어 설치 한 후 별칭 배열
에 :
public function login()
{
$input = Input::all();
$rules = array(
'user_email' => 'required',
'user_password' => 'required'
);
$validator = Validator::make($input, $rules);
if ($validator->fails()) {
return Redirect::to('login')
->withErrors($validator) // send back all errors to the login form
->withInput(Input::except('user_password'));
}
else {
$attempt = Auth::attempt([
'user_email' => $input['user_email'],
'password' => $input['user_password']
]);
if ($attempt) {
return Redirect::to('/home');
}
else {
return Redirect::to('login');
}
}
을 인 LoginController
내 PersonController
class PersonController extends BaseController {
public function index()
{
try
{
$user = Sentry::findUserByLogin('[email protected]');
if ($user)
{
$person = Person::with('user')->orderBy('person_id')->paginate(10);
return View::make('persons.index')
->with('person', $person);
}
}
catch (Cartalyst\Sentry\Users\UserNotFoundException $e)
{
echo 'User was not found.';
}
}
}
로그인 액션에서
<?php
class SentrySeeder extends Seeder {
public function run()
{
DB::table('users')->delete();
DB::table('groups')->delete();
DB::table('users_groups')->delete();
Sentry::getUserProvider()->create(array(
'email' => '[email protected]',
'password' => "test",
'activated' => 1,
));
$user = Sentry::getUserProvider()->findByLogin('[email protected]');
$adminGroup = Sentry::getGroupProvider()->findByName('Test');
$user->addGroup($adminGroup);
}
}
을
스토 데이터베이스의 사용자
을 변경 :
편집 당신은 보통 '이메일'과 '암호'열을 사용하지 않는 것처럼
, 센트리의 구성을 게시 [email protected] 사용자가 생성되지 않았습니다. 특정 사용자를 어떻게 찾을 수 있습니까? –
글쎄, 기존의 Sentry를 [email protected] 이메일과 패스워드 테스트로 바꿨지 만, 그건 작동하지 않았다. 나는 Sentry2를 사용하는 법을 배우는 중이다. Sentry2를 설치 한 후 기존 데이터베이스가 있었는데 데이터베이스에서 아무 것도 변경하지 않았습니다. 테이블이나 다른 것을 추가해야합니까? – Gilko
데이터베이스를 점검하여 [email protected]이있는 계정이 있는지 확인 했습니까? –