首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Cartalyst Sentry和注册用户

Cartalyst Sentry和注册用户
EN

Stack Overflow用户
提问于 2014-07-22 11:04:23
回答 2查看 534关注 0票数 0

是否可以由管理员在没有密码的情况下从管理面板创建用户?我想按照程序进行:

  • 管理员创建没有密码的用户
  • 用户收到带有输入密码和激活帐户指示的电子邮件。
  • 用户可以通过电子邮件和密码注册。
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-07-22 11:09:53

我不这样认为。这就是为什么当我创建我的用户时,我会生成一个随机密码。

$user->password = str_shuffle("Random_Password");//生成随机初始密码

票数 1
EN

Stack Overflow用户

发布于 2014-07-22 11:54:21

我以前也是这样做的:破解了Laravel的“被遗忘的密码”功能(而不是重新发明轮子)。我说不出这件事是否适合斯泰特,但在普通的老拉勒维尔身上做这件事实在是微不足道:

  1. 用空白密码创建用户
  2. 在密码提醒表中添加一个条目(手动,不要使用Auth::to或其他任何内容,因为它将发送电子邮件,但请使用类的代码生成令牌)
  3. 向用户发送欢迎电子邮件,链接到/ user / == (或者其他什么,重点是它不需要被/user/遗忘-密码),如果你想确保只有未经确认的人才能访问该页面(这并不是真正重要的),就用普通的方式连接忘记密码,并添加$user->password‘的检查。

您还可能希望延长已忘记密码的超时时间,或者,正如我所知道的(我知道),当用户处于忘记密码功能的/user/confirm版本时,在传递到Laravel的auth系统进行检查之前,只需刷新表中的超时即可。

我们的代码如下所示:

在登记册上:

代码语言:javascript
复制
// 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]));
    }
);

现在确认链接:

代码语言:javascript
复制
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'));
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24885645

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档