hi , i am new in laravel & stuck in a stage pls help me ... I am trying to authenticate a user & show his profile page with his name , the registration process is successful but the login is not happening as the authentication of the user from database is not not happaining hears the code which i am trying ...
LOGIN page-----
<!doctype html> <html> <head> <!-- Bootstrap --> {{ HTML::style('/css/bootstrap.min.css') }} {{ HTML::style('/css/bootstrap-theme.min.css') }} {{ HTML::style('/css/bootstrap.css') }} {{ HTML::style('/css/style.css') }} {{ HTML::script('jss/bootstrap.js') }} {{ HTML::script('js/jquery') }} {{ HTML::script('js/respond.js') }} </head> </head> <body> <div class="row"> <div class="col-lg-offset-5 col-lg-7"> <div cass="well"> <legend>Login</legend> {{ Form::open(array('url'=>'A_L_F')) }} @if($errors->any()) <div class="alert alert-error"> <a href="#" class="close" data-dismiss="alert">×</a> {{ implode('',$errors->all('<li class="error">:message</li>')) }} </div> @endif {{ Form::text('email','',array('placeholder' => 'Email')) }}<br> {{ Form::text('password','',array('placeholder' => 'Password')) }}<br> {{ Form::submit('Login','',array('class' => 'btn btn-success')) }} {{ HTML::link('A_R_F','Register',array('class' => 'btn btn-primary')) }} {{ Form::close() }} </div>
</div>
</div>
<!-- javascript -->
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/bootstrap.js"></script>
<script src="js/bootstrap-modalmanager.js"></script>
<script src="js/bootstrap-modal.js"></script>
</body>
</html>
__________________________________________________________________________________________
REGISTRATION page--
<!doctype html> <html> <head> <!-- Bootstrap --> {{ HTML::style('/css/bootstrap.min.css') }} {{ HTML::style('/css/bootstrap-theme.min.css') }} {{ HTML::style('/css/bootstrap.css') }} {{ HTML::style('/css/style.css') }} {{ HTML::script('jss/bootstrap.js') }} {{ HTML::script('js/jquery') }} {{ HTML::script('js/respond.js') }} </head> </head> <body> <div class="row"> <div class="col-lg-offset-5 col-lg-7"> <div cass="well"> <legend>Register</legend> {{ Form::open(array('url'=>'A_R_F')) }} @if($errors->any()) <div class="alert alert-error"> <a href="#" class="close" data-dismiss="alert">×</a> {{ implode('',$errors->all('<li class="error">:message</li>')) }} </div> @endif {{ Form::text('username','',array('placeholder' => 'Username')) }}<br> {{ Form::text('email','',array('placeholder' => 'Email')) }}<br> {{ Form::text('password','',array('placeholder' => 'Password')) }}<br> {{ Form::submit('Register','',array('class' => 'btn btn-success')) }} {{ HTML::link('A_L_F','Cancle',array('class' => 'btn btn-danger')) }} {{ Form::close() }} </div>
</div>
</div>
<!-- javascript -->
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/bootstrap.js"></script>
<script src="js/bootstrap-modalmanager.js"></script>
<script src="js/bootstrap-modal.js"></script>
</body>
</html>
_____________________________________________________________________________________________
Profile page
<div class="span8 well">
<h4>Hellow{{ ucwords(Auth::user()->username) }}</h4>
</div>
_____________________________________________________________________________________- Routes
Route::get('A_L_F', 'HomeController@getA_L_F'); Route::post('A_L_F', 'HomeController@getA_L_F');
Route::get('A_R_F', 'HomeController@getA_R_F'); Route::post('A_R_F', 'HomeController@postA_R_F');
Route::post('logout', 'HomeController@logout');
Route::group(array('before'=>'auth'),function(){
Route::get('admin','AdminController@getIndex');
});
Home controller
<?php class HomeController extends BaseController { /* |-------------------------------------------------------------------------- | Default Home Controller |-------------------------------------------------------------------------- | | You may wish to use controllers instead of, or in addition to, Closure | based routes. That's great! Here is an example controller method to | get you started. To route to this controller, just add the route: | | Route::get('/', 'HomeController@showWelcome'); | */ public function getindex() { return View::make('index'); } public function getLogin() { return View::make('home.login'); } public function getproduct() { return View::make('product'); } public function getslider() { return View::make('slider'); } public function getdemo() { return View::make('demo'); } public function getA_L_F() { return View::make('A_L_F'); } public function postA_L_F() { $input = Input::all(); $rules = array('email'=>'required','password'=>'required' ); $v = Validator::make($input, $rules); if ($v->fails()) { return Redirect::to('A_L_F')->withErrors($v); }else{ $credentials = array('email' =>$input['email'],'password'=>$input['password']); if(Auth::attempt($credentials)) { return Redirect::to('admin'); }else{ return Redirect::to('A_L_F'); } } } public function getA_R_F() { return View::make('A_R_F'); } public function postA_R_F() { $input = Input::all(); $rules = array('username'=>'required|unique:users','email'=>'required|unique:users|email', 'password' =>'required'); $v = Validator::make($input, $rules); if ($v->passes()) { $password = $input['password']; $password =Hash::make($password); $user = new User(); $user ->username = $input['username']; $user ->email = $input['email']; $user ->password = $password; $user ->save(); return Redirect::to('A_L_F'); }else{ return Redirect::to('A_R_F')->withInput()->WithErrors($v); } } public function logout() { Auth::logout(); return Redirect::to('A_L_F'); } } _________________________________________________________________________ Admin Contriller <?php class AdminController extends \BaseController { public function getIndex() { return View::make('admin.index'); } } ____________________________________________________________________________ database Schema::create('users', function(Blueprint $table){ $table->increments('userid'); $table->string('username'); $table->string('email'); $table->string('password'); $table->timestamp('created_at'); $table->timestamp('updated_at'); });Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community