是否可以由管理员在没有密码的情况下从管理面板创建用户?我想按照程序进行:
发布于 2014-07-22 11:09:53
我不这样认为。这就是为什么当我创建我的用户时,我会生成一个随机密码。
$user->password = str_shuffle("Random_Password");//生成随机初始密码
发布于 2014-07-22 11:54:21
我以前也是这样做的:破解了Laravel的“被遗忘的密码”功能(而不是重新发明轮子)。我说不出这件事是否适合斯泰特,但在普通的老拉勒维尔身上做这件事实在是微不足道:
您还可能希望延长已忘记密码的超时时间,或者,正如我所知道的(我知道),当用户处于忘记密码功能的/user/confirm版本时,在传递到Laravel的auth系统进行检查之前,只需刷新表中的超时即可。
我们的代码如下所示:
在登记册上:
// however you register the user:
$user = new User;
$user->email = Input::get('email');
$user->password = '';
$user->save();
// create a reminder entry for the user
$reminderRepo = App::make('auth.reminder.repository');
$reminderRepo->create($user);
Mail::send(
'emails.registered',
[
'token' => $reminder->token,
],
function ($message) use ($user) {
$message->to($user->email)->setSubject(Lang::get('account.email.registered.subject', ['name' => $user->name]));
}
);现在确认链接:
class AccountController extends Controller
{
public function confirm($token)
{
$reminder = DB::table('password_reminders')->whereToken($token)->first();
if (! $reminder) {
App::abort(404);
}
// reset reminder date to now to keep it fresh
DB::table('password_reminders')->whereToken($token)->update(['created_at' => Carbon\Carbon::now()]);
// send token to view but also email so they don't have to type it in (with password reminders it's is a good thing to make users type it, but with confirm account it feels weird)
return View::make('account.confirm-account')->withToken($token)->withEmail($reminder->email);
}
public function postConfirm($token)
{
$credentials = Input::only('email', 'password', 'password_confirmation', 'token');
$response = Password::reset($credentials, function ($user, $password) {
$user->password = $password;
$user->save();
});
switch ($response) {
case Password::INVALID_PASSWORD:
case Password::INVALID_TOKEN:
case Password::INVALID_USER:
return Redirect::back()->withInput()->with('message-error', Lang::get($response));
case Password::PASSWORD_RESET:
Auth::login(User::whereEmail(Input::get('email'))->first());
return Redirect::route('account.home')->with('message-info', Lang::get('messages.confirm_account.succeeded'));
}
}https://stackoverflow.com/questions/24885645
复制相似问题