i got a problem with my login script in a platform of creating native mobile app
the server side work perfectly
here is my test with postman
and this is the function that should redirect me to another page bit it don't
function auth() {
var login = js.getProperty('username', 'value');
var password = js.getProperty('password', 'value');
var url = 'http://meanlast.gear.host/user/login';
url = url + '&login=' + login + '&password=' + password;
var response = js.getDataFromUrl(url);
var jsonRep = JSON.parse(response);
if (jsonRep == "Login successful!") {
js.alert("ok");
js.navigateToPage('menu');
} else {
js.alert("error");
}
}
Your code
var url = 'http://meanlast.gear.host/user/login';
url = url + '&login=' + login + '&password=' + password;
produces
"http://meanlast.gear.host/user/login&login=login&password=password"
Do you see the problem with your querystring? You do not have a ?
Related
i am developing an application and loading an hosted application using the inapp browser plugin cordova-plugin-inappbrowser
I have gotten most of the functionalities to work but i am unable to get the part of loading an error message when he url does not load, it dosent just work and shows me an error message of the url where i have hosted my application instead.
Which could be embarrassing.
please i need help on this
This is what am working with below thanks for ur potential responses
// my child browser code, the main source of my app content
function fire(){
var ref = cordova.InAppBrowser.open('http://####################', '_blank', 'location=no,zoom=no,hardwareback=yes,clearsessioncache=yes,clearcache=no');
var myCallback = function(event) { alert(event.url); }
ref.addEventListener('loadstart', inAppBrowserbLoadStart);
ref.addEventListener('loadstop', inAppBrowserbLoadStop);
ref.addEventListener('loaderror', loadErrorCallBack);
ref.addEventListener('exit', inAppBrowserbClose);
}
function loadErrorCallBack(params) {
$('#status-message').text("");
var scriptErrorMesssage =
"alert('Sorry we cannot open that page. Message from the server is : "
+ params.message + "');"
inAppBrowserRef.executeScript({ code: scriptErrorMesssage }, executeScriptCallBack);
inAppBrowserRef.close();
inAppBrowserRef = undefined;
}
function executeScriptCallBack(params) {
if (params[0] == null) {
$('#status-message').text(
"Sorry we couldn't open that page. Message from the server is : '"
+ params.message + "'");
}
}
Your code is generally fine, but you have no control over the title of the alert() function. You can use some other techniques to display the error message. For example, you can use a div:
function loadErrorCallBack(params) {
$('#status-message').text("");
var scriptErrorMesssage = createMsg('Sorry we cannot open that page. Message from the server is: '
+ params.message);
inAppBrowserRef.executeScript({
code: scriptErrorMesssage
}, executeScriptCallBack);
inAppBrowserRef.close();
inAppBrowserRef = undefined;
}
function createMsg(msg) {
return 'var div = document.createElement("div");'
+ 'div.style.position = "absolute";'
+ 'div.style.top = "50%";'
+ 'div.style.left = "50%";'
+ 'div.style.width = "100px";'
+ 'div.style.height = "100px";'
+ 'div.style.color = "#f00";'
+ 'div.innerHTML = "' + msg + '";'
+ 'document.appendChild(div);'
}
I need to login throw google in my page. I got my clientID and set the redirect_uri path in Google Console but when I am trying to login it is giving me the following error. I am integrating this on my asp.net page.
Error:
400. That’s an error.
Error: redirect_uri_mismatch
Application: odiyaDoctor
You can email the developer of this application at: odiyadoctor#gmail.com
The redirect URI in the request: http://localhost/immediateHelp.aspx did not match a registered redirect URI.
My requirement is when user will login by google on first page(UserLogin.aspx) and after successful login the next page(i.e.immediateHelp.aspx) will come. I am explaining my all code and google credentials below.
UserLogin.aspx:
</i>
<script>
var OAUTHURL = 'https://accounts.google.com/o/oauth2/auth?';
var VALIDURL = 'https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=';
var SCOPE = 'https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email';
var CLIENTID = '*************************g96b1elfa8.apps.googleusercontent.com';
var REDIRECT = 'http://localhost/immediateHelp.aspx';
var LOGOUT = 'http://accounts.google.com/Logout';
var TYPE = 'token';
var _url = OAUTHURL + 'scope=' + SCOPE + '&client_id=' + CLIENTID + '&redirect_uri=' + REDIRECT + '&response_type=' + TYPE;
var acToken;
var tokenType;
var expiresIn;
var user;
var loggedIn = false;
function googleLogin() {
var win = window.open(_url, "windowname1", 'width=800, height=600');
var pollTimer = window.setInterval(function () {
try {
console.log(win.document.URL);
if (win.document.URL.indexOf(REDIRECT) != -1) {
window.clearInterval(pollTimer);
var url = win.document.URL;
acToken = gup(url, 'access_token');
tokenType = gup(url, 'token_type');
expiresIn = gup(url, 'expires_in');
win.close();
validateToken(acToken);
}
} catch (e) {
console.log('its error', e);
}
}, 500);
}
function validateToken(token) {
$.ajax({
url: VALIDURL + token,
data: null,
success: function (responseText) {
getUserInfo();
loggedIn = true;
window.location.href = "immediateHelp.aspx";
},
dataType: "jsonp"
});
}
function getUserInfo() {
$.ajax({
url: 'https://www.googleapis.com/oauth2/v1/userinfo?access_token=' + acToken,
data: null,
success: function (resp) {
user = resp;
console.log('user info',user);
$('#imgHolder').attr('src', user.picture);
},
dataType: "jsonp"
});
}
function gup(url, name) {
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regexS = "[\\#&]" + name + "=([^&#]*)";
var regex = new RegExp(regexS);
var results = regex.exec(url);
if (results == null)
return "";
else
return results[1];
}
</script>
In the above page the bellow error is coming in catch section.
at http://localhost:3440/UserLogin.aspx:92:32
UserLogin.aspx:103 its error DOMException: Blocked a frame with origin "http://localhost:3440" from accessing a cross-origin frame.
at Error (native)
clientID set in google.
Client ID for web application
Client ID
***************************************1ctsjaeg96b1elfa8.apps.googleusercontent.com
Client secret
*********oGbT13hv3S
Redirect URIs
https://localhost/immediateHelp.aspx
JavaScript origins
https://localhost
Here i need when user will logged in successfully,it will redirect to the immediateHelp.aspx page and in this page user can do the logout.Please help me to resolve these errors.
`"http://localhost/immediateHelp.aspx" != "https://localhost/immediateHelp.aspx"
The URL must be character perfect
I try these code but it generate error dialog box with "An unexpected error occurred and the application will reload" and application reload successfully
$email.click(crm_core.callback_function(function () {
var emailaddress = contact.email();
if (emailaddress == '')
return;
emailaddress = emailaddress.trim();
var newurl = 'mailto:' + contact.prompt() + " <" + emailaddress + ">";
window.location = newurl;
}));
My Question is how to open default mail provider in my system to compose mail from my app
You have to encode your url. Example space => %20, < => %3C, > => %3E
I appreciate any help with those familiar with the LinkedIn JavaScript API. Question: How do I pull in the phone number and email from the field array. In my example, posted to a php script, both phoneNumber and emailAddress are undefined when set to $_POST[''];:
<script type="text/javascript">
//Runs when the JavaScript framework is loaded
function onLinkedInLoad() {
IN.UI.Authorize().params({"scope":["r_fullprofile", "r_emailaddress", "r_contactinfo"]}).place();
IN.Event.on(IN, "auth", onLinkedInAuth);
}
//Runs when the viewer has authenticated
function onLinkedInAuth() {
IN.API.Profile("me").fields("id,firstName,lastName,phoneNumbers,emailAddress,positions").result(displayProfiles);
}
// 2. Runs when the Profile() API call returns successfully
function displayProfiles(profiles) {
var p = profiles.values[0];
var phone = profiles.values[0].phoneNumbers;
for (var i in p.positions.values) {
var pos = p.positions.values[i];
if (pos.isCurrent)
var company = pos.company.name;
}
//AJAX call to pass back vars to server
var http = new XMLHttpRequest();
var postdata= "id=" + p.id + "&fName=" + p.firstName + "&lName=" + p.lastName + "&phone=" + phone + "&email1=" + p.emailAddress + "&company=" + company;
http.open("POST", "../inc/linkedin.php", true);
use fields like this http://developer.linkedin.com/documents/profile-fields
Try this...
IN.API.Profile("me")
.fields('id,email-address,first-name,last-name,date-of-birth,phone-numbers,positions,num-connections')
.result(displayProfiles)
.error(displayErrors);
I'm trying to get my facebook graph oauth setup using javascript's window location methods.
Here is my code so far:
function fbLog() {
var clientID = '11502353444318540727';
var redirecturi = 'http://google.com';
var clientSecret = '6987d02323442423231f8b9da767b060e9';
var codeURI;
$('#fbLogin').click(function() {
window.location = 'https://graph.facebook.com/oauth/authorize?client_id=' + clientID + '&display=touch&redirect_uri='+ redirecturi + '&type=user_agent';
codeURI = window.location.href;
codeURI.split('=');
console.log(codeURI);
codeURI = codeURI.split('=');
codeURI = codeURI[1];
console.log(codeURI);
codeURI = codeURI.split('#');
codeURI = codeURI[0];
console.log('mega fun');
window.open = 'https://graph.facebook.com/oauth/access_token?client_id=' + clientID + '&redirect_uri=' + redirecturi + '&client_secret=' + clientSecret + '&code=' + codeURI
});
}
when I set codeURI to window.location.href, is that original call back page dead?
I'm super confused. Have I switched to a different window when I try to get the codeURI?
You have to assume that as soon as you set window.location, the browser will load a new page and all code on the current page will stop running. Don't try to do anything afterwards.
As far as I can tell, all you need here is to do things in a different order.