Discussion Forums  >  WebViews and HTML for Mobile

Replies: 14    Views: 145

Fingers Crossed
Veteran developer
Profile
Posts: 234
Reg: Jan 16, 2012
Simcoe, ON
6,390
12/20/12 10:52 AM (11 years ago)

Login and User Registration - Again :S

Hi folks, I just spent a couple of hours trolling the forums looking for an answer to this question. It seems to be asked a lot, but I don't see where it actually gets answered. Here's the requirement. User runs the app, and the start screen is a login screen. User logs in, and a normal BT menu screen is now displayed. The ID the user logs in with is read and validated (via php) and their ID# is retrieved from a mySQL database. This ID # is to be used via the other screens that are accessed from the BT screen to Enter information. (Eg: My Birthdays, My car service). This ID is their unique identifier. Using the login plugin isn't viable as people will need to register themselves via another php screen. I can't figure out how I can get from the login screen to a new BT menu. I can figure out how to get to a HTML menu from the login screen, but I wanted it to use the BT UI to navigate the screens. I thought I could use a cookie to tell me I'm logged in, and the user could back out, but I don't know how to control the menu system at the return. The end result would be a tabbed layout, with each icon on the tab taking you to a different html page as a custom HTML. Once you're logged in, I assume (am I right), that I can carry the user # variable across the app to reference in the other screens? Hopefully this isn't really confusing, but I'll clarify if needed. Here's some screenshots as an example... Login Screen - this would be the home page you start at. https://dl.dropbox.com/u/25547044/TDM_SS2/login.png After you login, it would take you elsewhere. (A button screen is OK instead of a Tabbed Layout) From here I selected 'Car Service' https://dl.dropbox.com/u/25547044/TDM_SS2/form.png Any thoughts?
 
Fingers Crossed
Veteran developer
Profile
Posts: 234
Reg: Jan 16, 2012
Simcoe, ON
6,390
like
12/20/12 11:07 AM (11 years ago)
Mind you, if the user carries over, I could just use PHP to say you're not logged in, and direct you to a login screen right? Default to the home screen, and process it that way. That way for each tab (custom html) it will preprocess login before displaying the regular screen. (Hopefully I answered my own rambling question!?)
 
ATRAIN53
Code is Art
Profile
Posts: 1755
Reg: Nov 17, 2011
Chicago
26,450
like
12/20/12 11:31 AM (11 years ago)
Have you looked at the BT Login plugin? It might work for your set-up. It is a bit tricky to understand how it works and how it limits access to a screen. Here's how I set it up. 1) make your home screen a simple menu (or use buttons, just use some type of menu screen. you can use any of them) 2) the first menu item should be a link to a LOGIN PLUGIN 3) the second menu item is link to a 'Secret" or "password" protected menu'. This menu needs to have the REQUIRE LOGIN set to YES 4) Add screens to that Second 'secret' menu and make sure each of those screens also have the REQUIRE LOGIN to yes. Now when the user launches the app they have a menu with 2 items: 1) LOGIN 2) Protected Menu If they are not logged in they can't access the protected menu. That's how the BT plug-in could be used to protect a menu. To make a screen that shows a menu automatically after you login - that would require some custom coding to be added to the login screen.
 
Fingers Crossed
Veteran developer
Profile
Posts: 234
Reg: Jan 16, 2012
Simcoe, ON
6,390
like
12/20/12 11:34 AM (11 years ago)
The problem here lies with #2, the login plugin is controlled manually. I'll be setting up a database for logins as this app is for the general population. If someone downloads the app, I can't manually add them to the control panel.
 
AlanMac
Aspiring developer
Profile
Posts: 2612
Reg: Mar 05, 2012
Esher, UK
37,120
like
12/20/12 12:34 PM (11 years ago)
I believe the BT Login plugin refers back to your control panel as a default, but it doesn't have to. "Authenticating users from your server is not difficult if you have some basic web-programming skills. The Authentication URL above is the URL the app will request when a user log's in. This URL must have the appropriate merge fields included (see the buzztouch authentication url ) so your script knows what user id and password where entered. "
 
Fingers Crossed
Veteran developer
Profile
Posts: 234
Reg: Jan 16, 2012
Simcoe, ON
6,390
like
12/20/12 12:41 PM (11 years ago)
OK, thanks Alan, I'll dig into and play with that and see what happens.
 
Fingers Crossed
Veteran developer
Profile
Posts: 234
Reg: Jan 16, 2012
Simcoe, ON
6,390
like
12/20/12 12:49 PM (11 years ago)
OK, so the DOES look interesting. I've used it as a manually managed process, but not as I suggested above. When I get it working, I'll post back here so I can share the answer and others may locate it :) {holding my breath}
 
AlanMac
Aspiring developer
Profile
Posts: 2612
Reg: Mar 05, 2012
Esher, UK
37,120
like
12/20/12 01:07 PM (11 years ago)
Good luck - if I had the slightest idea on how to do this, I would have said more.
 
ATRAIN53
Code is Art
Profile
Posts: 1755
Reg: Nov 17, 2011
Chicago
26,450
like
12/20/12 02:18 PM (11 years ago)
Fingers - maybe the Parse login/sign-up would work for you? https://www.parse.com/tutorials/login-and-signup-views I've got a subclassed custom Parse login BT plug-in on the racks that I might submit when the market opens again. But that tutorial is a pretty good watch and seems like it might serve your needs?
 
Fingers Crossed
Veteran developer
Profile
Posts: 234
Reg: Jan 16, 2012
Simcoe, ON
6,390
like
12/20/12 02:20 PM (11 years ago)
Thanks ATrain, I'll take a look there too. At the moment I'm having an issue getting the login page to show up on BT. I have screen set to Login Required = Yes, but it doesn't show the login screen, it just shows the page as is :) Haven't finished trying everything yet - just got the login screen to show as a screen on it's own! I even redownloaded source to figure it out. Definately something funky going on as it's a shell app and not working.
 
Fingers Crossed
Veteran developer
Profile
Posts: 234
Reg: Jan 16, 2012
Simcoe, ON
6,390
like
12/20/12 02:39 PM (11 years ago)
OK, any links from the tabbed layout icons ignore the 'Login' option. If they are added as a menu option, the Login option works just fine. That problem solved :)
 
Fingers Crossed
Veteran developer
Profile
Posts: 234
Reg: Jan 16, 2012
Simcoe, ON
6,390
like
12/20/12 06:13 PM (11 years ago)
OK, I have the login part figured out, a little testing later to see if those variable I passed back are usable then I'll post the solution here.
 
Fingers Crossed
Veteran developer
Profile
Posts: 234
Reg: Jan 16, 2012
Simcoe, ON
6,390
like
12/21/12 06:14 PM (11 years ago)
OK, I haven't figured out how to use the returned variables, but I wanted to post how I created the php script so others can beg borrow and steal it. 1) First off, you need a mySQL database. Set up a user table with at least email and password. Add a record to this table that can be used to validate against. (You're on your own for a registration screen :) ) 2) You need a PHP script to use to validate against your database. Save this to the location of your choice (that supports PHP) (I setup PHP and mySQL on my mac for testing) We'll call it FCAUTH.php The script below will need changing to access your database, these fields are at the top. 3) You need the login plugin, add a new screen using this plugin. Change the Login Authentication Auth field to... http://localhost/FCAuth.php?appGuid=[buzztouchAppId]&logInId=[userLogInId]&logInPassword=[userLogInPassword] The localhost bit should be changed to where you put your html (unless you put it locally). 4) I believe that's it. If luck is on your side it will work first time, if you're like me, it will take you a while of debugging. To debug I first just pasted the above URL into a browser, that helped me see errors on the mySQL side. If it displayed JSON, it's good. It should show fail when you paste the URL Anyhow, I hope this helps someone out who is trying to do something similar! Graham. FC Here's the script... (If it doesn't display in the forums, here's a link to it...) https://dl.dropbox.com/u/25547044/FCAuth.php <?php ob_start(); $host="127.0.0.1"; // Host name $username= 'ID to access your DB'; // Mysql username $password= 'Password to access database'; // Mysql password $db_name="DatabaseName"; // Database name $tbl_name="UserFile"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password") or die(mysql_error()); //echo "Connected to MySQL<br />"; mysql_select_db("$db_name") or die(mysql_error()); //echo "Connected to Database<br />"; // Check $username and $password /* if(empty($_POST['username'])) { echo "UserName/Password is empty!"; return false; } if(empty($_POST['password'])) { echo "Password is empty!"; return false; } */ // Define $username and $password //$username='[email protected]'; (I used this to test my DB $username=($_GET["logInId"]); // ** NOTE** In this example, the password is NOT encrypted, it SHOULD be. The next line // will do the md5 but for test purposes this was quicker. $password=($_GET["logInPassword"]); //$password=md5($_GET['logInPassword ]); // To protect MySQL injection (more detail about MySQL injection) $username = stripslashes($username); $password = stripslashes($password); $username = mysql_real_escape_string($username); $password = mysql_real_escape_string($password); $sql="SELECT * FROM $tbl_name WHERE Email='$username' and Password='$password'"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $username and $password, table row must be 1 row if ($count==1) { // Obviously the echo can be updated with the other values, but this at least says it worked. echo "{\"result\":{\"status\":\"valid\",\"userGuid\":\"12345\",\"userDisplayName\":\"John Smith\", \"userEmail\":\"[email protected]\"}}"; } else { echo "{\"result\":{\"status\":\"failed\"}}"; } ob_end_flush(); ?>
 
Fingers Crossed
Veteran developer
Profile
Posts: 234
Reg: Jan 16, 2012
Simcoe, ON
6,390
like
12/21/12 08:43 PM (11 years ago)
Addendum: If you correctly load from your database the JSON that is returned on validation, you can reference it from other screens to custom URLs. EG: userGuid will hold the # you pass back, userDisplayName holds the login email address. These two pieces of information can be used to link your database tables throughout your application. This for me was the missing link! EG: In your PHP script you can use... $test=($_GET["userDisplayName"]); For a Custom URL, you use something like http://localhost/FT/GSTest.php?&userDisplayName=[userLogInId] Cheers. Graham. FC
 
Fingers Crossed
Veteran developer
Profile
Posts: 234
Reg: Jan 16, 2012
Simcoe, ON
6,390
like
12/21/12 09:00 PM (11 years ago)
OK, last post :) I just finished figuring all this out, and posting the above. Then I decided to check out the forums, and check out what was posted... https://www.buzztouch.com/forum/thread.php?fid=17BE49A00187AB129BA4259&tid=17BE49A00187AB129BA4259 This is a MUCH better source of information than I just wrote, so thanks to those guys.
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.