Page 1 of 1

Can I have offline Login for my application?

Posted: Thu Jun 12, 2014 2:33 am
by Tooba Atif

Hi,

I am using local data for login using Rest Service. I just want to confirm that is it possible to make it work offline?
I am not using appery'd Db?
I am following this tutorial below.
What additional things I need to do for this?
http://devcenter.appery.io/tutorials/...


Can I have offline Login for my application?

Posted: Thu Jun 12, 2014 2:46 am
by Yurii Orishchuk

Hi Tooba.

Nope, you can not recive password from DB, cause of it does not stored in db(in accordance to security reason).

Regards.


Can I have offline Login for my application?

Posted: Thu Jun 12, 2014 2:58 am
by Tooba Atif

Hi Yurii,

I am using Microsoft Sql Server DB.
Its not possible to store the DB password somehow in local?
Is there any alternate way?
Can I do this for images?
Like if user of app upload images in offline mode and then when the wifi is available they are automatically uploaded to the server and synchronize accordingly!

Thanks


Can I have offline Login for my application?

Posted: Thu Jun 12, 2014 3:29 pm
by Evgene Karachevtsev

Hi Tooba,

You can store any data in local storage variables http://devcenter.appery.io/tutorials/...
Your image you can store on mobile device like files and then send them to server.
http://docs.phonegap.com/en/3.3.0/cor...


Can I have offline Login for my application?

Posted: Fri Jun 13, 2014 2:21 am
by Tooba Atif

I did not get your answer for the login question!
Can you please answer these again?

Can I implement the offline login verification using REST API and MS SQL DB?
As what I get from your answer you can get the image thing to work offline.. having the link stored in phone local db and using local storage variables this can be done.. Right?


Can I have offline Login for my application?

Posted: Fri Jun 13, 2014 12:57 pm
by Kateryna Grynko

Hi Tooba,

Yes, you can, if you install Microsoft SQL Serve on your device. To do this specify a local link to this database in service settings. Please note it must use REST requests.


Can I have offline Login for my application?

Posted: Fri Jun 20, 2014 8:04 am
by Tooba Atif

Done that using local Storage variables..
Thanks :)


Can I have offline Login for my application?

Posted: Thu Oct 16, 2014 6:30 am
by She

is it possible that the database inside the appery can connect to our webservice?


Can I have offline Login for my application?

Posted: Thu Oct 16, 2014 6:31 am
by She

like this code

