How to integrate remember me after successful login using jquery ajax?
You can make this by using cookie.
try following code:
//php (controller):
//after success login
if($remember){
//set cookie
$this->input->set_cookie('email', $email, 86500);
$this->input->set_cookie('password', $password, 86500);
}else
{
//delete cookie
delete_cookie('email');
delete_cookie('password');
}
view: login.php
//set cookie value if checked remember me.
<div class="row">
<input class="form-control" value="<?php if (get_cookie('email')) { echo get_cookie('email'); } ?>" placeholder="" type="email" id="elogin">
<input class="form-control" value="<?php if (get_cookie('password')) { echo get_cookie('password'); } ?>" placeholder="" type="password" id="plogin">
<input name="optionsCheckboxes" id="remember_me" type="checkbox" <?php if (get_cookie('email')) { ?> checked="checked" <?php } ?>>Remember Me
</div>
HTML5 localstorage remember me in login box
You shouldn't listen to the click events of specific form elements but rather to the submit event of the form.
When the form is submitted, you have the information from all fields at hand and the order in which the user fills in the form fields doesn't matter.
$('#my-form').on('submit', function() {
/* place your logic here… */
});
How to implement remember me functionality in react js
Finally resolved the problem,
I used cookies for when the remember me is unticked
and local storage for when remember me is ticked
here's the code for the same
https://github.com/guneethind/login-signup/tree/cookies-implementaion
Creating a remember me function
The common and more basic way to do this is to write a cookie with the username and another with the hashed password. But i think you should write the cookies with PHP, JS is a client-side language so you can't hide your salt, for instance.
How to loging to django with login form? With or without Ajax
Django authenticate
takes keyword arguments username
and password
for the default case with request
as optional parameter.
In your views.py
you pass user
as parameter in authenticate change it to username
.
The default authentication
returns None if user is in-active so you don't have to check for is_active
if you are using default authentication.
Change your views.py
as
def ajaxlogin(request):
is_ajax = request.headers.get('X-Requested-With') == 'XMLHttpRequest'
if is_ajax and request.method == "POST":
username = request.POST['username']
password = request.POST['password']
user = authenticate(username=username, password=password)
if user is not None :
login(request, user)
else:
pass
return render('./ecommerce/checkout.html')
Also set contentType
as application/x-www-form-urlencoded
or leave it at the default by omitting the contentType
key.
Related Topics
Regex for Mobile Number With or Without Country Code
How to Hash Passwords Before Posting and Then Using Bcrypt
How to Assign [(Ngmodel)] With an Empty/Null/Undefined Object - Angular 4
Javascript Regex: Replace Hyphen Between Characters Only (Not Spaces)
How to Count the Entire Number of Rows in a Datatable
React Router Dom Returns a Blank Page When Going to a Particular Route
Call 2 Functions Within Onchange Event
Angular: Toggle Active Class on Only Button the Current Clicked Button (Not Using *Ngfor)
Vuejs Set Active Class, When One Li Element Clicked in V-For Loop
How to Make Select Option Disable
React-Router Go Back a Page How to Configure History
Remove Duplicate Objects from Json Array
Failed to Execute Query Selector on Document, Id Is Not a Valid Selector
Referenceerror: Cannot Access 'Player' Before Initialization
Maxlength Does Not Work React Js
Uploading a File from a Bootstrap Modal Using Ajax
Android Webview Not Loading Website Properly
How to Import Modules from All Files in a Directory, Using a Wildcard