我是 Cartalyst Sentinel 和 ACL 概念的新手。我设法创建了一个用户,执行激活和登录和注销。
我想把我的学习提升到一个新的水平。我想在这个 laravel 应用程序上有 2 种类型的用户。1 是管理员另一个是订阅者。我假设我的帐户创建方法应该默认为用户创建订阅者。
public function postCreate() {
/* Validation */
$validation = Validator::make(Input::all(), [
'email' => 'required|email|max:50|unique:users',
'username' => 'required|min:3|max:20|unique:users',
'password' => 'required|min:6',
'password_repeat' => 'required|same:password',
]);
if ($validation->fails()) {
return Redirect('login')->withErrors($validation)->withInput();
} else {
$credentials = Input::all();
$user = Sentinel::register($credentials);
$activation = Activation::create($user);
$activation_code = $activation->code;
if ($user) {
Mail::send('emails.auth.activate', ['link' => URL::route('account-activate', [$user->id, $activation_code]), 'username' => $user->username], function($message) use ($user) {
$message->to($user->email, $user->username)->subject('Activate your account');
});
return Redirect::route('home')->with('global', 'Thank you for registering! We have sent you an email to activate your account');
}
}
}
我是否像这样更改代码
$user = Sentinel::register($credentials);
$user = Sentinel::findById(1);
$role = Sentinel::findRoleByName('Subscribers');
$role->users()->attach($user);
问题是我什至还没有创建任何角色。我们在哪里编写该功能?现在我有以下控制器
- AccountController - 处理激活
- AuthController - 处理登录/注销
- RegistrationController - 处理用户注册
- RolesController - 我还没有在这里写任何东西。我有点失落。
请指导我。任何帮助是极大的赞赏。