Facebook Login Button Retrieving Wrong User Email Sometimes -


i have social network called recommendation book , using facebook , google plus login buttons register users first time click button , log them second time click button. other day talking girl , showing website , tried register on website using facebook login button , system logged in user's account, instead of registering her. sure bug facebook made facebook system return email person , wondering if issue @ of facebook login button log users in wrong account. pasting code, mobile version, , wanna ask if there wrong on code, working, make facebook system return user's email user tried login? issue @ facebook login button logging users in wrong account?

<script type="text/javascript">   <!--    $(document).ready(function(){    	$(".spinnertr").hide();    });    function mytrim(x) {  	return x.replace(/^\s+|\s+$/gm,'');  }    function setcookiesrb(id) {  	var date = new date();  	date.settime(date.gettime() + (365 * 24 * 60 * 60 * 1000));    	var url = "http://localhost:8989/login.jsp";    	if(url.tolowercase().indexof("localhost:8989") >= 0) {  		document.cookie = "isrecommenderlogged=yes; expires="+date.togmtstring()+"";  		document.cookie = "recommenderid="+id+"; expires="+date.togmtstring()+"";  	} else {  		document.cookie = "isrecommenderlogged=yes; expires="+date.togmtstring()+"; domain=recommendationbook.com;path=/";  		document.cookie = "recommenderid="+id+"; expires="+date.togmtstring()+"; domain=recommendationbook.com;path=/";  	}  }    /*   *   * facebook login   *   */    function statuschangecallback(response) {  	if(response.status === 'connected') {  		$(document).ready(function(){  			$(".googlefacebookbuttons").hide();  			$(".spinnertr").show();  		});  		register();  	} else if(response.status === 'not_authorized') {  		  	} else {  		// person not logged facebook, we're not sure if logged app or not.  	}  }    function checkloginstate() {    	fb.login( function(response) {  		fb.getloginstatus(function(response) {  			statuschangecallback(response);  		});  	}, { scope: 'public_profile,email,user_birthday' } );    }    window.fbasyncinit = function() {  	fb.init({  		appid : '1054429214574465',  		cookie : true,  		xfbml : true,  		version : 'v2.2'  	});    	fb.getloginstatus(function(response) {  		// statuschangecallback(response);  	});  };    (function(d, s, id) {      var js, fjs = d.getelementsbytagname(s)[0];      if (d.getelementbyid(id)) return;      js = d.createelement(s); js.id = id;      js.src = "//connect.facebook.net/en_us/sdk.js";      fjs.parentnode.insertbefore(js, fjs);  }(document, 'script', 'facebook-jssdk'));    function register() {  	fb.api('/me', function(response) {    		var name = "";  		var email = "";  		var gender = "";  		var locale = "";  		var birthday = "";    		if(typeof response.name != "undefined") {  			name = ""+response.name+"";  		}    		if(typeof response.email != "undefined") {  			email = ""+response.email+"";  		}    		if(typeof response.gender != "undefined") {  			gender = ""+response.gender+"";  		}    		if(typeof response.birthday != "undefined") {  			birthday = ""+response.birthday+"";  		}    		if(typeof response.locale != "undefined") {  			locale = ""+ response.locale+"";  		}    		var posting = $.post("loginfacebook.jsp", {name: name, email: email, gender: gender, locale: locale, birthday: birthday});    		posting.done(function(data) {    			setcookiesrb(""+mytrim(data)+"");    			window.location.href = "http://recommendationbook.com/recommender.jsp?id="+mytrim(data)+"";  		});  	});  }    //-->  </script>
<!doctype html>    <html lang="en-us">    <head>     <title>recommendation book</title>     <meta name="keywords" content="recommendation book login" />  <meta name="description" content="recommendation book login page" />    <meta http-equiv="cache-control" content="no-cache, no-store, must-revalidate" />  <meta http-equiv="pragma" content="no-cache" />  <meta http-equiv="expires" content="0" />    <body>    <div class="geral">    	<div class="corpo">    		<form method="post" id="login" action="dologin.jsp" enctype="multipart/form-data">  				<table>  				<tbody>    				<tr class="googlefacebookbuttons"><td class="tdleft">  					<div style="width: 100%; text-align: center">  					facebook login , registration<br />  					<a href="#" onclick="checkloginstate();"><img src="./img/static/facebookbuttonbig.png" border="0" alt=""></a>  					</div>  				</td></tr>    				<tr class="spinnertr"><td>wait... <div id="spinner" class="spinner" style="display: inline;"><img width="200" height="200" src="./img/static/ajax-loader-goldenrod.gif" alt="" /></div></td></tr>    				</tbody>  				</table>  		</form>    	</div>    </div>    </body>     </html>

i found error. on side. happens thought facebook return email if user succeed login. user logging through facebook login button can deny permission , facebook system return junk or generic facebook email. 1 of users registered , wasn't checking placed junk facebook returned in place of email , didn't notice. later when tried register girl mentioning facebook system returned same junk , that's why logged in account of girl. fix placed following condition in javascript:

var emailregex = new regexp("^([a-za-z0-9_.-]+)@([a-z0-9_.-]+)$");    if(!emailregex.test(email) || email.tolowercase().indexof("facebook.com") >= 0) { }


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -