laravel 5.2 signup probleme - php

I'm working on laravel 5.2 shopping cart site and i have this sign up problem when i put an email address and a password to signup it tells me that password is required. but i filed the password place
the view signup
this is my user controller
<?php
namespace App\Http\Controllers;
use App\User;
use Illuminate\Http\Request;
use App\Http\Requests;
use Illuminate\Support\Facades\Auth;
class UserController extends Controller
{
public function getSignup(){
return view('user.signup');
}
public function postSignup(Request $request){
$this->validate($request,['email'=>'email|required|unique:users',
'password'=>'required|min:4',
]);
$user=new User([
'email'=> $request->input('email'),
'password'=>bcrypt($request->input('password'))
]);
$user->save();
return redirect()->route('product.index');
}
public function getSignin(){
return view('user.signin');
}
public function postSignin(Request $request){
if(Auth::attempt(['email'=>$request->input('email'), 'password'=>$request->input('password')])){
return redirect()->route('user.profile');
}
return redirect()->back();
}
public function getProfile(){
return view('user.profile');
}
}

Could you please post the view?, check if in the view you are putting to the password input the same name you are trying to get in the controller action

this is the view of signup controller
#extends('layouts.master')
#section('content')
<div class="row">
<div class="col-lg-4 col-lg-offset-4">
<h1>Sign Up</h1>
#if(count($errors)>0)
#foreach($errors->all() as $error)
<div class="alert alert-danger form-group">
<p>{{$error}}</p>
</div>
#endforeach
#endif
<form action="{{route('user.signup')}}" method="post">
<div class="form-group">
<label for="email">E-mail</label>
<input type="email"id="email" name="email" class="form-control">
</div>
<div class="form-group">
<label for="password">Password</label>
<input type="password" id="Password" name="Password" class="form-control">
</div>
<button class="btn btn-primary" type="submit">Sign Up</button>
{{csrf_field()}}
</form>
</div>
</div>
#endsection

Related

Can't login using Laravel with correct credentials

Good day, I've been having a hard time solving this problem for almost a week now. I'm trying to login my Laravel project, the problem is it doesn't login even though the email and password (hashed in db) input is correct. Any help will be greatly appreciated. Below are the code of my files for LoginController.php, login.blade.php, and web.php
LoginController.php
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use App\Providers\RouteServiceProvider;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Http\Request;
use Auth;
use DB;
use App\Models\Distributor;
use Carbon\Carbon;
use Session;
use Brian2694\Toastr\Facades\Toastr;
class LoginController extends Controller
{
/*
|--------------------------------------------------------------------------
| Login Controller
|--------------------------------------------------------------------------
|
| This controller handles authenticating users for the application and
| redirecting them to your home screen. The controller uses a trait
| to conveniently provide its functionality to your applications.
|
*/
use AuthenticatesUsers;
/**
* Where to redirect users after login.
*
* #var string
*/
protected $redirectTo = RouteServiceProvider::HOME;
/**
* Create a new controller instance.
*
* #return void
*/
public function __construct()
{
$this->middleware('guest')->except([
'logout',
'locked',
'unlock'
]);
}
public function login()
{
return view('auth.login');
}
public function username(){ return 'email_address';
}
public function authenticate(Request $request)
{
$request->validate([
'email' => 'required|string|email',
'password' => 'required|string',
]);
$email = $request->email;
$password = $request->password;
if (Auth::attempt(['emailAddress'=>$email,'password'=>$password,])) {
Toastr::success('Login successfully :)','Success');
return redirect()->intended('orders.sellload');
}elseif (Auth::attempt(['emailAddress'=>$email,'password'=>$password])) {
Toastr::success('Login successfully :)','Success');
return redirect()->intended('orders.sellload');
}elseif (Auth::attempt(['emailAddress'=>$email,'password'=>$password,])) {
Toastr::success('Login successfully :)','Success');
return redirect()->intended('admin.distributor');
}
elseif (Auth::attempt(['emailAddress'=>$email,'password'=>$password])) {
Toastr::success('Login successfully :)','Success');
return redirect()->intended('admin.distributor');
}else{
Toastr::error('fail, WRONG USERNAME OR PASSWORD :)','Error');
return redirect('login');
}
}
public function logout()
{
Auth::logout();
Toastr::success('Logout successfully :)','Success');
return redirect('login');
}
}
login.blade.php
#extends('layouts.app')
#section('content')
<div id="auth">
<div class="row h-100">
<div class="col-lg-3 col-12">
</div>
<div class="col-lg-6 col-12">
<div id="auth-left">
<p style="text-align:center;"><img src="assets/images/logo/icon.png" width="300" align>
</p>
{{-- message --}}
{!! Toastr::message() !!}
<p style="text-align:center;">Welcome to John Doe Portal</p>
#if(session()->has('error'))
<div class="text-danger text-center text-bold">
{{ session()->get('error') }}
</div>
#endif
<br>
<form method="POST" action="{{ route('login') }}" class="md-float-material">
#csrf
<div class="form-group position-relative has-icon-left mb-4">
<input type="text" class="form-control form-control-lg #error('email') is-invalid #enderror" name="email" value="{{ old('email') }}" placeholder="Enter email">
<div class="form-control-icon">
<i class="bi bi-person"></i>
</div>
#error('email')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
<div class="form-group position-relative has-icon-left mb-4">
<input type="password" class="form-control form-control-lg #error('password') is-invalid #enderror" name="password" placeholder="Enter Password">
<div class="form-control-icon">
<i class="bi bi-shield-lock"></i>
</div>
#error('password')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
<div class="form-check form-check-lg d-flex align-items-end">
<input class="form-check-input me-2" type="checkbox" value="remember_me" id="remember_me" name="remember_me">
<label class="form-check-label text-gray-600" for="flexCheckDefault">
Keep me logged in
</label>
</div>
<button class="btn btn-primary btn-block btn-lg shadow-lg mt-5">LOG IN</button>
</form>
</div>
</div>
<div class="col-lg-3 col-12">
</div>
</div>
</div>
#endsection
web.php
<?php
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\PhotosController;
use App\Http\Controllers\Auth\LoginController;
use App\Http\Controllers\Auth\RegisterController;
use App\Http\Controllers\ResetPasswordController;
use App\Http\Controllers\FormController;
use App\Http\Controllers\UserManagementController;
use App\Http\Controllers\LockScreen;
Route::get('/', function () {
return view('auth.login');
});
Route::get('/insert', function () {
$activationCodeParam=123456;
$idParentParam=1;
$tierParam=2;
$store = DB::select('
call createStore(?,?,?)',
array(activationCodeParam,idParentParam,tierParam));
});
Route::group(['middleware'=>'auth'],function()
{
Route::get('user',function()
{
return view('orders.sellload');
});
Route::get('home',function()
{
return view('orders.sellload');
});
});
Auth::routes();
Route::get('home',function()
{
return view('orders.sellload');
});
// ----------------------------- home dashboard ------------------------------//
Route::get('/home', [App\Http\Controllers\HomeController::class, 'index'])->name('home');
// -----------------------------login----------------------------------------//
Route::get('/login', [App\Http\Controllers\Auth\LoginController::class, 'login'])->name('login');
Route::post('/login', [App\Http\Controllers\Auth\LoginController::class, 'authenticate']);
Route::get('/logout', [App\Http\Controllers\Auth\LoginController::class, 'logout'])->name('logout');
You are missing the session refresh before your redirect.
// validation here
if(Auth::attempt(['emailAddress'=>$email,'password'=>$password,])) {
Toastr::success('Login successfully :)','Success');
$request->session()->regenerate(); // refresh session
return redirect()->intended('orders.sellload');
}
// …
This shouldn’t be related, but also your if-conditions don’t make sense — because they are all the same and if one matches, the other never can be reached.
Have you tried changing
if (Auth::attempt(['emailAddress'=>$email,'password'=>$password,]))
emailAddress
to email?

Laravel 5.8 Authentication coming back to login page after signing in

After clicking the sign in button, page refreshes and comes back to the login page. I tried debugging with dd() but the data seems to be posting. I have included my blade, web.php and controller below.
login.blade.php
<form action="{{ route('admin.login') }}" method="post">
{{ csrf_field() }}
<div class="input-group mb-3">
<input type="email" class="form-control" name="email" placeholder="Email">
<div class="input-group-append">
<div class="input-group-text">
<span class="fas fa-envelope"></span>
</div>
</div>
</div>
<div class="input-group mb-3">
<input type="password" class="form-control" name="password" placeholder="Password">
<div class="input-group-append">
<div class="input-group-text">
<span class="fas fa-lock"></span>
</div>
</div>
</div>
<div class="row">
<div class="col-4">
<button type="submit" class="btn btn-primary btn-block">Sign In</button>
</div> </div>
</form>
web.php
Route::get('/login', 'Auth\LoginController#showLoginForm')->name('admin.login');
Route::post('/login', 'Auth\LoginController#login');
Controller
public function showLoginForm()
{
return view('admin.login');
}
public function login(Request $request)
{
$this->validateLogin($request);
if ($this->attemptLogin($request)) {
return $this->sendLoginResponse($request);
}
return $this->sendFailedLoginResponse($request);
}
Your named route is a get route which shows the login form and you are trying to submit the form to the get route, which just returns the same page with the login form.
In route definitions you can have the post route as the named one
Route::get('/login', 'Auth\LoginController#showLoginForm');
Route::post('/login', 'Auth\LoginController#login')->name('admin.login');
You change your default login system, so conflict url, change url -
Route::get('/admin/login', 'Auth\LoginController#showLoginForm')->name('admin.login');
Route::post('/admin/login', 'Auth\LoginController#login');
I hope it will be work!
There is something different if the problem is not solved with the answers above.
Have you tried to look redirection operations at auth middleware?
Like this:
protected function redirectTo($request)
{
if (! $request->expectsJson()) {
return route('login');
}
}

BadMethodCallException Method App\Http\Controllers\UsuarioController::update does not exist

I'm new to Laravel (I'm using version 8) and I've been reviewing this error for a long time and I don't know what else to try.
I have a resource controller called ** UserController.php ** and I set the path in ** web.php ** as follows:
Route::resource('usuarios', App\Http\Controllers\UsuarioController::class);
The resource paths are:
The user can enter their profile and modify their fields through this menu option that invokes the edit() method of the controller:
So far everything works very well, but when the user enters to edit in the ** edit.blade.php ** form, and selects the "update" button that calls the method ** update () ** of the controller, it jumps to me the error: BadMethodCallException
Method App\Http\Controllers\UsuarioController::update does not exist.
This is edit.blade.php:
#section('title', 'Mi Perfil')
#section('intro')
#endsection
<br><br>
<style type="text/css">
h5 {text-align: center}
nav.navbar {
background-color: #34495E;
}
</style>
#section('content0')
<div class="container3">
<div class="bShadow3 bShadow-33">
<form method="POST" action="{{route('usuarios.update',[Auth::user()->slug]) }}">
#method('PUT')
#csrf
<br>
<h5>Mi perfil</h5>
<div class="form-group ml-5 mr-5">
<label for="name">{{ __('Nombre de usuario') }}</label>
<input id="name" type="text" class="form-control #error('name') is-invalid #enderror" name="name" value="{{Auth::user()->name}}" autocomplete="name" maxlength="30" autofocus placeholder="Introduce tu nombre de usuario" required>
#error('name')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
<div class="form-group ml-5 mr-5">
<label for="name">{{ __('Dirección de correo:') }}</label><br>
<label for="email">{{Auth::user()->email}}</label>
</div>
<div class="form-group row mb-0">
<div class="col text-center">
<button type="submit" class="btn2 mt-2 mb-3">
{{ __('Actualizar') }}
</button>
<button type="default" class="btn2 mt-2 mb-3">
{{ __('Cancelar') }}
</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
#endsection
This is UsuarioController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Providers\RouteServiceProvider;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Support\Facades\Auth;
use App\Models\User;
use App\Models\Role;
class UsuarioController extends Controller
{
public function __construct()
{
//permitir solo usuarios autenticados
$this->middleware('auth');
}
public function index()
{
//
}
public function create()
{
//
}
public function store(Request $request)
{
}
public function show($id)
{
}
public function edit($id)
{
$usuario=User::find($id);
if ($usuario== null)
return Redirect::to('usuario');
return view('usuarios.edit')->with('id',$id);
}
public function update(Request $request, $id)
{
$user = User::find($id);
$user->name = Input::get('name');
$user->email = Input::get('email');
$user->password = Input::get('password');
$user->save();
}
public function destroy($id)
{
//
}
}
If someone can give me a hand, I will thank them very much!
Thanks for the answers, I already fixed the error.
I had two controllers using the same controller class and I was working with one and laravel with another.
I do not know exactly where the problem comes from but I think
1: change route
{{route('usuarios.update',auth()->user()) }}
2: It needs a model but you send slug usuarios/{usuario}

submit form not storing data to database

So i was trying to make a posting form using ckeditor and post it to database, and then try to display it in the same view, but after i submit the form i don't see anything in my database table so clearly it's not even storing to database, is there any mistakes in my controller or view ?
this is my GuestbookController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Guestbook;
class GuestbookController extends Controller
{
public function index()
{
$guestbooks = Guestbook::get();
return view('post.post_textarea',[
'guestbooks' => $guestbooks,
]);
}
public function store(Request $request)
{
Guestbook::create([
'name' => $request->name,
'message' => $request->message
]);
return redirect()->back();
}
}
this is my routes
Route::get('/posting','GuestbookController#index')->name('guestbook');
Route::post('/posting','GuestbookController#store')->name('guestbook.store');
this is my model
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Guestbook extends Model
{
protected $fillable = ['name', 'message'];
}
and this is my view
<section class="games-single-page">
<div class="container">
#foreach ($guestbooks as $guestbook)
<div class="card">
<div class="card-body">
<label>mike</label>
<h3>{{ $guestbok->name }}</h3>
{!! $guestbook->message !!}
</div>
</div>
#endforeach
<div class="card">
<div class="card-body">
<form action="/posting" method "POST">
<div class="form-group">
<label style="color: black;" >Title</label>
<input type="text" class="form-control" name="name">
</div>
<div class="form-group">
<label style="color: black;" >Your Input</label>
<br>
<textarea class="form-control" name="message" id="" rows="10"></textarea>
</div>
<div class="form-group">
<input type="submit" class="btn btn-primary" value"Send">
</div>
</form>
</div>
</div>
</div>
</section>
You forgot an equal sign '=' and a csrf field. try the answer.
<form action="/posting" method="POST">
{{csrf_field()}}

Fatal error: Class 'App\Http\Controllers\Input' not found when sending a form

I'm trying to send an email filled with a form from a Laravel app.
When you hit submit it throws the above error:
Fatal error: Class 'App\Http\Controllers\Input' not found
Not sure why as I don't have, nor knew I needed to have an Input controller, or what I would put in it.
Below is the content of the controller:
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
class contact extends Controller
{
// This function will show the view
public function showForm()
{
return view('pages.contact');
}
public function handleFormPost()
{
$input = Input::only('name', 'email', 'msg');
$validator = Validator::make($input,
array(
'name' => 'required',
'email' => 'required|email',
'msg' => 'required',
)
);
if ($validator->fails())
{
return Redirect::to('contact')->with('errors', $validator->messages());
} else { // the validation has not failed, it has passed
// Send the email with the contactemail view, the user input
Mail::send('contactemail', $input, function($message)
{
$message->from('idocompscihw#gmail.com', 'Your Name');
$message->to('idocompscihw#gmail.com');
});
// Specify a route to go to after the message is sent to provide the user feedback
return Redirect::to('thanks');
}
}
}
Below is the view of the forum (based on bootstrap):
<div class="container">
<h1>A basic contact form</h1>
<form id="contact" method="post" class="form" role="form">
#if(Session::has('errors'))
<div class="alert alert-warning">
#foreach(Session::get('errors')->all() as $error_message)
<p>{{ $error_message }}</p>
#endforeach
</div>
#endif
<div class="row">
<div class="col-xs-6 col-md-6 form-group">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<input class="form-control" id="name" name="name" placeholder="Name" type="text"autofocus="">
</div>
<div class="col-xs-6 col-md-6 form-group">
<input class="form-control" id="email" name="email" placeholder="Email" type="text">
</div>
</div>
<textarea class="form-control" id="message" name="msg" placeholder="Message" rows="5"></textarea>
<br>
<div class="row">
<div class="col-xs-12 col-md-12 form-group">
<button class="btn btn-primary pull-right" type="submit">Submit</button>
</div>
</div>
</form>
</div>
Used this in your contact.php Controllers-
use Illuminate\Support\Facades\Input;
your error will get fixed. Thanks.
Input:: is replaced with Request::. Instead of
$input = Input::only('name', 'email', 'msg');
use this:
$input = Request::only('name', 'email', 'msg');
And if you get error something about 'should not use statically' just add this at the top of your file
use Request;
If you already have this line:
use Illuminate\Http\Request;
delete it because you can't have two classes with the same name in one file
public function handleFormPost(Request $request)
{
$name = $request->get('name');
$email = $request->get('email');
$msg = $request->get('msg');
}
OR
public function handleFormPost(Request $request)
{
$input = $request->all();
}
you not use input try this :
use Input;
Put it after the namespace declaration like this
<?php
namespace App\Http\Controllers;
use Input;
...
?>

Categories