First i have a UserController
controller to authenticate new users and register them. I have two methods index
for login and create
for registering a new user. But the Create
method doesn't work, No error occurs but the data is not going to database table.
Second the signup
form reload to its self after submission. signup
form have no action.
The userController
code :
<?php namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Auth;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Contracts\Hashing\Hasher;
use Illuminate\Http;
use Illuminate\Support\Facades\Input;
use Hash;
class UserController extends Controller
{
public function __construct(){
$this->middleware('auth');
}
public function index()
{
$cred = Input::only('email','password');
var_dump($cred);
if(Auth::attempt($cred)){
return Redirect::intended('index');
}else{
$error = "Username or password is incorrect.";
return Redirect::to('/signup');
}
}
public function create()
{
$user = new \App\User;
$user->username = input::get('firstname');
$user->username = input::get('lastname');
$user->username = input::get('username');
$user->email = input::get('email');
$user->password = Hash::make(input::get('password'));
$user->designation = input::get('profile_pic');
$user->save();
return view('index');
}
Routes :
Route::get('/', function () {
return view('index');
});
Route::get('index', function () {
return view('index');
});
Route::get('login', function () {
return view('login');
});
Route::post('login', 'UserController@index');
Route::get('/signup', function(){
return view('signup');
});
Route::post('/signup', ['uses' => 'UserController@create']);
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire