mardi 28 novembre 2017

Laravel login, check if username and pwd are a match in my database

In my login form all I need is just username and a password ,trying to use ajax to get data from sqlite .

enter image description here

.AJAX of my login.blade.php

$(document).ready(function(){

  $("#login").click(function(){
    $.ajax({
      type: "GET",
      url: "UserController.php",
      data: { username: $("#username").val(), password: $("#password").val()},
      success: function(data){

        response = JSON.parse(data);
        if(response[0]){

        }
        else{
          alert(response[1]);
        }
      }
    });
  });

});

my User.php

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Validator;

class User extends Model
{
    protected $table = 'user';

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'username', 'phone','email', 'password','password_confirmation','librarian'
    ];


}

read method in UserController

//to read data from database to login
    public function read(Request $request){


        $results = DB::select('select * from users where id = :id', ['id' => 1]);

        foreach ($users as $user) {
    echo $user->username;
}

my web.php

Route::get('/login', function () {
    return view('login');
});
Route::get('/signup',function(){
    return view('signup');
});
Route::get('/bookscreate',function(){
return view('bookscreate');
});

Route::get('/','BookController@index');
Route::post('signup', 'UserController@store');
//Route::post('signup', 'UserController@read');

Route::resource('/books','BookController');

So my objective is to go to my database table check username and password if they match one of the DB id then allow user to login .



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2AGJEHg
via IFTTT

Aucun commentaire:

Enregistrer un commentaire