How to Create a Remember Me Function in Login Without Using Form in JavaScript or Jquery

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



Leave a reply



Submit