Can I have offline Login for my application?

This forum contains topics that were moved from Get Satisfaction
Tooba Atif
Posts: 0
Joined: Fri Apr 04, 2014 3:07 am

Can I have offline Login for my application?

Post 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/...

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

Can I have offline Login for my application?

Post 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.

Tooba Atif
Posts: 0
Joined: Fri Apr 04, 2014 3:07 am

Can I have offline Login for my application?

Post 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

Evgene Karachevtsev
Posts: 12
Joined: Mon Apr 28, 2014 1:12 pm

Can I have offline Login for my application?

Post 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...

Tooba Atif
Posts: 0
Joined: Fri Apr 04, 2014 3:07 am

Can I have offline Login for my application?

Post 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?

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

Can I have offline Login for my application?

Post 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.

Tooba Atif
Posts: 0
Joined: Fri Apr 04, 2014 3:07 am

Can I have offline Login for my application?

Post by Tooba Atif »

Done that using local Storage variables..
Thanks :)

She
Posts: 0
Joined: Wed Oct 08, 2014 12:46 am

Can I have offline Login for my application?

Post by She »

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

She
Posts: 0
Joined: Wed Oct 08, 2014 12:46 am

Can I have offline Login for my application?

Post 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(); } } }
Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

Can I have offline Login for my application?

Post by Kateryna Grynko »

Hi She,

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

Post Reply