Code: Select all


 import java.io.File; 
 import java.io.FileWriter; 
 import java.io.InputStream; 
 import java.util.ArrayList; 
 import java.util.List; 
 import java.util.Random; 

 import org.apache.http.HttpEntity; 
 import org.apache.http.HttpResponse; 
 import org.apache.http.NameValuePair; 
 import org.apache.http.client.HttpClient; 
 import org.apache.http.client.methods.HttpPost; 
 import org.apache.http.impl.client.DefaultHttpClient; 
 import org.apache.http.message.BasicNameValuePair; 
 import org.json.JSONException; 
 import org.json.JSONObject; 

 import android.app.Activity; 
 import android.app.ProgressDialog; 
 import android.content.Intent; 
 import android.content.SharedPreferences; 
 import android.os.AsyncTask; 
 import android.os.Bundle; 
 import android.os.StrictMode; 
 import android.util.Log; 
 import android.view.View; 
 import android.view.View.OnClickListener; 
 import android.widget.Button; 
 import android.widget.CheckBox; 
 import android.widget.EditText; 
 import android.widget.Toast; 

 public class Login extends Activity implements OnClickListener  { 

  private EditText user, pass; 
  private Button mSubmit, reg; 
  private CheckBox chk; 
     private ProgressDialog pDialog; 
  private String sessionUser; 
  Session session; 

  public static String validUsername, validPassword; 

     JSONParser jsonParser = new JSONParser(); 
     //private static final String LOGIN_URL = "[url=http://10.0.2.2/ordering_api/login.php]http://10.0.2.2/ordering_api/login.php[/url]";     
private static final String LOGIN_URL = "[url=http://122.52.217.71:8080/phpWidgetSource/loggedIN.php]http://122.52.217.71:8080/phpWidgetSo...[/url]"; private static final String TAG_SUCCESS = "success"; private static final String TAG_MESSAGE = "message"; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.login); if (android.os.Build.VERSION.SDK_INT 9) { StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy); } chk = (CheckBox) findViewById(R.id.logCheck); user = (EditText) findViewById(R.id.log_username); pass = (EditText) findViewById(R.id.log_password); mSubmit = (Button)findViewById(R.id.btnLogin); mSubmit.setOnClickListener(this); } @Override public void onClick(View v) { switch (v.getId()) { case R.id.btnLogin: new AttemptLogin().execute(); break; default: break; } } class AttemptLogin extends AsyncTask { /** * Before starting background thread Show Progress Dialog * */ boolean failure = false; @Override protected void onPreExecute() { super.onPreExecute(); pDialog = new ProgressDialog(Login.this); pDialog.setMessage("Attempting login..."); pDialog.setIndeterminate(false); pDialog.setCancelable(true); pDialog.show(); } @Override protected String doInBackground(String... args) { // Check for success tag int success; //String success; String username = user.getText().toString(); String password = pass.getText().toString(); try { List params = new ArrayList(); params.add(new BasicNameValuePair("username", username)); params.add(new BasicNameValuePair("password", password)); Log.d("request!", "starting"); JSONObject json = jsonParser.makeHttpRequest(LOGIN_URL, "POST", params); String js = json.toString(); Log.d("Login attempt", json.toString()); Log.d("JSON:", js.replace("\\", "")); success = json.getInt(TAG_SUCCESS); if (success == 1) { Log.d("Login Successful!", json.toString()); Session.setSessionUser(sessionUser); Intent i = new Intent(Login.this, MainTabActivity.class); validUsername = username; validPassword = password; saveToStorage(); startActivity(i); return json.getString(TAG_MESSAGE); } else { Log.d("Login Failure!", json.getString(TAG_MESSAGE)); return json.getString(TAG_MESSAGE); } } catch (JSONException e) { e.printStackTrace(); } return null; } /** * After completing background task Dismiss the progress dialog * **/ protected void onPostExecute(String file_url) { pDialog.dismiss(); if (file_url != null){ Toast.makeText(Login.this, file_url, Toast.LENGTH_LONG).show(); } } } class FetchData extends AsyncTask { /** * Before starting background thread Show Progress Dialog * */ boolean failure = false; @Override protected void onPreExecute() { super.onPreExecute(); pDialog = new ProgressDialog(Login.this); pDialog.setMessage("Attempting login..."); pDialog.setIndeterminate(false); pDialog.setCancelable(true); pDialog.show(); } @Override protected String doInBackground(String... args) { //String success; String username = user.getText().toString(); String password = pass.getText().toString(); List params = new ArrayList(); params.add(new BasicNameValuePair("username", username)); params.add(new BasicNameValuePair("password", password)); Log.d("request!", "starting"); JSONObject json = jsonParser.makeHttpRequest(LOGIN_URL, "POST", params); String js = json.toString(); Log.d("Login attempt", json.toString()); //Session.setSessionUser(sessionUser); Intent i = new Intent(Login.this, MainTabActivity.class); saveToStorage(); startActivity(i); return null; } /** * After completing background task Dismiss the progress dialog * **/ protected void onPostExecute() { runOnUiThread(new Runnable() { public void run() { saveToStorage(); finish(); passIntent(); } }); } } private void passIntent() { Intent intent = new Intent(this, MainTabActivity.class); startActivity(intent); } private void saveToStorage() { String content = loadFromNet("[url=http://122.52.217.71:8080/phpWidgetSource/logged.php?u]http://122.52.217.71:8080/phpWidgetSo...[/url]=" + validUsername + "&p=" + validPassword); updateJSONData(content, "loggedin.json"); String notLogged = loadFromNet("[url=http://122.52.217.71:8080/phpWidgetSource/NotLoggedIN.php?u]http://122.52.217.71:8080/phpWidgetSo...[/url]=" + validUsername + "&p=" + validPassword); updateJSONData(notLogged, "notloggedin.json"); String stardyIn = loadFromNet("[url=http://122.52.217.71:8080/phpWidgetSource/TardyIN.php?u]http://122.52.217.71:8080/phpWidgetSo...[/url]=" + validUsername + "&p=" + validPassword); updateJSONData(stardyIn, "late.json"); } private String loadFromNet(String url){ String result = null; try { HttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost(url); HttpResponse response = client.execute(post); HttpEntity entity = response.getEntity(); InputStream entityStream = entity.getContent(); StringBuilder entityStringBuilder = new StringBuilder(); byte [] buffer = new byte[1024]; int bytesReadCount; while ((bytesReadCount = entityStream.read(buffer)) 0) { entityStringBuilder.append(new String(buffer, 0, bytesReadCount)); } result = entityStringBuilder.toString(); }catch(Exception e) { Log.e("log_tag", "Error in http connection " + e.toString()); } return result; } public void updateJSONData(String stringToWrite, String filename) { try { File createFile = new File("mnt/sdcard/EDSCACHE/asset/" + filename); FileWriter writeOutput = new FileWriter(createFile); writeOutput.write(stringToWrite); writeOutput.flush(); writeOutput.close(); } catch (Exception e) { e.printStackTrace(); } } }

Can I have offline Login for my application?

Posted: Thu Oct 16, 2014 11:43 am
by Kateryna Grynko

Hi She,

Please use REST services to access your server:
http://devcenter.appery.io/documentat...