Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Codeigniter Ajax Login issue
- $(document).keypress(function (e) {
- if (e.which == 13) {
- var login = $("#login").val();
- var pass = $("#pass").val();
- $('#login-block').removeBlockMessages().blockMessage('Please wait, cheking login...', {
- type: 'loading'
- });
- $.post("<?php echo base_url(); ?>index.php/login/validate_credentials/", {
- username: login,
- password: pass
- }, function (data) {
- if (data.error) {
- $('#login-block').removeBlockMessages().blockMessage(data.message, {
- type: 'error'
- });
- } else {
- document.location.href = data.redirect;
- }
- }, "json");
- }
- });
- function validate() {
- // CHECK LOGIN DETAILS
- $this->db-> select('first_name,last_name,usertype,id,products,mac');
- $this->db-> where('username', $this->input->post('username'));
- $this->db-> where('password', md5($this->input->post('password')));
- $query = $this->db->get('membership');
- if ($query->num_rows() > 0) {
- $data = array('usertype' => $row->usertype, 'userid' => $row->id, 'first_name' => $row->first_name, 'last_name' => $row->last_name, 'products' => $row->products, 'mac' = > $row->mac);
- return $data;
- }
- }
- if(data.error){
- $('#login-block').html('<p>'+data.message+'</p>);
- } else {
- document.location.href = data.redirect;
- }
- if($query->num_rows()==1)
- {
- $data2 = array(
- 'error' => false,
- 'redirect' => base_url().'index.php/site/home/'
- );
- $.getJSON('<?php echo base_url(); ?>index.php/login/validate_credentials/',{username: login, password: pass}, function(data) {
- if(data.error){
- $('#login-block').removeBlockMessages().blockMessage(data.message, {type: 'error'});
- } else {
- document.location.href = data.redirect;
- }
- });
Add Comment
Please, Sign In to add comment