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
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);
I'm trying to authenticate a login request from my login.html file
<form action="{{ url_for('login') }}" method="post">
<div class="col-sm-6">
<h2>Already a user, Login here!</h2>
<div class="form-group">
<input class="form-control" name="username" placeholder="username" required>
</div>
<div class="form-group">
<input type="password" class="form-control" name="password" placeholder="password" required>
</div>
<div class="form-group">
<button class="btn btn-primary">Log In</button>
</div>
</div>
</form>
here is the flask snippet
#app.route("/login", methods=["POST"])
def login():
username = request.form.get("username")
password = request.form.get("password")
if db.execute("SELECT username FROM users WHERE username=:username AND password=:password", {"username": username, "password": password}).fetchone() == username:
session['username'] = username
return render_template("home.html")
return render_template("error.html", message="username or password is incorrect",prompt="alert alert-warning")
When I enter wrong creds, it prompts me to the wrong creds message, which I pretty much want. Now problem is if I add the correct creds, then also it is showing me the same message. My database is connected properly and there's no issue with that. Is something wrong with my way of writing the query, as I'm a beginner in Flask and SQL
fetchone returns a sequence (list), so the if test is never true.
From the python Sqlite3 doc:
fetchone()
Fetches the next row of a query result set, returning a single sequence, or None when no more data is available.
One option: Since the result of fetchone is a list, the element to compare with username would be the first member returned i.e. ....fetchone()[0].
Another option: Assuming username is unique, the query will return one row or no rows. fetchone will return None if there are no rows. None is falsey therefore the equality is not necessary in the if clause.
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']) !!}
Insert data into Wordpress database table from a custom form
I have worked with your example but I have a problem. I have error on the start. I get this message:
WordPress database error: [Cannot add or update a child row: a foreign
key constraint fails (prowebex_barbara.barbara_schedule, CONSTRAINT
barbara_schedule_ibfk_1 FOREIGN KEY (day_id) REFERENCES barbara_days
(id_day))]
INSERT INTO barbara_schedule (id, challenger, challenged,
date_match, day_id, term_start, term_end) VALUES ('', 'gfdgdfgdfg', 'gdfgfdgdf', '2015-11-30', '', '23:00', '00:59');
Data Submitted
Can you tell me how can I change this. I have already, truncate tables,delete both tables. I don't know what to do.
<?php
if(isset($_POST['submit'])) {
global $wpdb;
$id = sanitize_text_field($_POST['id']);
$challenger = sanitize_text_field($_POST['challenger']);
$challenged = sanitize_text_field($_POST['challenged']);
$date_match = sanitize_text_field($_POST['date_match']);
$day = sanitize_text_field($_POST['day_id']);
$term_start = sanitize_text_field($_POST['term_start']);
$term_end = sanitize_text_field($_POST['term_end']);
$table_name = $wpdb->prowebex_barbara.barbara_schedule;
$wpdb->insert($table_name, array(
'id' => $id,
'challenger' => $challenger,
'challenged' => $challenged,
'date_match' => $date_match,
'day_id' => $day,
'term_start' => $term_start,
'term_end' => $term_end,
),
array( '%s', '%s', '%s', '%s', '%s', '%s', '%s')
);
$msg = "Data Submited";
echo $msg;
}?>
<form action="" method="post" id="subForm">
<div>
<input type="hidden" name="id" id="iiihuu-iiihuu" placeholder="" />
<br>
<input type="text" name="challenger" id="iiihuu-iiihuu" placeholder="Izazivač" />
<br>
<input type="text" name="challenged" id="iiihuu-iiihuu" placeholder="Izazvani" />
<br>
<input type="date" name="date_match" id="iiihuu-iiihuu" placeholder="Datum" />
<br>
<select>
<option>I don't know how to do this</option>
</select>
<br>
<input type="time" name="term_start" id="iiihuu-iiihuu" placeholder="Termin od" />
<br>
<input type="time" name="term_end" id="iiihuu-iiihuu" placeholder="Termin do" />
<br>
<input type="submit" name="submit" value="Spasi" class ="submit_button" id="formSubmit" />
</div>
</form>
</div>
The errors look like that the custom tables actually have relationship with each other, not sure how the database structure is, but it looks like in order to create a record in barbara_schedule you will have to also create a record in barbara_days.
So in order to just check if this is the case you should pass a fake day_id. So replace $_POST['day_id'] with an existing day_id that already exists in the barbara_days table.
But if thats not the case, then here is a quick thought, do you have a require statement on the top of this file?
Usually this is needed in order to make an insert on custom tables besides the meta table.
require_once('LINK-TO/wp-load.php');
Secondly i am not sure, what this outputs
$table_name = $wpdb->prowebex_barbara.barbara_schedule;
but just in case, try to hardcode the table name like this
$table_name = $wpdb->prefix."table-name"
I have multiple html helpers. When I click login button I am disabling user_register div using jquery and when I enter details the username and password the model binder is able to bind properly but when I click Register I am disabling user_login div and enabling user_register div and when I enter the details only email and firstname is what the model binder is able to bind and not username, password. Is this becoz I am using the same html helpers more than once. How to handle this. I have the following code
<div class="user_login">
<label>Email / Username</label>
#Html.TextBoxFor(model => model.Email)
<br />
<label>Password</label>
#Html.TextBoxFor(model => model.Password)
<br />
<div class="action_btns">
<div class="one_half"><i class="fa fa-angle-double-left"></i>Back
</div>
<div class="one_half last">
<input type="submit" style="border: none" name="action" class="btn btn_red" value="Login" />
</div>
</div>
Forgot password?
</div>
<div class="user_register">
<label>Full Name</label>
#Html.TextBoxFor(model => model.First_Name)<br />
<label>Email Address</label>
#Html.TextBox(model=>model.Email)<br />
<label>User Name</label>
#Html.TextBoxFor(model => model.User_Name)<br />
<label>Password</label>
#Html.TextBox(model=>model.Password") <br />
</div>
The controller follows here
public ActionResult Index(Customer customer, string Action)
{
//something here
}
You have not shown you complete view, but assuming all those controls are generated inside one form element, then all controls will post back unless you make the inputs disabled. If so, then the first input with name="Email" is bound and the second one is ignored by the DefaultModelBinder. (since the first one is only hidden, its value is probably empty). Your script needs to ensure that the 2 inputs in the login section are disabled, for example
#Html.TextBoxFor(model => model.Email, new { id = "login-email" })
and
$('#login-email').prop('disabled', true);
Note the id attribute so you can select the correct one (and prevent duplicate id's which is invalid html.
An alternative would be to create 2 separate forms.