It is possible to have a link in a flash message

I am working on checking if the user is active or not before logging in.

this is my current login code

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

        //Check if user  has surpassed their allowed login attempts
        //Keyed by the username and IP address of the client making
        //the request.
        if ($this->hasTooManyLoginAttempts($request)){
            $this->fireLockoutEvent($request);

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

        // Attempt the login of the user.
        $username = $request->get('username');
        $password = $request->get('password');
        $remember = $request->get('remember');


        if($this->auth->attempt([
            'username' => $username,
            'password' => $password,
            'activated' => 1
        ],$remember == 1 ? true : false)) {

            if($this->guard()->user()->activated){
                //Success: clear the login attempts session and redirect
                //user to the user dashboard.
                $request->session()->regenerate();
                $this->clearLoginAttempts($request);

                return redirect()->action('Front\PagesController@index');
            }else{
                //Not Activated redirect to login and kick them out
                $this->guard()->logout();
                $request->session()->flush();
                $request->session()->regenerate();

                return redirect('login')
                    ->with('activation_response', 'action.danger');
            }

        }
        else{
            //Fail: If login attempt was unsuccessful, increment the number of attempts
            //to login and redirect user back to login form, if user surpasses the maximum
            //number of attempts user will be locked out for a certain amount of time.
            $this->incrementLoginAttempts($request);

            return redirect()->back()
                ->with('message','Incorrect username or password')
                ->with('status','danger')
                ->withInput();
        }
    }

in the check, if the user is not active, I want to display a flash message informing them that the account is inactive, but I want to include a link to the reactivation page.

I also have this in my partials folder as activation_response.blade.php

<a href="{{ url('/activation/resend') }}" class="new-account">Resend activation code</a>

My attempt to do this does not work, is there a way I can do this?

I also have laracasts / flash package.

looking for some direction how to do this.

+4
source share
1 answer

Controller:

$errors = ['activation_response' => 'You are not an active user. ' . link_to(url('activation/resend'), 'Click here') . ' to resend activation code'];

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

View:

@if(session()->has('errors') && $errors->first('activation_response'))
    <div class="alert alert-danger" role="alert">
        {!!$errors->first('activation_response')!!}
    </div>
@endif

Be sure to wrap the HTML response in tags {!! !!}to render unrelated data.

0

Source: https://habr.com/ru/post/1680022/


All Articles