vendredi 1 avril 2016

Login Form not working Laravel 5.2

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>



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire