Working on login refactorization (iii)

parent ee792d66
...@@ -48,6 +48,41 @@ public class Translate extends Activity implements iVocabularyListener, iImgDown ...@@ -48,6 +48,41 @@ public class Translate extends Activity implements iVocabularyListener, iImgDown
// String constan for token // String constan for token
private final String TOKEN = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJvZmZpY2UiOnsiaWQiOjM4MywibmFtZSI6IkNvbXVuaWNhY2nDs24gQXVtZW50YXRpdmEgSkHDqW4gKENBSkEpIiwiYWRkcmVzcyI6IlBhcmFqZSBMYXMgTGFndW5pbGxhcywgRWQgQTMsIHByaW1lcmEgcGxhdGEsIDIzMDcxLiBKYcOpbiIsImVtYWlsIjoiZG9mZXJAdWphZW4uZXMiLCJwaG9uZTEiOiIrMzQgOTUzIDIxIDI4IDg4IiwicGhvbmUyIjpudWxsLCJsYW5nIjoiZXMtZXMiLCJjb3VudHJ5IjoiRVMiLCJhZG1pbiI6MjMsImNvbnRhY3RQZXJzb24iOiJGZXJuYW5kbyBNYXJ0w61uZXogU2FudGlhZ28iLCJtYXhTdHVkZW50cyI6MiwiY3VycmVudFN0dWRlbnRzIjowfSwiaWQiOjIzLCJuYW1lIjoiRmVybmFuZG8iLCJzdXJuYW1lIjoiTWFydMOtbmV6IFNhbnRpYWdvIiwiZ2VuZGVyIjoiTSIsInBpYyI6Imh0dHA6Ly93d3dkaS51amFlbi5lcy9zaXRlcy9kZWZhdWx0L2ZpbGVzL3lvLmpwZz8xNDQ4MDE5MzU2IiwiYWRkcmVzcyI6bnVsbCwiY291bnRyeSI6bnVsbCwiZW1haWwiOiJkb2ZlckB1amFlbi5lcyIsInBob25lIjoiKzM0OTUzMjEyODg4IiwibGFuZyI6ImVzLWVzIiwiYWN0aXZlIjp0cnVlLCJ0dHNFbmdpbmUiOm51bGwsImlzU3VwQWRtaW4iOnRydWUsImlhdCI6MTQ1Mjg4NjE1NSwiZXhwIjoxNDUyODkzMzU1fQ.dmxKE4qH1DqBM7BYakgwD0L6y1437_2Ba3T7rHnOIcE"; private final String TOKEN = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJvZmZpY2UiOnsiaWQiOjM4MywibmFtZSI6IkNvbXVuaWNhY2nDs24gQXVtZW50YXRpdmEgSkHDqW4gKENBSkEpIiwiYWRkcmVzcyI6IlBhcmFqZSBMYXMgTGFndW5pbGxhcywgRWQgQTMsIHByaW1lcmEgcGxhdGEsIDIzMDcxLiBKYcOpbiIsImVtYWlsIjoiZG9mZXJAdWphZW4uZXMiLCJwaG9uZTEiOiIrMzQgOTUzIDIxIDI4IDg4IiwicGhvbmUyIjpudWxsLCJsYW5nIjoiZXMtZXMiLCJjb3VudHJ5IjoiRVMiLCJhZG1pbiI6MjMsImNvbnRhY3RQZXJzb24iOiJGZXJuYW5kbyBNYXJ0w61uZXogU2FudGlhZ28iLCJtYXhTdHVkZW50cyI6MiwiY3VycmVudFN0dWRlbnRzIjowfSwiaWQiOjIzLCJuYW1lIjoiRmVybmFuZG8iLCJzdXJuYW1lIjoiTWFydMOtbmV6IFNhbnRpYWdvIiwiZ2VuZGVyIjoiTSIsInBpYyI6Imh0dHA6Ly93d3dkaS51amFlbi5lcy9zaXRlcy9kZWZhdWx0L2ZpbGVzL3lvLmpwZz8xNDQ4MDE5MzU2IiwiYWRkcmVzcyI6bnVsbCwiY291bnRyeSI6bnVsbCwiZW1haWwiOiJkb2ZlckB1amFlbi5lcyIsInBob25lIjoiKzM0OTUzMjEyODg4IiwibGFuZyI6ImVzLWVzIiwiYWN0aXZlIjp0cnVlLCJ0dHNFbmdpbmUiOm51bGwsImlzU3VwQWRtaW4iOnRydWUsImlhdCI6MTQ1Mjg4NjE1NSwiZXhwIjoxNDUyODkzMzU1fQ.dmxKE4qH1DqBM7BYakgwD0L6y1437_2Ba3T7rHnOIcE";
private login() {
if (RestapiWrapper.ping(context.getResources().getString(R.string.server),"server/ping",null)) {
// Tengo conexión a internet. Compruebo ONLINE
RestapiWrapper wrapper = PCBcontext.getRestapiWrapper();
if (username.contains("@")){
// Es un supervisor
String operation = "sup/login";
Hashtable<String, String> postDataParams = new Hashtable<String, String>();
postDataParams.put("email", username);
postDataParams.put("password", password);
wrapper.ask(operation, postDataParams, "post", (iRestapiListener) context);
} else{
// Es un estudiante
String operation = "stu/login";
Hashtable<String, String> postDataParams = new Hashtable<String, String>();
postDataParams.put("username", username);
postDataParams.put("password", password);
wrapper.ask(operation, postDataParams, "post", (iRestapiListener) context);
}
} else{
// NO Tengo conexión a internet. Compruebo OFFLINE
if (username.contains("@")) {
// Es un supervisor
// Necesito una función local que dado el username y pass me devuelva el listado de usuarios o el usuario, si es correcto
// ....
} else {
// Es un estudiante
}
// ....
}
}
/** Called when the activity is first created. */ /** Called when the activity is first created. */
@Override @Override
public void onCreate(Bundle savedInstanceState) public void onCreate(Bundle savedInstanceState)
......
...@@ -107,10 +107,9 @@ public class RestapiWrapper { ...@@ -107,10 +107,9 @@ public class RestapiWrapper {
/** /**
* synchronous ping * synchronous ping
* @param ping_op * @param ping_op
* @param error_listener
* @return * @return
*/ */
public static boolean ping(String server, String ping_op, iRestapiListener error_listener) { public static boolean ping(String server, String ping_op) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy); StrictMode.setThreadPolicy(policy);
boolean pingResult = false; boolean pingResult = false;
...@@ -118,7 +117,7 @@ public class RestapiWrapper { ...@@ -118,7 +117,7 @@ public class RestapiWrapper {
pingResult = GET(server + "/" + ping_op, null)!=null; pingResult = GET(server + "/" + ping_op, null)!=null;
} catch (UnknownHostException e){ } catch (UnknownHostException e){
//e.printStackTrace(); //e.printStackTrace();
Log.e(RestapiWrapper.class.getName(), "ping failed at"+ping_op); Log.e(RestapiWrapper.class.getName(), "ping failed at "+ping_op);
return false; return false;
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
......
...@@ -11,6 +11,8 @@ import com.yottacode.pictogram.tools.PCBcontext; ...@@ -11,6 +11,8 @@ import com.yottacode.pictogram.tools.PCBcontext;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import java.io.Serializable;
/** /**
* A object which represents a pictogram * A object which represents a pictogram
* * * *
......
...@@ -48,6 +48,8 @@ public class LoginActivity extends FragmentActivity implements iRestapiListener{ ...@@ -48,6 +48,8 @@ public class LoginActivity extends FragmentActivity implements iRestapiListener{
private static final String TAG_ATTRIBUTES = "attributes"; private static final String TAG_ATTRIBUTES = "attributes";
private static final String TAG_SUPERVISION = "supervision"; private static final String TAG_SUPERVISION = "supervision";
private int sup_id; private int sup_id;
// String constant for logs // String constant for logs
...@@ -108,7 +110,7 @@ public class LoginActivity extends FragmentActivity implements iRestapiListener{ ...@@ -108,7 +110,7 @@ public class LoginActivity extends FragmentActivity implements iRestapiListener{
// Compruebo si tengo acceso a internet y al servicio web // Compruebo si tengo acceso a internet y al servicio web
if (!RestapiWrapper.ping(getResources().getString(R.string.server),"server/ping",this)) { if (!RestapiWrapper.ping(getResources().getString(R.string.server),"server/ping")) {
// MODO OFFLINE // MODO OFFLINE
try { try {
Log.d(LOG_TAG, "username utilizado:" + username); Log.d(LOG_TAG, "username utilizado:" + username);
......
...@@ -14,6 +14,7 @@ import android.widget.Toast; ...@@ -14,6 +14,7 @@ import android.widget.Toast;
import com.yottacode.pictogram.R; import com.yottacode.pictogram.R;
import com.yottacode.pictogram.dao.Device; import com.yottacode.pictogram.dao.Device;
import com.yottacode.pictogram.dao.LoginException;
import com.yottacode.pictogram.dao.PCBDBHelper; import com.yottacode.pictogram.dao.PCBDBHelper;
import com.yottacode.pictogram.dao.User; import com.yottacode.pictogram.dao.User;
import com.yottacode.pictogram.tools.PCBcontext; import com.yottacode.pictogram.tools.PCBcontext;
...@@ -43,7 +44,6 @@ public class MainActivity extends Activity { ...@@ -43,7 +44,6 @@ public class MainActivity extends Activity {
PCBcontext.init(this); PCBcontext.init(this);
Log.d(LOG_TAG, "PCBcontext iniciado."); Log.d(LOG_TAG, "PCBcontext iniciado.");
// Nota magc: al pasar ya siempre por serial no tiene sentido tener main ¿no?
Intent serialActivity = new Intent(this, SerialActivity.class); Intent serialActivity = new Intent(this, SerialActivity.class);
serialActivity.putExtra("activity_name","MainActivity"); serialActivity.putExtra("activity_name","MainActivity");
......
...@@ -3,6 +3,7 @@ package com.yottacode.pictogram.gui; ...@@ -3,6 +3,7 @@ package com.yottacode.pictogram.gui;
import android.app.Activity; import android.app.Activity;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.database.Cursor; import android.database.Cursor;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.Point; import android.graphics.Point;
...@@ -49,6 +50,8 @@ import com.yottacode.pictogram.net.PictoUploader; ...@@ -49,6 +50,8 @@ import com.yottacode.pictogram.net.PictoUploader;
import com.yottacode.pictogram.net.iImgDownloaderListener; import com.yottacode.pictogram.net.iImgDownloaderListener;
import com.yottacode.pictogram.tools.Img; import com.yottacode.pictogram.tools.Img;
import com.yottacode.pictogram.tools.PCBcontext; import com.yottacode.pictogram.tools.PCBcontext;
import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import java.io.IOException; import java.io.IOException;
...@@ -57,6 +60,7 @@ import java.util.Arrays; ...@@ -57,6 +60,7 @@ import java.util.Arrays;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Vector;
import android.provider.Settings.Secure; import android.provider.Settings.Secure;
...@@ -81,18 +85,6 @@ public class PictogramActivity extends Activity implements iVocabularyListener, ...@@ -81,18 +85,6 @@ public class PictogramActivity extends Activity implements iVocabularyListener,
private int count_deletelong = 0; private int count_deletelong = 0;
private boolean isSupervisor = false;
private String selectedImagePath;
/*
float xAxis = 0f;
float yAxis = 0f;
float lastXAxis = 0f;
float lastYAxis = 0f;
*/
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
...@@ -101,32 +93,12 @@ public class PictogramActivity extends Activity implements iVocabularyListener, ...@@ -101,32 +93,12 @@ public class PictogramActivity extends Activity implements iVocabularyListener,
setContentView(R.layout.activity_pictogram); setContentView(R.layout.activity_pictogram);
Intent intent = getIntent(); Intent intent = getIntent();
isSupervisor = intent.getBooleanExtra("isSupervisor", false);
//isSupervisor = true;// QUITAR
//Log.d(LOG_TAG, "isSupervisor vale " + isSupervisor);
currentCategory = null; // this for refresh vocabulary when a websocket action arrived from the dashboard currentCategory = null; // this for refresh vocabulary when a websocket action arrived from the dashboard
count_deletelong = 0; count_deletelong = 0;
// Singleton getInstance
//pcb = PCBcontext.getInstance();
//FERNANDO he comentado esta llamada a PCBcontext.init ¿es realmente necesaria? ¿dónde está la llamada a set_user ---> token queda a nulo!!!
//Log.d(LOG_TAG, "1) Opening PCB");
//SSLDummyContext.init(getResources().getBoolean(R.bool.ssl_connect));
//PCBcontext.init(this);
//Log.d(LOG_TAG, "PCBcontext iniciado");
// Redundante, pero lo hago para forzarlo
/*
student = PCBcontext.getPcbdb().getCurrentUser();
String jsonToken = PCBcontext.getRestapiWrapper().getToken();
Log.d(LOG_TAG, "student name:" + student.get_name_stu());
PCBcontext.set_user(student,jsonToken, this);
*/
// Adapter for grid // Adapter for grid
panelAdapter = new PanelAdapter(new LinkedList<Picto>()); panelAdapter = new PanelAdapter(new LinkedList<Picto>());
...@@ -300,7 +272,7 @@ public class PictogramActivity extends Activity implements iVocabularyListener, ...@@ -300,7 +272,7 @@ public class PictogramActivity extends Activity implements iVocabularyListener,
panelGridView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { panelGridView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
@Override @Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
if (isSupervisor) { if (PCBcontext.getPcbdb().getCurrentUser().is_supervisor()) {
// Si es supervisor al hacer longClick deshabilito ese pictograma o lo habilito // Si es supervisor al hacer longClick deshabilito ese pictograma o lo habilito
Picto p = panelAdapter.getItem(position); Picto p = panelAdapter.getItem(position);
if (p == null) { if (p == null) {
......
...@@ -38,13 +38,9 @@ import com.yottacode.pictogram.tools.PCBcontext; ...@@ -38,13 +38,9 @@ import com.yottacode.pictogram.tools.PCBcontext;
*/ */
public class SerialActivity extends Activity { public class SerialActivity extends Activity {
// UI references.
private EditText mSerialViewMail;
private EditText mSerialViewPass;
private static final String TAG_USER = "user"; private static final String TAG_USER = "user";
private static final String TAG_ISSTUDENT = "isStudent";
private static final String TAG_TOKEN = "token"; private static final String TAG_TOKEN = "token";
private static final String TAG_ID = "id"; private static final String TAG_ID = "id";
private static final String TAG_NAME = "name"; private static final String TAG_NAME = "name";
...@@ -55,20 +51,21 @@ public class SerialActivity extends Activity { ...@@ -55,20 +51,21 @@ public class SerialActivity extends Activity {
private static final String TAG_ATTRIBUTES = "attributes"; private static final String TAG_ATTRIBUTES = "attributes";
//private static final String TAG_TTSENGINE = "ttsEngine"; //private static final String TAG_TTSENGINE = "ttsEngine";
private Integer st_id=-1; private Integer st_id=-1;
// String constant for logs // String constant for logs
private final String LOG_TAG = this.getClass().getSimpleName(); // Or .getCanonicalName() private final String LOG_TAG = this.getClass().getSimpleName(); // Or .getCanonicalName()
//A ProgressDialog object
private ProgressDialog progressDialog;
public static final String PREFS_NAME = "MyPrefsFile"; public static final String PREFS_NAME = "MyPrefsFile";
private Intent manageSupervisorLogin(String username, String password, boolean online) { private void manageSupervisorLogin(String username, String password, boolean online) {
final Intent loginActivity = new Intent(SerialActivity.this, LoginActivity.class); final Intent loginActivity = new Intent(SerialActivity.this, LoginActivity.class);
if (online) { if (online) {
final ProgressDialog progressDialog = ProgressDialog.show(SerialActivity.this, SerialActivity.this.getBaseContext().getString(R.string.userLoadingMsg),
SerialActivity.this.getBaseContext().getString(R.string.userLoadingTxt), false, false);;
final String operation = "sup/login"; final String operation = "sup/login";
Hashtable<String, String> postDataParams = new Hashtable<String, String>(); Hashtable<String, String> postDataParams = new Hashtable<String, String>();
...@@ -78,8 +75,7 @@ public class SerialActivity extends Activity { ...@@ -78,8 +75,7 @@ public class SerialActivity extends Activity {
PCBcontext.getRestapiWrapper().ask(operation, postDataParams, "post", new iRestapiListener() { PCBcontext.getRestapiWrapper().ask(operation, postDataParams, "post", new iRestapiListener() {
@Override @Override
public void preExecute() { public void preExecute() {
progressDialog = ProgressDialog.show(SerialActivity.this, SerialActivity.this.getBaseContext().getString(R.string.userLoadingMsg),
SerialActivity.this.getBaseContext().getString(R.string.userLoadingTxt), false, false);
} }
@Override @Override
...@@ -89,6 +85,7 @@ public class SerialActivity extends Activity { ...@@ -89,6 +85,7 @@ public class SerialActivity extends Activity {
@Override @Override
public void result(JSONObject result) { public void result(JSONObject result) {
progressDialog.dismiss();
if (SerialActivity.this.checkLogin(result)) { if (SerialActivity.this.checkLogin(result)) {
String jsonToken; String jsonToken;
JSONObject user; JSONObject user;
...@@ -102,14 +99,9 @@ public class SerialActivity extends Activity { ...@@ -102,14 +99,9 @@ public class SerialActivity extends Activity {
Log.e(LOG_TAG, e.getMessage()); Log.e(LOG_TAG, e.getMessage());
} }
Log.d(LOG_TAG, "Es un SUPERVISOR. Sigo...");
Log.d(LOG_TAG, "jsonToken válido:" + jsonToken);
try { try {
Integer su_id = user.getInt(TAG_ID); Integer su_id = user.getInt(TAG_ID);
int su_id_int = su_id.intValue(); int su_id_int = su_id.intValue();
progressDialog.dismiss();
loginActivity.putExtra("offline", false); loginActivity.putExtra("offline", false);
loginActivity.putExtra("sup_id", su_id_int); loginActivity.putExtra("sup_id", su_id_int);
loginActivity.putExtra("token", jsonToken); loginActivity.putExtra("token", jsonToken);
...@@ -129,12 +121,40 @@ public class SerialActivity extends Activity { ...@@ -129,12 +121,40 @@ public class SerialActivity extends Activity {
loginActivity.putExtra("username", username); loginActivity.putExtra("username", username);
loginActivity.putExtra("password", password); loginActivity.putExtra("password", password);
} }
return loginActivity;
} }
private void set_student_oline(User student, String token) {
final ProgressDialog progressDialog=ProgressDialog.show(this, getString(R.string.userLoadingTxt),getString(R.string.loadingGrammar));
Vector<User> vstudent = new Vector<>(1);
vstudent.add(student);
try {
PCBcontext.getDevice().synchronizeUsers(vstudent, new iImgDownloaderListener() {
@Override
public void loadComplete() {
private Intent manageStudentLogin(final String username, final String password, boolean online) }
{
@Override
public void loadImg(Img image) {
Log.d(LOG_TAG, "Load a single image with ID: " + image.get_id());
}
});
} catch (JSONException e) {
e.printStackTrace();
}
PCBcontext.set_user(student, token, new iImgDownloaderListener() {
@Override
public void loadComplete() {
progressDialog.dismiss();
}
@Override
public void loadImg(Img image) {
}
});
}
private void manageStudentLogin(final String username, final String password, boolean online)
{
final Intent pictogramActivity = new Intent(SerialActivity.this, PictogramActivity.class); final Intent pictogramActivity = new Intent(SerialActivity.this, PictogramActivity.class);
if (online) { if (online) {
Log.d(LOG_TAG, "Entro con usuario y password"); Log.d(LOG_TAG, "Entro con usuario y password");
...@@ -143,11 +163,7 @@ public class SerialActivity extends Activity { ...@@ -143,11 +163,7 @@ public class SerialActivity extends Activity {
postDataParams.put("username", username); postDataParams.put("username", username);
postDataParams.put("password", password); postDataParams.put("password", password);
/*
postDataParams.put("idFirmware", _ANDROIDID);
postDataParams.put("desc", _MODEL);
postDataParams.put("serial", serial);
*/
PCBcontext.getRestapiWrapper().ask(operation, postDataParams, "post", new iRestapiListener() { PCBcontext.getRestapiWrapper().ask(operation, postDataParams, "post", new iRestapiListener() {
@Override @Override
public void preExecute() { public void preExecute() {
...@@ -162,7 +178,6 @@ public class SerialActivity extends Activity { ...@@ -162,7 +178,6 @@ public class SerialActivity extends Activity {
@Override @Override
public void result(JSONObject result) { public void result(JSONObject result) {
try { try {
pictogramActivity.putExtra("token", result.getString(TAG_TOKEN));
JSONObject user = result.getJSONObject(TAG_USER); JSONObject user = result.getJSONObject(TAG_USER);
// Es un estudiante // Es un estudiante
st_id = user.getInt(TAG_ID); st_id = user.getInt(TAG_ID);
...@@ -173,15 +188,23 @@ public class SerialActivity extends Activity { ...@@ -173,15 +188,23 @@ public class SerialActivity extends Activity {
String st_gender = user.getString(TAG_GENDER); String st_gender = user.getString(TAG_GENDER);
String st_lang = user.getString(TAG_LANG); String st_lang = user.getString(TAG_LANG);
String st_attributes = user.getString(TAG_ATTRIBUTES); String st_attributes = user.getString(TAG_ATTRIBUTES);
set_student_oline(
new User(st_id_int,
username,
User student = new User(st_id_int, username,password, st_name, st_surname, st_pic, st_gender, st_lang, st_attributes, password,
User.NO_SUPERVISOR, "", "", "", "", "", "M", "es-es", ""); st_name,
st_surname,
st_pic,
st_gender,
st_lang,
st_attributes,
User.NO_SUPERVISOR, "", "", "", "", "", "M", "es-es", "")
,result.getString(TAG_TOKEN));
startActivity(pictogramActivity);
} catch (JSONException e) { } catch (JSONException e) {
SerialActivity.this.error(e); SerialActivity.this.error(e);
} }
} }
@Override @Override
...@@ -190,7 +213,7 @@ public class SerialActivity extends Activity { ...@@ -190,7 +213,7 @@ public class SerialActivity extends Activity {
} }
}); });
} }
else { else { //Offline student login
try { try {
Vector<User> localUsers = PCBcontext.getDevice().findUser(username, password); Vector<User> localUsers = PCBcontext.getDevice().findUser(username, password);
PCBcontext.set_user(localUsers.elementAt(0), null, null); PCBcontext.set_user(localUsers.elementAt(0), null, null);
...@@ -218,49 +241,24 @@ public class SerialActivity extends Activity { ...@@ -218,49 +241,24 @@ public class SerialActivity extends Activity {
} }
e.printStackTrace(); e.printStackTrace();
} }
} startActivity(pictogramActivity);
return pictogramActivity;
} }
protected void login(String username, String password) {
boolean online=RestapiWrapper.ping(this.getResources().getString(R.string.server),"server/ping", new iRestapiListener() {
@Override
public void preExecute() {
} }
@Override private void login(String username, String password) {
public void result(JSONArray result) { boolean online=RestapiWrapper.ping(this.getResources().getString(R.string.server),"server/ping");
if (username.contains("@"))
manageSupervisorLogin(username,password,online);
else
manageStudentLogin(username,password,online);
} }
@Override
public void result(JSONObject result) {
} private boolean checkLogin(JSONObject result) {
@Override
public void error(Exception e) {
SerialActivity.this.error(e);
}
});
Intent nextActivity=username.contains("@")
? manageSupervisorLogin(username,password,online)
: manageStudentLogin(username,password,online);
nextActivity.putExtra("offline",!online);
startActivity(nextActivity);
}
public boolean checkLogin(JSONObject result) {
Log.d(LOG_TAG, "JSON en result:" + result.toString()); Log.d(LOG_TAG, "JSON en result:" + result.toString());
if (result.toString().contains("error")){
if (result.toString().contains("error")) {
if (progressDialog != null) progressDialog.dismiss();
AlertDialog.Builder builder = new AlertDialog.Builder(SerialActivity.this); AlertDialog.Builder builder = new AlertDialog.Builder(SerialActivity.this);
if (result.toString().contains("Invalid password")) { if (result.toString().contains("Invalid password")) {
...@@ -287,7 +285,7 @@ public class SerialActivity extends Activity { ...@@ -287,7 +285,7 @@ public class SerialActivity extends Activity {
} }
public void error(Exception e) { private void error(Exception e) {
Log.e(this.getClass().getName(), " Server restapi error: " + e.getLocalizedMessage()); Log.e(this.getClass().getName(), " Server restapi error: " + e.getLocalizedMessage());
AlertDialog.Builder builder = new AlertDialog.Builder(SerialActivity.this); AlertDialog.Builder builder = new AlertDialog.Builder(SerialActivity.this);
...@@ -311,8 +309,8 @@ public class SerialActivity extends Activity { ...@@ -311,8 +309,8 @@ public class SerialActivity extends Activity {
Intent intent=getIntent(); Intent intent=getIntent();
String activityName=intent.getStringExtra("activity_name"); String activityName=intent.getStringExtra("activity_name");
mSerialViewMail = (EditText) findViewById(R.id.serialmail); final EditText mSerialViewMail = (EditText) findViewById(R.id.serialmail);
mSerialViewPass = (EditText) findViewById(R.id.serialpass); final EditText mSerialViewPass = (EditText) findViewById(R.id.serialpass);
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0); SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
String username = settings.getString("username", ""); String username = settings.getString("username", "");
...@@ -321,8 +319,8 @@ public class SerialActivity extends Activity { ...@@ -321,8 +319,8 @@ public class SerialActivity extends Activity {
// Escribo el último valor indicado de username // Escribo el último valor indicado de username
mSerialViewMail.setText(username); mSerialViewMail.setText(username);
username="";
Log.i(this.LOG_TAG,"1 FERNANDO username:"+username);
if (username.equals("")) { // No tengo aún usuario. Espero a que lo indique if (username.equals("")) { // No tengo aún usuario. Espero a que lo indique
Button mEntrarButton = (Button) findViewById(R.id.entrar_button); Button mEntrarButton = (Button) findViewById(R.id.entrar_button);
mEntrarButton.setOnClickListener(new OnClickListener() { mEntrarButton.setOnClickListener(new OnClickListener() {
......
...@@ -33,27 +33,7 @@ public class NetService implements Runnable { ...@@ -33,27 +33,7 @@ public class NetService implements Runnable {
static final String ping_session="server/ping"; static final String ping_session="server/ping";
private boolean updated; private boolean updated;
public NetService(int delay) { public NetService(int delay) {
this.updated=RestapiWrapper.ping(PCBcontext.getContext().getResources().getString(R.string.server), ping_session, new iRestapiListener() { this.updated=RestapiWrapper.ping(PCBcontext.getContext().getResources().getString(R.string.server), ping_session);
@Override
public void preExecute() {
}
@Override
public void result(JSONArray result) {
}
@Override
public void result(JSONObject result) {
updated=true;
}
@Override
public void error(Exception e) {
updated=false;
}
});
Log.i(this.getClass().getName(), "Checking Pictogram server access..."); Log.i(this.getClass().getName(), "Checking Pictogram server access...");
Log.i(this.getClass().getName(), this.updated ? "Pictogram server access ok" : "Pictogram server access failed, Internet connection available?"); Log.i(this.getClass().getName(), this.updated ? "Pictogram server access ok" : "Pictogram server access failed, Internet connection available?");
ScheduledThreadPoolExecutor exec = new ScheduledThreadPoolExecutor(1); ScheduledThreadPoolExecutor exec = new ScheduledThreadPoolExecutor(1);
......
...@@ -13,6 +13,7 @@ import java.io.FileNotFoundException; ...@@ -13,6 +13,7 @@ import java.io.FileNotFoundException;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.Serializable;
import com.yottacode.tools.FileTools; import com.yottacode.tools.FileTools;
import com.yottacode.tools.ImgTools; import com.yottacode.tools.ImgTools;
......
...@@ -80,10 +80,29 @@ type TEXT(5) NOT NULL CHECK (type in ('stu','sup','pic')) ...@@ -80,10 +80,29 @@ type TEXT(5) NOT NULL CHECK (type in ('stu','sup','pic'))
;-- ;--
CREATE VIEW users_detail AS CREATE VIEW users_detail AS
SELECT id_stu, a.nickname nickname_stu, a.pwd pwd_stu, a.name name_stu, a.surname surname_stu, a.url_img url_img_stu, a.gender gender_stu, a.lang lang_stu, a.attributes attributes_stu, SELECT
id_sup, b.email email_sup, b.pwd pwd_sup, b.name name_sup, b.surname surname_sup, b.url_img url_img_sup, b.gender gender_sup, b.lang lang_sup, b.tts_engine tts_engine_sup id_stu,
FROM student a, supervisor b, users a.nickname nickname_stu,
WHERE a.id=users.id_stu AND b.id=users.id_sup a.pwd pwd_stu,
a.name name_stu,
a.surname surname_stu,
a.url_img url_img_stu,
a.gender gender_stu,
a.lang lang_stu,
a.attributes attributes_stu,
id_sup,
b.email email_sup,
b.pwd pwd_sup,
b.name name_sup,
b.surname surname_sup,
b.url_img url_img_sup,
b.gender gender_sup,
b.lang lang_sup,
b.tts_engine tts_engine_sup
FROM
student a, supervisor b, users
WHERE
a.id=users.id_stu AND b.id=users.id_sup
;-- ;--
CREATE VIEW collection_detail AS CREATE VIEW collection_detail AS
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment