5

I'm playing with PhoneGap for the first time. I'd like to do the following:

Create a login UI in the file index.html like so:

<input id="email">
<input id="password">
<button id="login">Login</button>

The UI will appear on an iphone. When user clicks the login button, I want to asychronously authenticate against the website http://mysite.com/login. If authentication fails, user stays on the index.html UI. If authentication succeeds, user sees a new UI found in dashboard.html, which looks like this:

<ul>
   <li>task 1</li>
   <li>task 2</li>
   <li>task 3 etc... (asychronously retrieve data from http://mysite.com)</li>
</ul>

The user can perform asynchronous actions against the list in dashboard.html. So to do this, the server-side scripts must always check to see if user has the appropriate permissions.

SO my questions are:

1) I've outlined what I'd like to achieve, but i've also suggested web-development philsophy to solving the problem. Is there a better overall approach?

2) Which asynchronous technology should I use? Ajax, webservice, something else?

3) Can I still use SESSION on the server side to maintain user session data like user_id, roles, permissions etc... That way the client machine doesn't have to transmit this data with every asynchronous call?

John
  • 32,403
  • 80
  • 251
  • 422
  • A related question on how to AJAX user authenticate with PhoneGap: http://stackoverflow.com/questions/3709315/phonegap-cookie-based-authentication-php-not-working-webview – John Nov 14 '10 at 18:20

2 Answers2

9
  1. good approach
  2. I would suggest ajax with json response
  3. Yes you can still use session variables

remember in the end, that the phonegap application is really just a web page running in a container created by phonegap.

Here is a phonegap plugin I wrote for logging into a system running SSL

Excellent PhoneGap Documentation is here and don't forget the PhoneGap Wiki has great stuff too

Aaron Saunders
  • 33,180
  • 5
  • 60
  • 80
  • 1
    no, plugins are platform specific, I will create an android version since it is a secondary platform for me – Aaron Saunders Nov 14 '10 at 18:28
  • @AaronSaunders Nice plugin. Please update when you create Android version of the plugin. I'm waiting for it. :) – Imdad Nov 28 '12 at 10:47
0

You can use event.preventDefault on submit button in case of no authentication.. Ajax and json is the solution.. But careful about the cross-domain policy if you debug on browser...best debug on emulator.

gnnpls
  • 141
  • 1
  • 8