I configured laravel 5.1 according to mail docs. Sending mail works fine.
Next step was to add the reset password according to resetting passwords docs. Here I struggle to send the link to the reset-password formular.
Seems like the function to send the reset mail is not triggered. I checked as well with the config/mail.php configuration pretend = true;. There was no entry in the logfile, that a email was send.
Somehow its as well hard to debug, as I could not find the function where the reset email is triggered.
How do I send the reset password with mailgun?
Where is the function locate to send the reset password, or where can I overwrite it, to test it?
This are my configurations:
.env
# ...
MAIL_DRIVER=mailgun
MAIL_HOST=smtp.mail.org
MAIL_PORT=587
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAILGUN_DOMAIN=mg.foo.com
MAILGUN_SECRET=key-foobar.etc
# ....
config/service.php
//...
'mailgun' => [
'domain' => env('MAILGUN_DOMAIN'),
'secret' => env('MAILGUN_SECRET'),
],
//...
config/mail.php
// ...
'driver' => env('MAIL_DRIVER', 'smtp'),
'host' => env('MAIL_HOST', 'smtp.mailgun.org'),
'port' => env('MAIL_PORT', 587),
'from' => ['address' => 'foo#test.com', 'name' => 'foo'],
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('MAIL_USERNAME'),
'password' => env('MAIL_PASSWORD'),
'pretend' => false,
// ...
app/Http/routes.php
// ...
Route::group([
'prefix' => LaravelLocalization::setLocale(),
'middleware' => [ 'localeSessionRedirect', 'localizationRedirect' ]
], function() {
//Route::controllers([ 'password' => 'Auth\PasswordController', ]);
// works only if the user is logged out!!!1
// Password reset link request routes...
Route::get('password/email', 'Auth\PasswordController#getEmail');
Route::post('password/email', 'Auth\PasswordController#postEmail');
// Password reset routes...
Route::get('password/reset/{token}', 'Auth\PasswordController#getReset');
Route::post('password/reset', 'Auth\PasswordController#postReset');
});
//...
resources/views/auth/password.blade.php
#extends('layout')
#section('content')
<div class="container">
<form method="POST" action="/password/email">
{!! csrf_field() !!}
#if (count($errors) > 0)
<ul>
#foreach ($errors->all() as $error)
<li>{{ $error }}</li>
#endforeach
</ul>
#endif
<div class="row">
<div class="col-md-6">
{!! Form::label('email', trans( 'mes.email' )) !!}
<input type="email" name="email" value="{{ old('email') }}" class="form-control">
</div>
<div class="col-md-8">
<button type="submit" class="btn">
Send Password Reset Link
</button>
</div>
<div>
</form>
</div>
#endsection
Incorrect routes was the problem. The example from the docs did hardcode the action value in the form element.
This did not reflect my routes configuration. With the following changes the password reset email works:
app/Http/routes
// change route to a named route
// Route::post('password/email', 'Auth\PasswordController#postEmail');
Route::post('password/email', ['as' => 'password.email', 'uses' => 'Auth\PasswordController#postEmail']);
resources/views/auth/password.blade.php
<!-- Use the named route in the form builder and remove csrf_field -->
{!! Form::open(['route' => 'password.email']) !!}
Related
I have a method to store and validate data from POST request, the first method works fine and validated successfully.
public function saveClientInfo(){
ClientInfo::create($this->validateClientInfo());
}
public function validateClientInfo(){
return request()->validate([
'code' => 'required',
're' => ['required','unique:client_infos'],
'name' => 'required',
'contact' => 'required',
'email' => 'required',
'property' => 'required',
'status' => 'required'
]);
}
Here in this second method with the same structure for saving and validating the requests, it doesn't work I'm very intrigue as to why.
public function loanStatus(){
PaymentInfo::create($this->validatePay());
}
public function validatePay(){
return request()->validate([
'payment_type' => 'required',
'terms' => 'required',
'amount_due' => 'required',
'from' => 'required',
'to' => 'required'
]);
}
By the way they're in the same controller so I dont get nauseous trying to figure out what is the difference of both as to where I went wrong.
NOTE:
the error it gives is Route GET is not Supported suggested Method
POSTS some sort of like this,
that's why it's confusing enough already I checked the form and routes and I used post so why this error is showing so I figure it must be the request validate part.
Blade File
<form action="/proceed/loan-status" method="POST">
#csrf
<input type="hidden" name="re" value="{{ $re }}">
<div class="row">
<div class="p-2">
<input type="text" class="form-control" name="payment-type" placeholder="Payment Type...">
#if($errors->has('payment_type'))
<p class="alert text-danger">{{ $errors->first('payment_type') }}</p>
#endif
</div>
<div class="p-2">
<input type="text" class="form-control" name="terms" placeholder="Terms...">
</div>
<div class="p-2">
<input type="number" min="2" max="" step="any" class="form-control" name="amount" placeholder="Amount Due...">
</div>
<div class="p-2">
<input type="text" class="form-control" name="from" placeholder="From...">
</div>
<div class="p-2">
<input type="text" class="form-control" name="to" placeholder="To...">
</div>
</div>
</div>
<div class="card-footer d-flex justify-content-between">
<button type="submit" class="btn btn-success btn-sm">Save</button>
Cancel
</div>
</form>
web.php
Route::post('/proceed/loan-status', 'ClientInfoController#loanStatus');
If your Laravel version is 8, change the route sintax
Route::post('/proceed/loan-status', ClientInfoController::class,'loanStatus')->name('proceed.loan-status');
and in the blade form change the action to
<form action="{{ route('proceed.loan-status') }}" method="POST">
Also, I suggest you use validation request like Laravel doc, it's a better coded controller and adjusted to patterns. Changing that, you must have something like
public function loanStatus(StorePaymentInfoRequest $request){
PaymentInfo::create($request->validated());
}
and in the StorePaymentInfoRequest
/**
* Determine if the user is authorized to make this request.
*
* #return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* #return array
*/
public function rules()
{
return [
'payment_type' => 'required',
'terms' => 'required',
'amount_due' => 'required',
'from' => 'required',
'to' => 'required'
];
}
Please use the laravel's request validation.
php artisan make:request FormRequest
It will generate a file that you can use.
https://medium.com/#kamerk22/the-smart-way-to-handle-request-validation-in-laravel-5e8886279271
This Article is a good example.
The error look like you have defined post route in web.php but you are requesting form method is GET or vice versa .So it throwing error
So you need to change form method to post to support that
<form method="POST" >
Or if you still need get request in form method then you need to update routes form post to get
in your Route put your code like this
ROUTE::POST('/VARRIBALE NAME', [CONTROLLER NAME::CLASS, 'FUNCTIONNAME']->NAME('VARRIBALE NAME.FUNCTIONNAME);
Listed below are code listings in which changes have been made. The authorization and registration system works well. The only problem is resetting the password.
web.php
Route::get('/', function() {
return view('index');
});
Route::group([
'prefix' => '{locale}',
'where' => ['locale' => '[a-zA-Z]{2}'],
'middleware' => 'setlocale'
], function () {
Route::get('/', function () {
return view('index');
});
Auth::routes();
});
head
<head>
...
<meta name="csrf-token" content="{{ csrf_token() }}">
...
</head>
email.blade.php
#extends('layouts._main')
#section('content')
<section class="main_section">
<div class="auth_wrapper">
<div class="form_container">
#if (session('status'))
<div class="alert alert-success" role="alert">
{{ session('status') }}
</div>
#endif
<form method="POST" action="{{ route('password.email', app()->getLocale()) }}" class="auth_login">
#csrf
<div class="auth_form_titles">
<h1 class="auth_form_title">#lang('forgot.caption')</h1>
</div>
<div class="auth_form_text">#lang('forgot.text')</div>
<input id="email" type="email" name="email"
#if($errors->has('email')) class="fields_error" #else class="fields" #endif
placeholder="#lang('forgot.email_field')" title="#lang('forgot.email_field')"
value="{{ old('email') }}" required autocomplete="email" autofocus>
#error('email')
<span class="validation_error">{{ $message }}</span>
#enderror
<button type="submit" class="buttons button_login">#lang('forgot.button2')</button>
</form>
</div>
</div>
</section>
#endsection
If now I click on the button "Send Password Reset Link", I get an error.
result
Illuminate\Routing\Exceptions\UrlGenerationException
Missing required parameters for [Route: password.reset] [URI: {locale}/password/reset/{token}].
Please tell me how to solve this problem.
This is a publicly shared error: https://flareapp.io/share/lm2GgDPx#F61
In order for the error not to appear in the described scheme, it is enough to make the prefix parameter optional (?), And also list the languages with a regular expression, as in the listing below:
Route::group([
'prefix' => '{locale?}',
'where' => ['locale' => '^ru|en$'],
'middleware' => 'setlocale'
], function () {
Route::get('/', function() {
return view('index');
});
Auth::routes();
});
When i check in firefox i can i see my password.
I am using the following code
#using (Html.BeginForm("Login", "Account", FormMethod.Post, new { #class = "navbar-form navbar-left", #id = "loginform" }))
{
#Html.AntiForgeryToken()
#Html.ValidationSummary(true)
<div class="form-group form-header input-group-lg">
#Html.TextBoxFor(m => m.UserName, htmlAttributes: new { #class = "form-control", #placeholder = "Email:" })
#Html.ValidationMessageFor(m => m.UserName)
</div>
<div class="form-group form-header input-group-lg">
#Html.PasswordFor(m => m.Password, htmlAttributes: new { #class = "form-control", #placeholder = "Password:" })
#Html.ValidationMessageFor(m => m.Password)
</div>
<button class="btn btn-danger btn-lg" type="submit">Login</button>
<div class="remember">
#Html.CheckBoxFor(m => m.RememberMe, htmlAttributes: new { #id = "login-remember" })
#Html.LabelFor(m => m.RememberMe)
</div>
}
The password will always be sent in plain text in the post body. #Html.PasswordFor only obscures the input box on the screen to prevent people looking over the user's shoulder and knowing their password.
This is why you should only submit secure information through an https page: this way it will be encrypted during transmission from your computer to the remote server. It is good practice to make sure during the initial page GET that the page is on https, and if not then redirect the user to the https url for the page.
I am trying to recreate the HTML design of an existing login form for use in an MVC4 program. Most of this is fine, however when I try to enter a pipe character ( | ) between two elements, it throws an error "unexpected token". You can see it there at the bottom, after the button and before the anchor. Any ideas why this is an error? Is there a way to fix it? (Other than removing the pipe character?)
#using (Html.BeginForm("Login", "AccountController", new { ReturnUrl = ViewBag.ReturnUrl }, FormMethod.Post, new { #class = "form-login form-wrapper form-narrow" }))
{
#Html.AntiForgeryToken()
#Html.ValidationSummary(true)
<h3 class="title-divider"><span>Login</span> <small>Not signed up? #Html.ActionLink("Sign Up Here.", "Register")</small></h3>
#Html.LabelFor(m => m.UserName)
#Html.TextBoxFor(m => m.UserName, new { #class = "input-block-level" } )
#Html.ValidationMessageFor(m => m.UserName)
#Html.LabelFor(m => m.Password)
#Html.PasswordFor(m => m.Password, new { #class = "input-block-level" })
#Html.ValidationMessageFor(m => m.Password)
#Html.LabelFor(m => m.RememberMe, new { #class = "checkbox" })
#Html.CheckBoxFor(m => m.RememberMe)
<button class="btn btn-primary" type="submit" value="Log in" >Sign in</button>
| Forgotten Password?
}
Put it inside <text> tags or use the #: operator
<text>|</text>
or
#:|
Inside the using statement, you are actually in a razor code block, so anything not inside an html tag or preceded by the #: operator will be read as server code.
I have the following code for my login view:
<?php
echo $session->flash('auth');
echo $this->Form->create('User', array('action' => 'login'));
echo $this->Form->input('email');
echo $this->Form->input('password');
echo $this->Form->end('Login');
?>
This generates the following HTML:
<div id="authMessage" class="message">Login failed. Invalid username or password.</div>
<form id="UserLoginForm" method="post" action="/control/users/login" accept-charset="utf-8">
<div style="display: none;"><input name="_method" value="POST" type="hidden"></div>
<div class="input text required">
<label for="UserEmail">Email</label>
<input name="data[User][email]" maxlength="255" value="" id="UserEmail" type="text">
</div>
<div class="input password">
<label for="UserPassword">Password</label>
<input name="data[User][password]" id="UserPassword" type="password">
</div>
<div class="submit"><input value="Login" type="submit"></div>
</form>
App Controller:
function beforeFilter()
{
$this->Auth->fields = array (
'username' => 'email',
'password' => 'password'
);
}
When I attempt to log in I get an error that my password is incorrect. Here's a dump of $this->data:
Array
(
[User] => Array
(
[email] => myemail#gmail.com
[password] =>
)
)
I found a few other similar questions on stackoverflow but none of them seem to have an answer. Does anyone know why this is happening?
The cakePHP Auth component will hash your password and try to match with the password in DB.
They are hashing the password with the salt.
If you are setHash to MD5 then
MD5($password.$salt) will be stored matched with the password in DB.
So plz make sure that you are storing the password is correct.
To enter some dummy data. i usually try to debug $this->Auth->password($password) Then i will copy the result and insert in DB.
If the password is wrong the Auth component will reset the password field internally.ie., why u get this result.
Array
(
[User] => Array
(
[email] => myemail#gmail.com
[password] =>
)
)
This doesn't means your password is not available for checking with DB.
Happy Baking