canihelpyou

662 经验值

本站中文字体是什么字体?字体文件大吗?

第一次配置使用。有几个基本问题不清楚,麻烦帮解释一下:
如果有sendmail,sendcloud起的作用是什么,sendCLOUD 做发送模板是什么意思?只用sendmail不能完成发送模板吗?

默认是这样的:

MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null

视频中sendcloud那一节讲的示例,要添加这两项:

SENDCLOUD_API_USER=
SENDCLOUD_API_KEY=

可是,如果使用SENDCLOUD,那上面MAIL_DRIVER怎么填写呢?

以前的视频没讲用redis存储队列,能否讲一下?

如果更完整一点就更好了:
用redis队列存储和发送注册激活邮件(邮件服务使用sendcloud)。laravel干点啥经常都层层转包,多转包几次就不知道到哪里去了。

https://laravel.com/docs/5.3/queues#introduction

Other Driver Prerequisites

The following dependencies are needed for the listed queue drivers:

Amazon SQS: aws/aws-sdk-php ~3.0
Beanstalkd: pda/pheanstalk ~3.0
Redis: predis/predis ~1.0

由于laravel 5.3自带的auth没有邮件激活的机制,需要增加邮件激活,所以对它进行了一点改写:

laravel 5.3自带的auth的login方法原本是这样的:

    public function login(Request $request)
    {
        $this->validateLogin($request);

        // If the class is using the ThrottlesLogins trait, we can automatically throttle
        // the login attempts for this application. We'll key this by the username and
        // the IP address of the client making these requests into this application.
        if ($this->hasTooManyLoginAttempts($request)) {
            $this->fireLockoutEvent($request);

            return $this->sendLockoutResponse($request);
        }

        $credentials = $this->credentials($request);

       //问题是关于这个if判断。
        if ($this->guard()->attempt($credentials, $request->has('remember'))) {
            return $this->sendLoginResponse($request);
        }

        // If the login attempt was unsuccessful we will increment the number of attempts
        // to login and redirect the user back to the login form. Of course, when this
        // user surpasses their maximum number of attempts they will get locked out.
        $this->incrementLoginAttempts($request);

        return $this->sendFailedLoginResponse($request);
    }

问题在上面if()判断那里。

改写描述:
在user表中用is_confirmed字段来表示帐号是否激活,0代表未激活,1代表已激活,激活才能登陆。

如果帐号没激活,在视图中单独显示帐号没有激活,而不是笼统的显示帐号或密码不对,或帐号没激活,所以把原本的代码改成了这样:(只改了if语句那里)

if($this->guard()->attempt($credentials)){

            if ($this->guard()->attempt(array_merge($credentials,['is_confirmed'=>1]), $request->has('remember'))) {

                return $this->sendLoginResponse($request);

            }elseif($this->guard()->attempt(array_merge($credentials,['is_confirmed'=>0]), $request->has('remember'))){
                
                \Session::flash('email_not_confirmed','帐号没有激活,无法登录,请先去您的邮箱激活帐号');

                return back()->withInput($request->only($this->username(), 'remember'));
            }
        }

问题:
感觉我的代码逻辑有点重复,有其他更优化的写法吗?

Auth::guard()的意思是什么?不太明白。

protected function guard()
    {
        return Auth::guard();
    }

使用laravel5.3和自带的auth,用户注册时怎么发送邮件?

本站视频有两节相关的视频,视频中是自己写的用户注册登录代码,如果使用laravel自带的auth,应该怎么做?看了视频但头绪有点乱。(备注:发送邮件使用sendcloud)