javascript - Trouble with Wordpress Ajax Login System - 302 -
i'm trying create simple ajax login system wordpress. unfortunately, every time "wp_signon" function fired, system failed , information have 1 :
post myurl/wp-admin/admin-ajax.php - 302 found myurl/?login = failed - 200 found
so, whether try log in informations or not, js script goes in "error part" of ajax function.
can tell me doing wrong? appreciated!
many thanks!
js :
jquery(document).on('submit', loginform, function(event) { event.preventdefault(); var usernameval = jquery('.modal-login .login-form #user_login').val(); var passwordval = jquery('.modal-login .login-form #user_pass').val(); var remembermefield = jquery('.modal-login .login-form #rememberme'); var securityval = jquery('.modal-login .login-form #security').val(); if ( remembermefield.prop('checked') ) { var remembermeval = 'true'; } else { var remembermeval = 'false'; } jquery.ajax({ type : "post", url : data_front_end_users_management.ajaxurl, datatype: 'json', data: { action: 'authuserajax', username: usernameval, password: passwordval, rememberme: remembermeval, security: securityval }, success: function(data) { if ( data['answer'] === 1 ) { modalalert( msgrow, msgalert, msgcontent, false, 'alert-success', 'alert-danger', data['message'] ); } else { modalalert( msgrow, msgalert, msgcontent, false, 'alert-danger', 'alert-success', data['message'] ); } //end success }, error: function () { modalalert( msgrow, msgalert, msgcontent, false, 'alert-danger', 'alert-success', defaulterror ); } //end ajax }); //end jquery(document).on('submit', loginform, function(event) });
action :
function authuserajax() { $logincontroller = new felogincontroller(); $value = array(); $value['answer'] = 0; $value['message'] = ''; $username = trim($_post['username']); $password = trim($_post['password']); $rememberme = $_post['rememberme']; $security = $_post['security']; if ( $logincontroller->checkauthinfosfilled( $username, $password ) ) { $user = $logincontroller->userauth( $username, $password, $rememberme ); if ( $user ) { if ( is_wp_error( $user ) ) { $value['answer'] = 0; $value['message'] = $user->get_error_message(); } else { $value['answer'] = 1; $value['message'] = 'success.'; } //end if ( $user ) } else { $value['answer'] = 0; $value['message'] = 'wrong username or password.'; } } else { $value['answer'] = 0; $value['message'] = 'please, enter username , password.'; } $data = json_encode($value); die( $data ); //end authuserajax } add_action( 'wp_ajax_authuserajax','authuserajax' ); add_action( 'wp_ajax_nopriv_authuserajax','authuserajax' );
controller :
public function userauth( $username, $password, $rememberme ) { if ( check_ajax_referer( 'ajax-login-nonce', 'security' ) ) { $creds = array(); $creds['user_login'] = $username; $creds['user_password'] = $password; if ( $rememberme == 'true' || $rememberme == true ) { $creds['remember'] = true; } else { $creds['remember'] = false; } $user = wp_signon( $creds, false ); return $user; } else { return false; } //end userauth }
so, after hours of searching, found problem : method in class interfered ajax authentication system.
Comments
Post a Comment