Login With Ajax - Version 1.1

Version Description

  • Fixed JavaScript for http to https support.
  • Added shortcut tag login_with_ajax()

=

Download this release

Release Info

Developer netweblogic
Plugin Icon 128x128 Login With Ajax
Version 1.1
Comparing to
See all releases

Code changes from version 1.0 to 1.1

Files changed (4) hide show
  1. login-with-ajax.js +40 -37
  2. login-with-ajax.php +17 -7
  3. readme.txt +8 -2
  4. widget/widget_out.php +1 -1
login-with-ajax.js CHANGED
@@ -1,45 +1,48 @@
1
  jQuery(document).ready( function($) {
2
  //Oh well... I guess we have to use jQuery ... if you are a javascript developer, consider MooTools if you have a choice, it's great!
3
- //Kudos to those that made the jQuery Form Plugin, which is used for the AJAX calls.
4
  //I'm biased, but form functionality already comes prepacked with MooTools :)
5
- $('#LoginWithAjax_Form').ajaxForm({
6
- dataType: 'json',
7
- success: function(data){
 
 
 
 
 
 
 
 
8
  $('#LoginWithAjax_Loading').remove();
9
- if(data.result == '1'){
10
- //Login Successful
11
- if( $('#LoginWithAjax_Status').length > 0 ){
12
- $('#LoginWithAjax_Status').attr('class','confirm').html("Login Successful, redirecting...");
13
- }else{
14
- $('<span id="LoginWithAjax_Status" class="confirm">Login Successful, redirecting...</span>').prependTo('#login-with-ajax');
15
- }
16
- if(data.redirect == null){
17
- window.location.reload();
 
 
 
 
18
  }else{
19
- window.location = data.redirect;
 
 
 
 
 
 
 
 
 
 
 
 
 
20
  }
21
- }else{
22
- //Login Failed
23
- //If there already is an error element, replace text contents, otherwise create a new one and insert it
24
- if( $('#LoginWithAjax_Status').length > 0 ){
25
- $('#LoginWithAjax_Status').attr('class','invalid').html(data.error);
26
- }else{
27
- $('<span id="LoginWithAjax_Status" class="invalid">'+data.error+'</span>').prependTo('#login-with-ajax');
28
- }
29
- }
30
- },
31
- error: function(XMLHttpRequest, textStatus, errorThrown){
32
- $('#LoginWithAjax_Loading').remove();
33
- //If there already is an error element, replace text contents, otherwise create a new one and insert it
34
- if( $('#LoginWithAjax_Status').length > 0 ){
35
- $('#LoginWithAjax_Status').attr('class','invalid').html('An error has occured. Please try again.');
36
- }else{
37
- $('<span id="LoginWithAjax_Status" class="invalid">An error has occured. Please try again.</span>').prependTo('#login-with-ajax');
38
  }
39
- },
40
- beforeSend: function(){
41
- $('<div id="LoginWithAjax_Loading"></div>').prependTo('#login-with-ajax');
42
- }
43
- });
44
-
45
  });
1
  jQuery(document).ready( function($) {
2
  //Oh well... I guess we have to use jQuery ... if you are a javascript developer, consider MooTools if you have a choice, it's great!
 
3
  //I'm biased, but form functionality already comes prepacked with MooTools :)
4
+ $('#LoginWithAjax_Form').submit(function(event){
5
+ //Stop event, add loading pic...
6
+ event.preventDefault();
7
+ $('<div id="LoginWithAjax_Loading"></div>').prependTo('#login-with-ajax');
8
+ //Sort out url
9
+ url = $('#LoginWithAjax_Form').attr('action');
10
+ url += (url.match(/\?/) != null) ? '&callback=?' : '?callback=?' ;
11
+ url += "&log="+$("#lwa_user_login").attr('value');
12
+ url += "&pwd="+$("#lwa_user_pass").attr('value');
13
+ url += "&login-with-ajax=login";
14
+ $.getJSON( url , function(data, status){
15
  $('#LoginWithAjax_Loading').remove();
16
+ if( data.result === true || data.result === false ){
17
+ if(data.result == '1'){
18
+ //Login Successful
19
+ if( $('#LoginWithAjax_Status').length > 0 ){
20
+ $('#LoginWithAjax_Status').attr('class','confirm').html("Login Successful, redirecting...");
21
+ }else{
22
+ $('<span id="LoginWithAjax_Status" class="confirm">Login Successful, redirecting...</span>').prependTo('#login-with-ajax');
23
+ }
24
+ if(data.redirect == null){
25
+ window.location.reload();
26
+ }else{
27
+ window.location = data.redirect;
28
+ }
29
  }else{
30
+ //Login Failed
31
+ //If there already is an error element, replace text contents, otherwise create a new one and insert it
32
+ if( $('#LoginWithAjax_Status').length > 0 ){
33
+ $('#LoginWithAjax_Status').attr('class','invalid').html(data.error);
34
+ }else{
35
+ $('<span id="LoginWithAjax_Status" class="invalid">'+data.error+'</span>').prependTo('#login-with-ajax');
36
+ }
37
+ }
38
+ }else{
39
+ //If there already is an error element, replace text contents, otherwise create a new one and insert it
40
+ if( $('#LoginWithAjax_Status').length > 0 ){
41
+ $('#LoginWithAjax_Status').attr('class','invalid').html('An error has occured. Please try again.'+status);
42
+ }else{
43
+ $('<span id="LoginWithAjax_Status" class="invalid">An error has occured. Please try again.</span>').prependTo('#login-with-ajax');
44
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
  }
46
+ });
47
+ });
 
 
 
 
48
  });
login-with-ajax.php CHANGED
@@ -4,7 +4,7 @@ Plugin Name: Login With Ajax
4
  Plugin URI: http://netweblogic.com/wordpress/plugins/login-with-ajax/
5
  Description: Ajax driven login widget. Customisable from within your template folder, and advanced settings from the admin area.
6
  Author: NetWebLogic
7
- Version: 1.0
8
  Author URI: http://netweblogic.com/
9
  Tags: Login, Ajax, Redirect, BuddyPress, MU, WPMU, sidebar, admin, widget
10
 
@@ -31,10 +31,9 @@ class LoginWithAjax {
31
  // Class initialization
32
  function LoginWithAjax() {
33
  //Make decision on what to display
34
- if ( function_exists('register_sidebar_widget') && !isset($_POST["login-with-ajax"]) ){
35
  //Enqueue scripts
36
- wp_enqueue_script( "login-with-ajax-form", path_join(WP_PLUGIN_URL, basename( dirname( __FILE__ ) )."/form.js"), array( 'jquery' ) );
37
- wp_enqueue_script( "login-with-ajax", path_join(WP_PLUGIN_URL, basename( dirname( __FILE__ ) )."/login-with-ajax.js"), array( 'jquery', 'login-with-ajax-form' ) );
38
  //Enqueue stylesheets
39
  if( file_exists(get_template_directory().'/plugins/login-with-ajax/widget.css') ){
40
  wp_enqueue_style( "login-with-ajax-css", get_template_directory_uri().'/plugins/login-with-ajax/widget.css' );
@@ -47,14 +46,14 @@ class LoginWithAjax {
47
  add_action('wp_logout', array(&$this, 'logoutRedirect'));
48
  add_action('wp_login', array(&$this, 'loginRedirect'));
49
 
50
- }elseif ( isset($_POST["login-with-ajax"]) ) {
51
  $this->ajax();
52
  }
53
  }
54
 
55
  // Decides what action to take from the ajax request
56
  function ajax(){
57
- switch ( $_POST["login-with-ajax"] ) {
58
  case 'login':
59
  //A login has been requested
60
  $this->ajaxLogin();
@@ -68,7 +67,13 @@ class LoginWithAjax {
68
 
69
  //Calls normal login and JSON encodes it
70
  function ajaxLogin(){
71
- echo json_encode($this->login());
 
 
 
 
 
 
72
  exit();
73
  }
74
 
@@ -139,6 +144,11 @@ function LoginWithAjaxInit(){
139
  $LoginWithAjax = new LoginWithAjax();
140
  }
141
 
 
 
 
 
 
142
  // Start this plugin once all other plugins are fully loaded
143
  add_action( 'init', 'LoginWithAjaxInit' );
144
 
4
  Plugin URI: http://netweblogic.com/wordpress/plugins/login-with-ajax/
5
  Description: Ajax driven login widget. Customisable from within your template folder, and advanced settings from the admin area.
6
  Author: NetWebLogic
7
+ Version: 1.1
8
  Author URI: http://netweblogic.com/
9
  Tags: Login, Ajax, Redirect, BuddyPress, MU, WPMU, sidebar, admin, widget
10
 
31
  // Class initialization
32
  function LoginWithAjax() {
33
  //Make decision on what to display
34
+ if ( function_exists('register_sidebar_widget') && !isset($_GET["login-with-ajax"]) ){
35
  //Enqueue scripts
36
+ wp_enqueue_script( "login-with-ajax", path_join(WP_PLUGIN_URL, basename( dirname( __FILE__ ) )."/login-with-ajax.js"), array( 'jquery' ) );
 
37
  //Enqueue stylesheets
38
  if( file_exists(get_template_directory().'/plugins/login-with-ajax/widget.css') ){
39
  wp_enqueue_style( "login-with-ajax-css", get_template_directory_uri().'/plugins/login-with-ajax/widget.css' );
46
  add_action('wp_logout', array(&$this, 'logoutRedirect'));
47
  add_action('wp_login', array(&$this, 'loginRedirect'));
48
 
49
+ }elseif ( isset($_GET["login-with-ajax"]) ) {
50
  $this->ajax();
51
  }
52
  }
53
 
54
  // Decides what action to take from the ajax request
55
  function ajax(){
56
+ switch ( $_GET["login-with-ajax"] ) {
57
  case 'login':
58
  //A login has been requested
59
  $this->ajaxLogin();
67
 
68
  //Calls normal login and JSON encodes it
69
  function ajaxLogin(){
70
+ $_POST['log'] = $_GET['log'];
71
+ $_POST['pwd'] = $_GET['pwd'];
72
+ $return = json_encode($this->login());
73
+ if( isset($_GET['callback']) ){
74
+ $return = $_GET['callback']."($return)";
75
+ }
76
+ echo $return;
77
  exit();
78
  }
79
 
144
  $LoginWithAjax = new LoginWithAjax();
145
  }
146
 
147
+ function login_with_ajax(){
148
+ global $LoginWithAjax;
149
+ $LoginWithAjax->widget();
150
+ }
151
+
152
  // Start this plugin once all other plugins are fully loaded
153
  add_action( 'init', 'LoginWithAjaxInit' );
154
 
readme.txt CHANGED
@@ -4,7 +4,7 @@ Contributors: netweblogic
4
  Tags: Login, Ajax, Redirect, BuddyPress, MU, WPMU, sidebar, admin, widget
5
  Requires at least: 2.7
6
  Tested up to: 2.8.2
7
- Stable tag: 1.0
8
 
9
  Add smooth ajax during login, avoid screen refreshes and choose where users get redirected to upon login/logout. Supports SSL, MU, and BuddyPress.
10
 
@@ -20,6 +20,12 @@ Another useful feature (which can be used without the widget) is login and logou
20
 
21
  If you find this plugin useful and would like to donate something, all we ask is you please add a link on your site to the plugin page on our blog or digg our plugin page [http://netweblogic.com/wordpress/plugins/login-with-ajax/](http://netweblogic.com/wordpress/plugins/login-with-ajax/) thanks!
22
 
 
 
 
 
 
 
23
  == Installation ==
24
 
25
  1. Upload this plugin to the `/wp-content/plugins/` directory and unzip it, or simply upload the zip file within your wordpress installation.
@@ -28,7 +34,7 @@ If you find this plugin useful and would like to donate something, all we ask is
28
 
29
  3. If you want login/logout redirections, go to Settings > Login With Ajax in the admin area and fill out the form.
30
 
31
- 4. Add the login with ajax widget to your sidebar.
32
 
33
  5. Happy logging in!
34
 
4
  Tags: Login, Ajax, Redirect, BuddyPress, MU, WPMU, sidebar, admin, widget
5
  Requires at least: 2.7
6
  Tested up to: 2.8.2
7
+ Stable tag: 1.1
8
 
9
  Add smooth ajax during login, avoid screen refreshes and choose where users get redirected to upon login/logout. Supports SSL, MU, and BuddyPress.
10
 
20
 
21
  If you find this plugin useful and would like to donate something, all we ask is you please add a link on your site to the plugin page on our blog or digg our plugin page [http://netweblogic.com/wordpress/plugins/login-with-ajax/](http://netweblogic.com/wordpress/plugins/login-with-ajax/) thanks!
22
 
23
+ == Changelog ==
24
+
25
+ = 1.1 =
26
+ * Fixed JavaScript for http to https support.
27
+ * Added shortcut tag login_with_ajax()
28
+
29
  == Installation ==
30
 
31
  1. Upload this plugin to the `/wp-content/plugins/` directory and unzip it, or simply upload the zip file within your wordpress installation.
34
 
35
  3. If you want login/logout redirections, go to Settings > Login With Ajax in the admin area and fill out the form.
36
 
37
+ 4. Add the login with ajax widget to your sidebar, or use login_with_ajax() in your template.
38
 
39
  5. Happy logging in!
40
 
widget/widget_out.php CHANGED
@@ -9,7 +9,7 @@
9
  echo $before_widget . $before_title . __('Log In') . $after_title;
10
  ?>
11
  <span id="LoginWithAjax_Status"></span>
12
- <form name="LoginWithAjax_Form" id="LoginWithAjax_Form" action="<?php echo site_url('wp-login.php') ?>" method="post">
13
  <table width='100%' cellspacing="0" cellpadding="0">
14
  <tr id="LoginWithAjax_Username">
15
  <td class="username_label">
9
  echo $before_widget . $before_title . __('Log In') . $after_title;
10
  ?>
11
  <span id="LoginWithAjax_Status"></span>
12
+ <form name="LoginWithAjax_Form" id="LoginWithAjax_Form" action="<?php echo site_url('wp-login.php', 'login_post') ?>" method="post">
13
  <table width='100%' cellspacing="0" cellpadding="0">
14
  <tr id="LoginWithAjax_Username">
15
  <td class="username_label">