Im running in laravel 5.2.* and I'm exploring the captcha validation in my new website. I saw a package in github naming mewebstudio/captcha. I followed his instruction for installation and testing if the image is working, it comes out fine but when im implementing it in my login page, I got little confused where should i declare the validation.
I inputted the login credentials and I tried to not input the correct answer in the captcha box and surprisingly, i got in to the home page which should be not. Do you guys have any solutions for this? thanks.
P.S. Sorry for my english
Form:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>LOGIN</title>
<meta name="msapplication-TileColor" content="#da532c">
<meta name="msapplication-TileImage" content="/mstile-144x144.png">
<meta name="theme-color" content="#ffffff">
</head>
<body>
<div id="wrap">
<div class="container-fluid">
<div class="row">
<div class="col-xs-12 col-sm-10 col-md-4 col-xs-offset-0 col-sm-offset-1 col-md-offset-4">
<div class="main-content-login">
<div class="panel panel-fos" style="margin-top: 100px;">
<div class="panel-heading">
<h3> LOG IN</h3>
</div>
<div class="panel-body">
#if (count($errors) > 0)
<div class="alert alert-danger">
<strong>Whoops!</strong> There were some problems with your input.<br><br>
<ul style="text-align: left;">
#foreach ($errors->all() as $error)
<li>{{ $error }}</li>
#endforeach
</ul>
</div>
#endif
<form id="emailForm" role="form" method="POST" action="{{ url('/auth/login') }}">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<div class="form-group">
<!--<div class="row">
<div class="col-sm-4 col-lg-3">
<label>Username:</label>
</div>
<div class="col-sm-8 col-lg-9">
<input type="password" name="password" class="form-control login" id="password">
</div>
</div>-->
<div class="input-group">
<span class="input-group-addon glyphicon glyphicon-user"></span>
<input type="email" id="email" name="email" class="form-control" aria-describedby="inputGroupSuccess3Status" placeholder="Email Address">
</div>
</div>
<div class="form-group">
<div class="input-group">
<span class="input-group-addon glyphicon glyphicon-lock"></span>
<input type="password" class="form-control" id="password" name="password" aria-describedby="inputGroupSuccess3Status" placeholder="Password">
</div>
</div>
<div class="form-group">
<div class="input-group">
{!! captcha_img() !!}
<input type="text" name="captcha" id="captcha">
</div>
</div>
<div class="row" style="margin-top: 30px;">
<div class="col-xs-12 col-sm-6">
<input type="submit" class="btn btn-md btn-primary btn-move-right login-btn" value="Log In"> </button>
</div>
<div class="col-xs-12 col-sm-6 checkbox remember" style="margin-top: 0;">
<label class="remember"><input type="checkbox"> Remember me</label>
</div>
</div>
<div class="row">
<div class="col-xs-12">
Forgot Password?
</div>
</div>
{{--<div class="row" style="margin-top: 30px;">
<div class="col-xs-7 col-lg-7">
<input type="submit" class="btn btn-md btn-primary btn-move-right" value="Log In"> </input> <span class="login"><a href="#" > Forgot Password?</a></span>
</div>
<div class="col-xs-5 col-lg-5 checkbox text-right" style="margin-top: 0;">
<label class="remember"><input type="checkbox" name="remember" value="{{old('remember')}}"> Remember me</label>
</div>
</div>--}}
</form>
</div>
</div>
<p class="text-center">An INF-SRD Project. All Rights Reserved 2015.</p>
</div>
</div>
</div>
</div>
</div>
<!--END OF WRAPPER-->
<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="<?php echo asset('js/bootstrap.min.js');?>"></script>
</body>
</html>
Controller:
(AuthController.php)
<?php
namespace App\Http\Controllers\Auth;
use App\User;
use Validator;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\ThrottlesLogins;
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;
use Illuminate\View\Middleware\ErrorBinder;
class AuthController extends Controller
{
/*
|--------------------------------------------------------------------------
| Registration & Login Controller
|--------------------------------------------------------------------------
|
| This controller handles the registration of new users, as well as the
| authentication of existing users. By default, this controller uses
| a simple trait to add these behaviors. Why don't you explore it?
|
*/
use AuthenticatesAndRegistersUsers, ThrottlesLogins;
/**
* Where to redirect users after login / registration.
*
* #var string
*/
private $redirectTo = '/';
private $maxLoginAttempts = 10;
/**
* Create a new authentication controller instance.
*
* #return void
*/
public function __construct()
{
$this->middleware('guest', ['except' => 'logout']);
}
/**
* Get a validator for an incoming registration request.
*
* #param array $data
* #return \Illuminate\Contracts\Validation\Validator
*/
protected function validator(array $data)
{
return Validator::make($data, [
'name' => 'required|max:255',
'email' => 'required|email|max:255|unique:users',
'password' => 'required|confirmed|min:6',
]);
}
/**
* Create a new user instance after a valid registration.
*
* #param array $data
* #return User
*/
protected function create(array $data)
{
return User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
]);
}
}
(AuthenticatesUsers.php)
<?php
namespace Illuminate\Foundation\Auth;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Lang;
trait AuthenticatesUsers
{
use RedirectsUsers;
/**
* Show the application login form.
*
* #return \Illuminate\Http\Response
*/
public function getLogin()
{
return $this->showLoginForm();
}
/**
* Show the application login form.
*
* #return \Illuminate\Http\Response
*/
public function showLoginForm()
{
if (property_exists($this, 'loginView')) {
return view($this->loginView);
}
if (view()->exists('auth.authenticate')) {
return view('auth.authenticate');
}
return view('auth.login');
}
/**
* Handle a login request to the application.
*
* #param \Illuminate\Http\Request $request
* #return \Illuminate\Http\Response
*/
public function postLogin(Request $request)
{
return $this->login($request);
}
/**
* Handle a login request to the application.
*
* #param \Illuminate\Http\Request $request
* #return \Illuminate\Http\Response
*/
public function login(Request $request)
{
$this->validate($request, [
$this->loginUsername() => 'required', 'password' => 'required','captcha'=>'required',
]);
// 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.
$throttles = $this->isUsingThrottlesLoginsTrait();
if ($throttles && $this->hasTooManyLoginAttempts($request)) {
return $this->sendLockoutResponse($request);
}
$credentials = $this->getCredentials($request);
if (Auth::guard($this->getGuard())->attempt($credentials, $request->has('remember'))) {
return $this->handleUserWasAuthenticated($request, $throttles);
}
// 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.
if ($throttles) {
$this->incrementLoginAttempts($request);
}
return $this->sendFailedLoginResponse($request);
}
/**
* Send the response after the user was authenticated.
*
* #param \Illuminate\Http\Request $request
* #param bool $throttles
* #return \Illuminate\Http\Response
*/
protected function handleUserWasAuthenticated(Request $request, $throttles)
{
if ($throttles) {
$this->clearLoginAttempts($request);
}
if (method_exists($this, 'authenticated')) {
return $this->authenticated($request, Auth::guard($this->getGuard())->user());
}
return redirect()->intended($this->redirectPath());
}
/**
* Get the failed login response instance.
*
* #param \Illuminate\Http\Request $request
* #return \Illuminate\Http\Response
*/
protected function sendFailedLoginResponse(Request $request)
{
return redirect()->back()
->withInput($request->only($this->loginUsername(), 'remember'))
->withErrors([
$this->loginUsername() => $this->getFailedLoginMessage(),
]);
}
/**
* Get the failed login message.
*
* #return string
*/
protected function getFailedLoginMessage()
{
return Lang::has('auth.failed')
? Lang::get('auth.failed')
: 'These credentials do not match our records.';
}
/**
* Get the needed authorization credentials from the request.
*
* #param \Illuminate\Http\Request $request
* #return array
*/
protected function getCredentials(Request $request)
{
return $request->only($this->loginUsername(), 'password');
}
/**
* Log the user out of the application.
*
* #return \Illuminate\Http\Response
*/
public function getLogout()
{
return $this->logout();
}
/**
* Log the user out of the application.
*
* #return \Illuminate\Http\Response
*/
public function logout()
{
Auth::guard($this->getGuard())->logout();
return redirect(property_exists($this, 'redirectAfterLogout') ? $this->redirectAfterLogout : '/');
}
/**
* Get the login username to be used by the controller.
*
* #return string
*/
public function loginUsername()
{
return property_exists($this, 'username') ? $this->username : 'email';
}
/**
* Determine if the class is using the ThrottlesLogins trait.
*
* #return bool
*/
protected function isUsingThrottlesLoginsTrait()
{
return in_array(
ThrottlesLogins::class, class_uses_recursive(get_class($this))
);
}
/**
* Get the guard to be used during authentication.
*
* #return string|null
*/
protected function getGuard()
{
return property_exists($this, 'guard') ? $this->guard : null;
}
}
can check this package better for recaptcha
https://github.com/anhskohbo/no-captcha
you can check recapcha in validation rules
In Your Package can check in rules for example
$rules = ['captcha' => 'required|captcha'];
$validator = Validator::make(Input::all(), $rules);
if ($validator->fails())
{
echo '<p style="color: #ff0000;">Incorrect!</p>';
}
else
{
echo '<p style="color: #00ff30;">Matched :)</p>';
}
Related
This type of question has been asked before but not one addresses my particular query. I have tried all the solutions but non seem to work.
I am building a Blog with Laravel and this particular error occurs when I try to edit any of my posts. You are all encouraged to participate. thank you.
edit.blade.php
#extends('layouts.app')
#section('content')
#if(count($errors)>0)
<ul class="list-group">
#foreach($errors->all() as $error)
<li class="list-group-item text-danger">
{{$error}}
</li>
#endforeach
</ul>
#endif
<div class="panel panel-default">
<div class="panel-heading">
Edit post{{$post->title}}
</div>
<div class="panel-body">
<form action="{{ route('post.update', ['id'=>$post->id])}}" method="post" enctype="multipart/form-data">
{{csrf_field()}}
<div class="form-group">
<label for="title">Title</label>
<input type="text" name="title" class="form-control" value="{{$post->title}}">
</div>
<div class="form-group">
<label for="featured">Featured Image</label>
<input type="file" name="featured" class="form-control">
</div>
<div class="form-group">
<label for="category">Select a Category</label>
<select type="file" name="category_id" id="category" class="form-control">
#foreach($categories as $category)
<option value="{{$category->id}}">{{$category->name}}</option>
#endforeach
</select>
</div>
<div class="form-group">
<label for="content">Content</label>
<textarea name="content" id="content" cols="5" rows="5" class="form-control" >{{$post->content}}</textarea>
</div>
<div class="form-group">
<div class="text-center">
<button class="btn btn-success" type="submit">Update Post</button>
</div>
</div>
</form>
</div>
</div>
#stop
PostController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Support\Str;
use Illuminate\Http\Request;
use App\Category;
use App\Post;
use Session;
class PostController extends Controller
{
/**
* Display a listing of the resource.
*
* #return \Illuminate\Http\Response
*/
public function index()
{
return view('admin.posts.index')->with('posts', Post::all());
}
/**
* Show the form for creating a new resource.
*
* #return \Illuminate\Http\Response
*/
public function create()
{
$categories =Category::all();
if ($categories-> count()==0){
Session::flash('info', 'You must have some categories before attempting to create a post');
return redirect()->back();
}
return view('admin.posts.create')->with('categories', Category::all());
}
/**
* Store a newly created resource in storage.
*
* #param \Illuminate\Http\Request $request
* #return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$this->validate($request, [
'title'=> 'required|max:255',
'featured'=>'required|image',
'content'=>'required',
'category_id' => 'required'
]);
$featured=$request->featured;
$featured_new_name= time().$featured->getClientOriginalName();
$featured->move('uploads/posts', $featured_new_name);
$post=Post::create([
'title'=> $request->title,
'content'=> $request->content,
'featured'=> 'uploads/posts/' .$featured_new_name,
'category_id'=> $request->category_id,
'slug' => Str::slug($request->title)
]);
Session::flash('success', 'Post created Successfully');
}
/**
* Display the specified resource.
*
* #param int $id
* #return \Illuminate\Http\Response
*/
public function show($id)
{
//
}
/**
* Show the form for editing the specified resource.
*
* #param int $id
* #return \Illuminate\Http\Response
*/
public function edit($id)
{
$post=Post::find($id);
return view('admin.posts.edit')->with('post', Post::find($id)->with('categories', Category::all()));
}
/**
* Update the specified resource in storage.
*
* #param \Illuminate\Http\Request $request
* #param int $id
* #return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
$post =Post::find($id);
$this->validate($request, [
'title'=> 'required',
'content'=>'required',
'category_id'=>'required']
);
if($request->hasfile('featured')){
$featured=$request->featured;
$featured_new_name=time() . $featured->getClientOriginalName();
$featured->move('uploads/posts', $featured_new_name );
$post->featured=$featured_new_name;
}
$post->title=$request->title;
$post->content=$request->content;
$post->category_id=$request->category_id;
$post->save();
Session::flash('success', 'Your post was just updated.');
return redirect()->route('posts');
}
/**
* Remove the specified resource from storage.
*
* #param int $id
* #return \Illuminate\Http\Response
*/
public function destroy($id)
{
$post =Post::find($id);
$post->delete();
Session::flash('success', 'Your post was just Trashed.');
return redirect()->back();
}
}
Property [title] does not exist on the Eloquent builder instance
This error message is telling you that you are trying to load a property named 'title' on an entity of type 'Eloquent builder'.
Eloquent builder is the type of object which can be used to query the database. The results of a call to ->first() on an Eloquent builder instance would be a Property entity, which is likely what you want.
Please examine and share the code where the Property is being loaded from the database. Do you do something, such as ->first(), to execute the query?
I have made a simple form when I am calling the form from api route it is showing an error that "errors" is an undefined variable when I am calling using web route it just works fine and shows no error. Why is this happening? Since error is a pre defined variable but why is it showing error.
Layout file:
#extends('layout')
#section('content')
<h1 class="title">Simple Form</h1>
<form method="POST" action="/website/atg/public/projects">
#csrf
<div class="field">
<label class="label" for="name">Name</label>
<div class="control">
<input type="text" class="input" name="name" placeholder="Enter Name" value="{{old('name')}}" required>
</div>
</div>
<div class="field">
<label class="label" for="email">E-mail</label>
<div class="control">
<input type="text" class="input" name="email" placeholder="Enter E-mail Address" value="{{old('email')}}" required>
</div>
</div>
<div class="field">
<label class="label" for="pincode">Pincode</label>
<div class="control">
<input type="text" class="input" name="pincode" placeholder="Enter Pincode" value="{{old('pincode')}}" required>
</div>
</div>
<div class="field">
<div class="control">
<button type="submit" class="button">Submit</button>
</div>
</div>
#if($errors->any())
<div class="notification">
<ul>
#foreach($errors->all() as $error)
<li>{{$error}}</li>
#endforeach
</ul>
</div>
#endif
</form>
#endsection
Routes file:
<?php
use Illuminate\Http\Request;
/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/
/*Route::middleware('auth:api')->get('/user', function (Request $request) {
return $request->user();
});
*/
Route::apiResource('projects','ATGController');
Controller file:
<?php
namespace App\Http\Controllers;
use App\Project;
use App\Mail\ProjectCreated;
use Illuminate\Support\Facades\Validator;
use Illuminate\Http\Request;
class ATGController extends Controller
{
/**
* Display a listing of the resource.
*
* #return \Illuminate\Http\Response
*/
public function index()
{
return view('projects.index');
}
/**
* Show the form for creating a new resource.
*
* #return \Illuminate\Http\Response
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*
* #param \Illuminate\Http\Request $request
* #return \Illuminate\Http\Response
*/
public function store(Request $request)
{
request()->validate([
'name'=>'required|unique:projects,name',
'email'=>'required|email|unique:projects,email',
'pincode'=>'required|digits:6'
]);
if ($validator->fails()) {
return redirect('/projects')
->withErrors($validator)
->withInput();
}
else{
$project=Project::create(request(['name','email','pincode']));
\Mail::to('sbansal1809#gmail.com')->send(
new ProjectCreated($project)
);
//echo '<script>alert("User added sucessfully!")</script>';
return response()->json($project);
}
}
/**
* Display the specified resource.
*
* #param \App\Project $project
* #return \Illuminate\Http\Response
*/
public function show(Project $project)
{
//
}
/**
* Show the form for editing the specified resource.
*
* #param \App\Project $project
* #return \Illuminate\Http\Response
*/
public function edit(Project $project)
{
//
}
/**
* Update the specified resource in storage.
*
* #param \Illuminate\Http\Request $request
* #param \App\Project $project
* #return \Illuminate\Http\Response
*/
public function update(Request $request, Project $project)
{
//
}
/**
* Remove the specified resource from storage.
*
* #param \App\Project $project
* #return \Illuminate\Http\Response
*/
public function destroy(Project $project)
{
//
}
}
you have to return validator fails like this, to be able to get $errors in your blade. Check below example for reference and change the code to your parameters
don't forget to import use Illuminate\Support\Facades\Validator;
public function store(Request $request){
$validator = Validator::make($request->all(), [
'name'=>'required|unique:projects,name',
'email'=>'required|email|unique:projects,email',
'pincode'=>'required|digits:6'
]);
if ($validator->fails()) {
return redirect('/projects/create')
->withErrors($validator)
->withInput();
}else{
$project=Project::create(request(['name','email','pincode']));
\Mail::to('sbansal1809#gmail.com')->send(
new ProjectCreated($project)
);
//echo '<script>alert("User added sucessfully!")</script>';
return response()->json($project);
}
}
It is a login page made with help of using artisan command make::auth and it generated all the required code , But remember me with this login page is not working.
Here is login page code
<form id="login-form" method="post" role="form" style="display:#if($errors->has('NotMobileRegisterd')) {{ 'none' }} #else {{ 'block' }} #endif ;" enctype="application/x-www-form-urlencoded">
<input type="hidden" name="_token" value="{{csrf_token()}}">
#if(Session::has('ErrorLogin'))
<div class="alert alert-danger">
<strong><i class="fa fa-ban"></i></strong> {{ Session::get('ErrorLogin')}}.
</div>
#endif
<div class="form-group form-group {{ $errors->has('email') ? ' has-error' : '' }}">
<input type="text" name="email" id="username" tabindex="1" class="form-control" placeholder="Username" value="{{ old('email') }}" required autofocus>
#if ($errors->has('email'))
<span class="help-block">
<strong>{{ $errors->first('email') }}</strong>
</span>
#endif
</div>
<div class="form-group {{ $errors->has('password') ? ' has-error' : '' }}">
<input type="password" name="password" id="password" autocomplete="off" tabindex="2" class="form-control" placeholder="Password" required>
#if ($errors->has('password'))
<span class="help-block">
<strong>{{ $errors->first('password') }}</strong>
</span>
#endif
</div>
<div class="form-group text-center">
<input type="checkbox" tabindex="3" class="" name="remember_me" id="remember">
<label for="remember"> Remember Me</label>
</div>
<div class="form-group">
<div class="row">
<div class="col-sm-6 col-sm-offset-3">
<input type="submit" name="submit" id="submit" tabindex="4" class="form-control btn btn-login" value="Log In">
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col-lg-12">
<div class="text-center">
<a href="{{ route('password.request') }}" tabindex="5" class="forgot-password" >Forgot Password?</a>
</div>
<button type="button" class="btn btn-primary pull-left" onclick="displayOTP()" style="padding-top:10px; padding-bottom:10px;"><i class="fa fa-mobile-alt"> Login with OTP</i></button>
<button type="button" class="btn btn-danger pull-right" style="padding-top:10px; padding-bottom:10px;"><i class="fa fa-at"> Login with Gmail</i></button>
</div>
</div>
</div>
</form>
After sending this to authenticationUser trait where checking if user have click remember me then passed value in auth::attempt . Code is working fine but when user logout then there is no credential stored in login form
trait AuthenticatesUsers
{
use RedirectsUsers, ThrottlesLogins;
/**
* Show the application's login form.
*
* #return \Illuminate\Http\Response
*/
public function showLoginForm()
{
return view('auth.login');
}
/**
* Handle a login request to the application.
*
* #param \Illuminate\Http\Request $request
* #return \Illuminate\Http\RedirectResponse|\Illuminate\Http\Response
*/
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);
}
if ($this->attemptLogin($request)) {
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);
}
/**
* Validate the user login request.
*
* #param \Illuminate\Http\Request $request
* #return void
*/
protected function validateLogin(Request $request)
{
$this->validate($request, [
$this->username() => 'required|string',
'password' => 'required|string',
]);
}
/**
* Attempt to log the user into the application.
*
* #param \Illuminate\Http\Request $request
* #return bool
*/
protected function attemptLogin(Request $request)
{
$remember_me=$request->has('remember_me')?true:false;
return $this->guard()->attempt(
$this->credentials($request),$remember_me
);
}
/**
* Get the needed authorization credentials from the request.
*
* #param \Illuminate\Http\Request $request
* #return array
*/
protected function credentials(Request $request)
{
return $request->only($this->username(), 'password');
}
/**
* Send the response after the user was authenticated.
*
* #param \Illuminate\Http\Request $request
* #return \Illuminate\Http\Response
*/
protected function sendLoginResponse(Request $request)
{
$request->session()->regenerate();
$this->clearLoginAttempts($request);
return $this->authenticated($request, $this->guard()->user())
?: redirect()->intended($this->redirectPath());
}
/**
* The user has been authenticated.
*
* #param \Illuminate\Http\Request $request
* #param mixed $user
* #return mixed
*/
protected function authenticated(Request $request, $user)
{
//
}
/**
* Get the failed login response instance.
*
* #param \Illuminate\Http\Request $request
* #return \Illuminate\Http\RedirectResponse
*/
protected function sendFailedLoginResponse(Request $request)
{
$errors = [$this->username() => trans('auth.failed')];
if ($request->expectsJson()) {
return response()->json($errors, 422);
}
return redirect()->back()
->withInput($request->only($this->username(), 'remember'))
->withErrors($errors);
}
/**
* Get the login username to be used by the controller.
*
* #return string
*/
public function username()
{
return 'email';
}
/**
* Log the user out of the application.
*
* #param \Illuminate\Http\Request $request
* #return \Illuminate\Http\Response
*/
public function logout(Request $request)
{
$this->guard()->logout();
$request->session()->invalidate();
return redirect('/');
}
/**
* Get the guard to be used during authentication.
*
* #return \Illuminate\Contracts\Auth\StatefulGuard
*/
protected function guard()
{
return Auth::guard();
}
}
And User table have remembering token attribute but still not remembering user credential after logout from page .
I think you are confusing what the remember me functionality of Laravel does.
It does not remember the users credentials, instead it sets a larger session time limit for the logged in user.
So as standard the user will be logged out after 2 hours of inactivity, with the remember me box ticked the session is set to a longer period, so you can navigate away from the site, come back 5 hours later and you will still be logged in.
But if the user logs out then the session is destroyed.
Hope that clarifies the functionality.
in laravel 5 i try the PasswordController and the ResetsPasswords but always i have a route probleme
Route.php
Route::controllers(['uses' => 'Auth/PasswordController']);
Route::get('home/ResetsPasswords',array('as'=>'getEmail' ,'uses' => 'home/ResetsPasswords#getEmail') );
Route::post('home/ResetsPasswords',array('as'=>'postEmail' ,'uses' => 'home/ResetsPasswords#postEmail' ));
Route::get('home/ResetsPasswords/{token}',array('as' => 'getReset','uses' => 'home/ResetsPasswords#getReset' ) );
Route::post('home/ResetsPasswords/{token}', array( 'as' => 'postReset','uses' => 'home/ResetsPasswords#postReset'));
Route::get('home/ResetsPasswords',array('as'=>'getEmailSubject' ,'uses' => 'home/ResetsPasswords#getEmailSubject') );
Route::get('home/ResetsPasswords',array('as'=>'redirectPath' ,'uses' => 'home/ResetsPasswords#redirectPath') );
The PasswordController.php
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\ResetsPasswords;
class PasswordController extends Controller
{
use ResetsPasswords;
public function __construct()
{
$this->middleware('guest');
}
}
the ResetsPasswords.php
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\ResetsPasswords;
class PasswordController extends Controller
{
/*
|--------------------------------------------------------------------------
| Password Reset Controller
|--------------------------------------------------------------------------
|
| This controller is responsible for handling password reset requests
| and uses a simple trait to include this behavior. You're free to
| explore this trait and override any methods you wish to tweak.
|
*/
use ResetsPasswords;
/**
* Create a new password controller instance.
*
* #return void
*/
public function __construct()
{
$this->middleware('guest');
}
}
<?php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\ResetsPasswords;
class PasswordController extends Controller
{
/*
|--------------------------------------------------------------------------
| Password Reset Controller
|--------------------------------------------------------------------------
|
| This controller is responsible for handling password reset requests
| and uses a simple trait to include this behavior. You're free to
| explore this trait and override any methods you wish to tweak.
|
*/
use ResetsPasswords;
/**
* Create a new password controller instance.
*
* #return void
*/
public function __construct()
{
$this->middleware('guest');
}
}
ResetsPasswords.php
<?php
//namespace Illuminate\Foundation\Auth;
use Illuminate\Http\Request;
use Illuminate\Mail\Message;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Password;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
trait ResetsPasswords
{
/**
* Display the form to request a password reset link.
*
* #return \Illuminate\Http\Response
*/
public function getEmail()
{
return view('auth.password');
}
/**
* Send a reset link to the given user.
*
* #param \Illuminate\Http\Request $request
* #return \Illuminate\Http\Response
*/
public function postEmail(Request $request)
{
$this->validate($request, ['email' => 'required|email']);
$response = Password::sendResetLink($request->only('email'), function (Message $message) {
$message->subject($this->getEmailSubject());
});
switch ($response) {
case Password::RESET_LINK_SENT:
return redirect()->back()->with('status', trans($response));
case Password::INVALID_USER:
return redirect()->back()->withErrors(['email' => trans($response)]);
}
}
/**
* Get the e-mail subject line to be used for the reset link email.
*
* #return string
*/
protected function getEmailSubject()
{
return isset($this->subject) ? $this->subject : 'Your Password Reset Link';
}
/**
* Display the password reset view for the given token.
*
* #param string $token
* #return \Illuminate\Http\Response
*/
public function getReset($token = null)
{
if (is_null($token)) {
throw new NotFoundHttpException;
}
return view('auth.reset')->with('token', $token);
}
/**
* Reset the given user's password.
*
* #param \Illuminate\Http\Request $request
* #return \Illuminate\Http\Response
*/
public function postReset(Request $request)
{
$this->validate($request, [
'token' => 'required',
'email' => 'required|email',
'password' => 'required|confirmed',
]);
$credentials = $request->only(
'email', 'password', 'password_confirmation', 'token'
);
$response = Password::reset($credentials, function ($user, $password) {
$this->resetPassword($user, $password);
});
switch ($response) {
case Password::PASSWORD_RESET:
return redirect($this->redirectPath());
default:
return redirect()->back()
->withInput($request->only('email'))
->withErrors(['email' => trans($response)]);
}
}
/**
* Reset the given user's password.
*
* #param \Illuminate\Contracts\Auth\CanResetPassword $user
* #param string $password
* #return void
*/
protected function resetPassword($user, $password)
{
$user->password = bcrypt($password);
$user->save();
Auth::login($user);
}
/**
* Get the post register / login redirect path.
*
* #return string
*/
public function redirectPath()
{
if (property_exists($this, 'redirectPath')) {
return $this->redirectPath;
}
return property_exists($this, 'redirectTo') ? $this->redirectTo : '/home';
}
}
and for the views
first the emails/password.blade.php
<?php
Click here to reset your password: {{ url('password/reset/'.$token) }}
?>
the auth/password.blade.php
#extends('layouts.master')
#section('content')
<div class="container-fluid">
<div class="row">
<div class="col-md-8 col-md-offset-2">
<div class="panel panel-default">
<div class="panel-heading">Reset Password</div>
<div class="panel-body">
#if (session('status'))
<div class="alert alert-success">
{{ session('status') }}
</div>
#endif
#if (count($errors) > 0)
<div class="alert alert-danger">
<strong>Whoops!</strong> There were some problems with your input.<br><br>
<ul>
#foreach ($errors->all() as $error)
<li>{{ $error }}</li>
#endforeach
</ul>
</div>
#endif
<form class="form-horizontal" role="form" method="POST" action="/password/email">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<div class="form-group">
<label class="col-md-4 control-label">E-Mail Address</label>
<div class="col-md-6">
<input type="email" class="form-control" name="email" value="{{ old('email') }}">
</div>
</div>
<div class="form-group">
<div class="col-md-6 col-md-offset-4">
<button type="submit" class="btn btn-primary">
Send Password Reset Link
</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
#endsection
the reset.blade.php
#extends('layouts.master')
#section('content')
<div class="container-fluid">
<div class="row">
<div class="col-md-8 col-md-offset-2">
<div class="panel panel-default">
<div class="panel-heading">Reset Password</div>
<div class="panel-body">
#if (count($errors) > 0)
<div class="alert alert-danger">
<strong>Whoops!</strong> There were some problems with your input.<br><br>
<ul>
#foreach ($errors->all() as $error)
<li>{{ $error }}</li>
#endforeach
</ul>
</div>
#endif
<form class="form-horizontal" role="form" method="POST" action="/password/reset">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<input type="hidden" name="token" value="{{ $token }}">
<div class="form-group">
<label class="col-md-4 control-label">E-Mail Address</label>
<div class="col-md-6">
<input type="email" class="form-control" name="email" value="{{ old('email') }}">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Password</label>
<div class="col-md-6">
<input type="password" class="form-control" name="password">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Confirm Password</label>
<div class="col-md-6">
<input type="password" class="form-control" name="password_confirmation">
</div>
</div>
<div class="form-group">
<div class="col-md-6 col-md-offset-4">
<button type="submit" class="btn btn-primary">
Reset Password
</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
#endsection
and finally my login view
Mot de passe oubliƩ?
so the error is
Call to undefined method Laravel\Routing\Route::controllers()
can you please help me :/ i try to change the route many time but always the same problem !!!!!!!
thank you
Implicit controllers are deprecated on Laravel 5. You need to remove this:
Route::controllers(['uses' => 'Auth/PasswordController']);
More info: https://laravel.com/docs/5.2/routing#route-model-binding
This is for laravel 5
Route::controllers([
'auth' => 'Auth\AuthController',
'password' => 'Auth\PasswordController',
]);
This is for laravel 5.2
Route::group(['middleware' => ['web']], function () {
Route::controllers([
'auth' => 'Auth\AuthController',
'password' => 'Auth\PasswordController',
]);
});
I think you are using in routes.php
use Illuminate\Routing\Route;
Route::controllers([
'auth' => 'Auth\AuthController',
'password' => 'Auth\PasswordController',
]);
if you use this then the error comes.
Call to undefined method Illuminate\Routing\Route::controllers()
to avoid this error use this
use Illuminate\Support\Facades\Route;
Route::controllers([
'auth' => 'Auth\AuthController',
'password' => 'Auth\PasswordController',
]);
Note:Dont need to import anything route
leave it as
The below one also works
Route::controllers([
'auth' => 'Auth\AuthController',
'password' => 'Auth\PasswordController',
]);
I created a login form and a registration form in my eComerace Application but when I submit my login form ( sign in ) it returns nothing ! I have typed username and password correct but my login page is not working.
Routes
Route::get('users/signin', 'UsersController#getSignin');
Route::post('users/signin', 'UsersController#postSignin');
Route::resource('users', 'UsersController');
Route::get('/', 'StoreController#index');
Route::get('store/category/{id}', 'StoreController#getCategory');
Route::get('store/search', 'StoreController#getSearch');
Route::get('/admin', function () {
return view('welcome');
});
Route::resource('store', 'StoreController');
Route::resource('admin/categories', 'CategoriesController');
Route::resource('admin/products', 'ProductsController');
UsersController
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Auth;
use App\Http\Requests;
use App\Category;
use App\product;
use Hash;
use View;
use Illuminate\Support\Facades\Input;
use Illuminate\Support\Facades\Redirect;
class UsersController extends Controller
{
public function __construct(){
parent::__construct();
}
/**
* Display a listing of the resource.
*
* #return \Illuminate\Http\Response
*/
public function getSignin(){
return View::make('users.signin');
}
public function index()
{
return Hash::make('ifti');
}
/**
* Show the form for creating a new resource.
*
* #return \Illuminate\Http\Response
*/
public function create()
{
return View::make('users.newaccount');
}
/**
* Store a newly created resource in storage.
*
* #param \Illuminate\Http\Request $request
* #return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$user = new User;
$user->name = Input::get('name');
$user->email = Input::get('email');
$user->password = Hash::make(Input::get('password'));
$user->save();
return Redirect::to('users/signin')->with('message','Thank you for creating new account.Sign in now');
}
/**
* Display the specified resource.
*
* #param int $id
* #return \Illuminate\Http\Response
*/
public function show($id)
{
//
}
/**
* Show the form for editing the specified resource.
*
* #param int $id
* #return \Illuminate\Http\Response
*/
public function edit($id)
{
//
}
/**
* Update the specified resource in storage.
*
* #param \Illuminate\Http\Request $request
* #param int $id
* #return \Illuminate\Http\Response
*/
public function update(Request $request, $id)
{
//
}
/**
* Remove the specified resource from storage.
*
* #param int $id
* #return \Illuminate\Http\Response
*/
public function destroy($id)
{
//
}
public function getSignout(){
Auth::logout();
return Redirect::to('users/signin')->with('message','Signouted!');
}
public function postSignin(){
$password = Hash::make(Input::get('password'));
$credentials = array('name' => Input::get('name'), 'password' => $password);
if(Auth::attempt($credentials)){
return Redirect::to('http://localhost/ecom/')->with('message','Thanks for signin');
}
return Redirect::to('users/signin')->with('message','Was Incorrect DATA!');
}
}
Signin View
{!! Form::open(array('url' => 'users/signin' , 'method' => 'post')) !!}
<div class="form-group">
<label for="username">User Name:</label>
{!! Form::text('name') !!}
</div>
<div class="form-group">
<label for="username">Password:</label>
{!! Form::password('password') !!}
</div>
<button type="submit" class="btn btn-default">Sign IN</button>
{!! Form::close() !!}
New Account View
<div class="col-md-8 col-lg-8 col-sm-12 col-xs-12">
{!! Form::open(array('url' => 'users/create' , 'method' => 'post')) !!}
<div class="form-group">
<label for="username">User Name:</label>
<input type="username" class="form-control" name="name" id="name">
</div>
<div class="form-group">
<label for="email">Email:</label>
<input type="email" class="form-control" name="email" id="name">
</div>
<div class="form-group">
<label for="password">Password:</label>
<input type="password" class="form-control" name="password" id="name">
</div>
<button type="submit" class="btn btn-default">Create New Account</button>
{!! Form::close() !!}
</div>