This topic is locked
[SOLVED]

 Capture Login Json

6/3/2014 9:29:59 AM
ASPRunnerPro General questions
lefty author

I need to capture login data from asprunner application to an external hybrid mobile application in json format.

basically want to get login data and return as json data in my external mobile app? Anyone have any ideas on this. I see image upload returns json format . Do I need to write a plugin for this or is there an easer method?

admin 6/3/2014

Create a new ASP file named, for instance, mydata.asp. Here is the sample code you can use there.

<%

Response.ContentType = "application/json"

Response.Write("{ ""UserID"":""" & Session("UserID") & """ }")

%>


Once user is logged in you can use http://yourwebsite.com/yourproject/mydata.asp to retrieve UserID in JSON format.

lefty author 6/7/2014

I guess I worded this wrong . I need to do the opposite . My question is; How can I call ASPrunner login session in Javascript with an external application in JSON format. Basically I need to GET/POST data in my mobile index.html page to ASPrunner login.asp so session is saved and application logs in. I may need an ASp service page . But don't know how it could connect to ASPruner. Just trying to do a login call and then webview on mobile app. But stuck with the login . I also use Md5 encrytion so ??????

admin 6/8/2014

This is exactly what you need. You can call this custom ASP page using JavaScript and get results in JSON format.

lefty author 6/12/2014



This is exactly what you need. You can call this custom ASP page using JavaScript and get results in JSON format.



I see how this would work if I am already logged in to ASPrunner application but my external mobile app needs to login first. I am trying to use the hybrid application to login to asprunner and then send it to my web mobile view menu.asp in ASPrunner project. So basically I am trying to post login info from hybrid mobile application to ASPrunner then redirect to menu.asp . Something like http://www.mywebsite.com/customlogin.asp?returnformat=JSON
Thought I can use existing code in ASPrunner so external mobile app can just go to web application(ASPRunner) mobile view after login.

admin 6/12/2014

I see what you mean. In your mobile application you can perform a POST to login.asp sending username/password and then you can use the sample code I provided in AfterSuccessfulLogin event to return login data.
Another option - if AfterSuccessfulLogin event you can redirect the user to the same custom mydata.asp file that would return the same login data in JSON format.

G
gonzalosb 6/12/2014

hi John,

what you can do is a login over URL
in your app ones you get the Username and Password transfer that over an URL to the web application like:
www.host.com/login.asp?Username=john&Password=1234
this is what i am working on one of my post for a different use but it can be implemented to your need
as i say i am working on this because i get only to transfer the username but not the password. here is the link

lefty author 6/15/2014



hi John,

what you can do is a login over URL
in your app ones you get the Username and Password transfer that over an URL to the web application like:
www.host.com/login.asp?Username=john&Password=1234
this is what i am working on one of my post for a different use but it can be implemented to your need
as i say i am working on this because i get only to transfer the username but not the password. here is the link



I tried putting the code admin supplied me in after login event. My code below does not seem to get the data and when someone logs in on server side it also opens application/json . When testing in native app using javascript to post to the url and get Json callback . Nothing happend I get a white screen when running the application on a mobile device. I tested my mobile application with just index.html and the form works . But ends there. Got this from My link. I think this can also be a security issue by using url for this purpose.
Here is my Javascript that posts to service.
Called Main.js
function init() {

document.addEventListener("deviceready", deviceReady, true);

delete init;

}
function checkPreAuth() {

console.log("checkPreAuth");

var form = $("#loginForm");

if(window.localStorage["username"] != undefined && window.localStorage["password"] != undefined) {

$("#username", form).val(window.localStorage["username"]);

$("#password", form).val(window.localStorage["password"]);

handleLogin();

}

}
function handleLogin() {

var form = $("#loginForm");

//disable the button so we can't resubmit while we wait

$("#submitButton",form).attr("disabled","disabled");

var u = $("#username", form).val();

var p = $("#password", form).val();

if(u != '' && p!= '') {

$.post("http://www.mywebsite.com/output/login.asp?username="Userid"&password="password"";,{username:u,password:p}, function(res) {

if(res == true) {

//store

window.localStorage["username"] = u;

window.localStorage["password"] = p;

$.mobile.changePage("some.html");

} else {

navigator.notification.alert("Your login failed", function() {});

}

$("#submitButton").removeAttr("disabled");

},"json");

} else {

navigator.notification.alert("You must enter a username and password", function() {});

$("#submitButton").removeAttr("disabled");

}

return false;

}
function deviceReady() {

console.log("deviceReady");

$("#loginPage").on("pageinit",function() {

console.log("pageinit run");

$("#loginForm").on("submit",handleLogin);

checkPreAuth();

});

$.mobile.changePage("#loginPage");
And My html form file index.html
<!DOCTYPE HTML>

<html>

<head>

<meta name="viewport" content="width=device-width, initial-scale=1">

<meta http-equiv="Content-type" content="text/html; charset=utf-8">

<title>Login Demo form</title>

<link rel="stylesheet" href="http://code.jquery.com/mobile/latest/jquery.mobile.min.css"; />

<script src="jquery.mobile/jquery-1.7.2.min.js"></script>

<script src="jquery.mobile/jquery.mobile-1.1.0.min.js"></script>

<script src="main.js"></script>

</head>
<body onload="init()">
<div id="launcherPage" data-role="page">

<!-- I'm just here waiting for deviceReady -->

</div>
<div id="loginPage" data-role="page">
<div data-role="header">

<h1>Login Demo</h1>

</div>
<div data-role="content">
<form id="loginForm">

<div data-role="fieldcontain" class="ui-hide-label">

<label for="username">Username:</label>

<input type="text" name="username" id="username" value="" placeholder="username" />

</div>
<div data-role="fieldcontain" class="ui-hide-label">

<label for="password">Password:</label>

<input type="password" name="password" id="password" value="" placeholder="password" />

</div>
<input type="submit" value="Login" id="submitButton">

</form>
</div>
<div data-role="footer">

<h4>&copy; My Footer</h4>

</div>
</div>
</body>

</html>

admin 6/16/2014

I'm not sure why would you need to add any extra files while it can be all handled by ASPRunnerPro application itself.

lefty author 6/16/2014



I'm not sure why would you need to add any extra files while it can be all handled by ASPRunnerPro application itself.



Native apps cannot have asp in them , they can only make calls to asp or php etc....
I am trying to have a native/hybrid mobile application so that the user can store some data on device ex. username and password and eventually some other data. Also instead of having to put a tile on each mobile device they log from or enter the url , they can just download a private application. In the future I plan to use geolocation of the device for gathering data and accessing the mobile device's camera. SO basically they will be using both the hybrid application and the ASPrunner application when they are on a desktop which will have all the features of the already existing application. Just need to get started by using same credentials on the client sice as the server side and use the same database on the server side. I thought I could just build a form and submit to login.asp in asprunner, but seems I need some type of service call to this. Need to callback json data userid and password. I use Phonegap build service to build native application which allows me to use javascript / Html 5 and CSS in the mobile app.
I am open to another route if anyone has any ideas. Thanks

admin 6/16/2014

What you need to do is to perform a POST query from your native application to login.asp. Before doing that use Chrome developers tools or Firebug to see what exactly browser posts to login.asp and do the same thing from your native app.

lefty author 7/17/2014



What you need to do is to perform a POST query from your native application to login.asp. Before doing that use Chrome developers tools or Firebug to see what exactly browser posts to login.asp and do the same thing from your native app.



So here is my post query from hybrid app
function init() {

document.addEventListener("deviceready", deviceReady, true);

delete init;

}
function checkPreAuth() {

console.log("checkPreAuth");

var form = $("#loginForm");

if(window.localStorage["username"] != undefined && window.localStorage["password"] != undefined) {

$("#username", form).val(window.localStorage["username"]);

$("#password", form).val(window.localStorage["password"]);

handleLogin();

}

}
function handleLogin() {

var form = $("#loginForm");

//disable the button so we can't resubmit while we wait

$("#submitButton",form).attr("disabled","disabled");

var u = $("#username", form).val();

var p = $("#password", form).val();

if(u != '' && p!= '') {

$.post("http://www.mygwebsite.com/Output10/login.asp", {username:u,password:p}, function(res) {

if(res == true) {

//store

window.localStorage["username"] = u;

window.localStorage["password"] = p;

$.mobile.changePage("some.html");

} else {

navigator.notification.alert("Your login failed", function() {});

}

$("#submitButton").removeAttr("disabled");

},"json");

} else {

navigator.notification.alert("You must enter a username and password", function() {});

$("#submitButton").removeAttr("disabled");

}

return false;

}
function deviceReady() {

console.log("deviceReady");

$("#loginPage").on("pageinit",function() {

console.log("pageinit run");

$("#loginForm").on("submit",handleLogin);

checkPreAuth();

});

$.mobile.changePage("#loginPage");

}
If I added application/json after successfull login then desktop web application would get the same result , which I do not want . I know this maybe outside of asp/php , but I suspect in the future there will be alot of questions like this especially for php . When I do a post to asprunner application login.asp ,nothing happens it just gets whitelisted or blank screen . I tried firebug but maybe don't understand firebug results as I can't seem to see where the post is in firebug. application uses multi includes from project . I wondering if I should bypass application entirely and use just the database for all functions , but that will throw all security from asprunner appp out the window.

admin 7/17/2014

In Firebug or in Chrome developers tools you can use Network tab to see all requests and responses.
See this screenshot: