JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsWeb DesignJavaScript Development
The ASP Free website provides in-depth information on the latest developer tools available from Microsoft. Our cadre of writers, highly experienced industry experts, reveals the best ways to use established technologies as well as new and emerging technologies. Our coverage of Microsoft's development and administration technologies is among the most respected in the IT industry today.

ASP Free and Iron Speed Designer are giving away $5,500+ in FREE licenses. Iron Speed's RAD CASE toolset can save up to 80% of your coding time. One free license per week, one perpetual license per month!
Download and Activate to enter!

Intel® Graphics Performance Analyzers is a powerful tool suite for analyzing and optimizing your games, media, and graphics-intensive applications. Used by some of the best developers on the planet, Intel GPA lets you maximize your app’s performance.


Tutorials
| Forums

Download to Enter
| Contest Rules

DOWNLOAD INTEL® GPA FOR FREE

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old May 22nd, 2007, 04:08 PM
vipersniper vipersniper is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2006
Posts: 70 vipersniper User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 51 m 14 sec
Reputation Power: 6
AJAX - redirect after login is validated

I am validating login information via AJAX and that works fine. However, I want to redirect the page to the "secure dashboard" once the user has entered in valid username/password information. How would you go about doing this?

I tried sending headers back via php, but as I have read in other forums, it only redirects that particular <DIV> to the redirection URL.

I do not believe that I need any code up here because it is kind of generic in nature.

Any help would be great. Thanks!

Reply With Quote
  #2  
Old May 22nd, 2007, 04:22 PM
huyaroo's Avatar
huyaroo huyaroo is offline
:)
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Oct 2006
Location: IL
Posts: 1,520 huyaroo User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)huyaroo User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)huyaroo User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)huyaroo User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)huyaroo User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)huyaroo User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)huyaroo User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)huyaroo User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)huyaroo User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)huyaroo User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)huyaroo User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)  Folding Points: 303 Folding Title: Novice Folder
Time spent in forums: 2 Weeks 6 Days 2 h 36 m 42 sec
Reputation Power: 438
Use window.location='newURL.html'; once your javascript returns a success message.
__________________



shinygears | twinarrow

Reply With Quote
  #3  
Old May 22nd, 2007, 04:37 PM
vipersniper vipersniper is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2006
Posts: 70 vipersniper User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 51 m 14 sec
Reputation Power: 6
Quote:
Originally Posted by huyaroo
Use window.location='newURL.html'; once your javascript returns a success message.


I tried that, but doesn't work

Right now I have it returning "You have logged in successful" just to make sure that it did indeed work. So, then I tried returning "<script type='text/javascript'>window.location='newURL'</script>", but that didn't work

Reply With Quote
  #4  
Old May 22nd, 2007, 04:40 PM
huyaroo's Avatar
huyaroo huyaroo is offline
:)
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Oct 2006
Location: IL
Posts: 1,520 huyaroo User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)huyaroo User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)huyaroo User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)huyaroo User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)huyaroo User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)huyaroo User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)huyaroo User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)huyaroo User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)huyaroo User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)huyaroo User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)huyaroo User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)  Folding Points: 303 Folding Title: Novice Folder
Time spent in forums: 2 Weeks 6 Days 2 h 36 m 42 sec
Reputation Power: 438
You don't print that out using innerHTML or whatever. Can you post a snippet of your code? Right around where you are printing the "You have logged in successful" message.

Reply With Quote
  #5  
Old May 22nd, 2007, 04:50 PM
vipersniper vipersniper is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2006
Posts: 70 vipersniper User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 51 m 14 sec
Reputation Power: 6
Here is the form html


Code:
  <form action="#" method="post" name="agentLogin">
	<div style="color:#FFFFFF;position:relative;background-image:url(../../../img/login-background.gif); width:365px; height:227px; background-repeat:no-repeat;" id="login-table">
	<table style=" position:relative; left:-10px;margin-top:80px;">
		<tr>
			<td align="right">Username: </td>
			<td><input tabindex="1" type="text" id="agentUsername" name="agentUsername" /></td>
		</tr>
		<tr>
			<td align="right">Password: </td>
			<td><input tabindex="2" type="password" id="agentPassword" name="agentPassword" /></td>
		</tr>
		<tr>
			<td align="right"><span style="font-size:90%; color:#ddd">Remember Me:</span></td>
			<td align="left"><input onclick="javascript:login()" tabindex="4" style="float:right; font-weight:bold;" type="submit" value="LOGIN" name="agentLogin" /><input tabindex="3" style="float:left;" name="rememberMe" id="rememberMe" type="checkbox" value="y" /></td>
		</tr>
		<tr>
			<td style="padding-top:10px;" colspan="2" align="center"><a tabindex="5" class="login-link" href="#" onclick="showForgotPassword()">Forgot Password |</a> <a tabindex="6" class="login-link"  href="new-user.php">I'm A New Agent</a></td>
		</tr>
	</table>
	</div>
  </form>


Here is the ajax function that is called when the form is submitted:

Code:
function login() {
	var user = document.getElementById('agentUsername').value;
	var pass = document.getElementById('agentPassword').value;
	var remember;
	
	if(document.agentLogin.rememberMe.checked) {
		remember = "y";
	}
	else {
		remember = "n";
	}
	
	new Ajax.Updater('errors', 'check.php?login=true&auser='+user+'&apass='+pass+'&remember='+remember);
	new Effect.Highlight('errors', {startcolor:'#ff000',endcolor:'#ff99ff', restorecolor:'#ff99ff'});
}


Here is the PHP function that is run to log the user in and return the text:

PHP Code:
function login($u,$p,$remember) {
    if(
$u == "" or $p == "") {
        echo 
"Please enter a username and a password";
    }
    else {
        
dbConnect();
        
        
// Queries the database
        
$sql "
            SELECT bg_username,bg_password
            FROM agents
            WHERE bg_username = '$u'
            AND bg_password = '$p'
        "
;
        
$res mysql_query($sql) or die(mysql_error());
        
$num mysql_num_rows($res);
        
        
// 
        
if($num == 1) {
            echo 
"Success!"
        }
        else {
            echo 
"Incorrect login information, please try again";
        }
    }


Reply With Quote
  #6  
Old May 22nd, 2007, 05:18 PM
huyaroo's Avatar
huyaroo huyaroo is offline
:)
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Oct 2006
Location: IL
Posts: 1,520 huyaroo User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)huyaroo User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)huyaroo User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)huyaroo User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)huyaroo User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)huyaroo User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)huyaroo User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)huyaroo User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)huyaroo User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)huyaroo User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)huyaroo User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)  Folding Points: 303 Folding Title: Novice Folder
Time spent in forums: 2 Weeks 6 Days 2 h 36 m 42 sec
Reputation Power: 438
Are you using prototype? It seems like you need to add a response handler for your AJAX call so that you can differentiate between a successful login and one with errors. You can do that by adding another method using the onComplete option.

Your new method would look something like this:

Code:
function checkLogin(response)
{
 if (response == "Success!") {
   window.location='newurl.html';
 } else {
  alert("You have something wrong in your form.");
 }
}


example of an AJAX call with onComplete:

Code:
var ajax = new Ajax.Updater(
         'datestr',        // DIV id (XXX: doesnt work?)
         'date.cgi',        // URL
         {                // options
         method:'get',
             onComplete: checkLogin
             });
Comments on this post
vipersniper agrees!

Reply With Quote
  #7  
Old May 23rd, 2007, 02:24 PM
vipersniper vipersniper is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2006
Posts: 70 vipersniper User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 13 h 51 m 14 sec
Reputation Power: 6
Thank you, this works great now. Thank you!

Reply With Quote
  #8  
Old October 18th, 2007, 03:25 AM
oliever oliever is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2007
Posts: 2 oliever User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 m 54 sec
Reputation Power: 0
Quote:
Originally Posted by huyaroo

Code:
function checkLogin(response)
{
 if (response == "Success!") {
   window.location='newurl.html';
 } else {
  alert("You have something wrong in your form.");
 }
}



Hi. I was also thinking about this solution. But I think this method is vulnerable to hackers. Anyone who know js can just call checkLogin('success'); and viola! logged in. Is there a better way to handle safe login? Thanks!

Reply With Quote
  #9  
Old October 18th, 2007, 04:04 AM
sarav_dude's Avatar
sarav_dude sarav_dude is offline
Expert Debugger
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Apr 2006
Location: Dev Shed Forums (-_^)v
Posts: 1,021 sarav_dude User rank is General 5th Grade (Above 100000 Reputation Level)sarav_dude User rank is General 5th Grade (Above 100000 Reputation Level)sarav_dude User rank is General 5th Grade (Above 100000 Reputation Level)sarav_dude User rank is General 5th Grade (Above 100000 Reputation Level)sarav_dude User rank is General 5th Grade (Above 100000 Reputation Level)sarav_dude User rank is General 5th Grade (Above 100000 Reputation Level)sarav_dude User rank is General 5th Grade (Above 100000 Reputation Level)sarav_dude User rank is General 5th Grade (Above 100000 Reputation Level)sarav_dude User rank is General 5th Grade (Above 100000 Reputation Level)sarav_dude User rank is General 5th Grade (Above 100000 Reputation Level)sarav_dude User rank is General 5th Grade (Above 100000 Reputation Level)sarav_dude User rank is General 5th Grade (Above 100000 Reputation Level)sarav_dude User rank is General 5th Grade (Above 100000 Reputation Level)sarav_dude User rank is General 5th Grade (Above 100000 Reputation Level)sarav_dude User rank is General 5th Grade (Above 100000 Reputation Level)sarav_dude User rank is General 5th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 1 Week 6 Days 14 h 33 m 57 sec
Reputation Power: 1299
Send a message via Yahoo to sarav_dude Send a message via Google Talk to sarav_dude
You did not get the point , js is only used for redirection in this case, login process is dependent on the server side script so wont affect much, calling checkLogin('success'); will redirect em but not logged in.
Quote:
Originally Posted by oliever
Hi. I was also thinking about this solution. But I think this method is vulnerable to hackers. Anyone who know js can just call checkLogin('success'); and viola! logged in. Is there a better way to handle safe login? Thanks!
__________________
Online bookmarking

Reply With Quote
  #10  
Old October 18th, 2007, 04:51 AM
oliever oliever is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2007
Posts: 2 oliever User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 m 54 sec
Reputation Power: 0
Quote:
Originally Posted by sarav_dude
You did not get the point , js is only used for redirection in this case, login process is dependent on the server side script so wont affect much, calling checkLogin('success'); will redirect em but not logged in.


I get your point. Thank for clarifying it.

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignJavaScript Development > AJAX - redirect after login is validated


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.

© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 8 - Follow our Sitemap