javascript - Kendo UI login functionality -


i making iphone application using kendo ui running through phone gap test on iphone.

the design mapped out nicely , getting grips kendo framework. trying make functionality whereby log account.

my external php file runs query , returns json:

<?php     $arr = array();  //takes username , password login form , queries database find out if have access site.           //cleanse inputs         $username = $_get['username'];         $password = md5_base64($_get['password']);          $stmt = $membermysqli->prepare("select id, firstname, dob, sex, recordingweight, blocked, enabled member email = ? , password = ?");         $stmt->bind_param('ss', $username, $password);         $stmt->execute();         $stmt->bind_result($memberid, $firstname, $dob, $sex, $recordingweight, $blocked, $enabled);         $stmt->store_result();            session_start();          while ($stmt->fetch())         {             $userisblocked = $blocked;             $enabled = $enabled;         }             if(($numrows = $stmt->num_rows) > 0)  //if num rows  1 combination exists therefore succesful login         {                if($userisblocked)             {                 $arr['status'] = "error";                 $arr['message'] = "sorry, account isnt active. please contact re-activate it.";             }             else if(!$enabled)             {                 $arr['status'] = "error";                 $arr['message'] = "sorry, account isn't enabled. please contact us.";             }              else             {                     $_session['memberid'] = $memberid;                     $_session['memberfirstname'] = $firstname;                     $_session['dob'] = $dob;                     $_session['sex'] = $sex;                     $_session['recordingweight'] = $recordingweight;                      $arr['status'] = "success";                     $arr['message'] = "logged in";             }         }         else         {             $arr['status'] = "error";             $arr['message'] = "sorry, wrong username/password combination";                          } header("content-type: application/json");    echo json_encode($arr); /* close connection */ function md5_base64 ( $data )  {      return preg_replace('/=+$/','',base64_encode(md5($data,true)));  }    ?> 

so returns success, logged in or sorry wrong username/password combination..

here form code:

<form>              <fieldset>                  <p><label style="color:white;" for="email">e-mail address</label></p>                 <p><input type="email" id="email" value=""></p>                   <p><label style="color:white; font" for="password">password</label></p>                 <p><input type="password" id="password" value=""></p>                   <p><input type="submit" value="sign in"></p>              </fieldset> 

and js:

<script>          $("form").on("submit", function() {          var username = document.getelementbyid('email').value;         var password = document.getelementbyid('password').value;          var datasource = new kendo.data.datasource({           transport: {             read:  {              url: 'http://myurl.co.uk/appqueries/login.php?username='+username+'&password='+password,              datatype: "json"            }           }         });          //alert("your username "+username+" , password is: "+password);          });     </script> 

can me getting json php file returns , letting user app if login successful, or displaying message if not.

i don't think want datasource (it done, datasource expects array of objects read operation), unless there additional requirements.

if html:

<input id='username' type='text' value='user'></input> <input id='password' type='text' value='password'></input> <button id='loginbutton'>login</button> <div id='loginresult'></div> 

then can use jquery (which assume you're using since it's requirement kendo ui):

function loginclick() {     var username = $("#username").val();     var password = $("#password").val();     var loginurl = 'http://myurl.co.uk/appqueries/login.php?username='+username+'&password='+password;      $.ajax({         url: loginurl,         type: 'get',         datatype: 'json',         success: function (data) {             handleloginresult(data);         }     }); }  $(document).on("click", "#loginbutton", loginclick);  function handleloginresult(data) {     var status = data.status;     var message = data.message;      if (status === "success") {         // whatever needs done after successful login         $("#loginresult").html(message);     } } 

see working example here (there few differences because using jsfiddle's echo api): http://jsfiddle.net/lhoeppner/9tgjd/

this works same kendo mobile, except you'd use mobile button , data-click binding:

  <a id="loginbutton" data-role="button" data-click="loginclick">login!</a> 

Comments

Popular posts from this blog

php - Add the correct number of days for each month -

java.util.scanner - How to read and add only numbers to array from a text file -