Bug login solucionado

parent 922f7edc
......@@ -183,7 +183,7 @@ public class PictogramActivity extends Activity implements iVocabularyListener,
*/
final GridView panelGridView = (GridView) findViewById(R.id.panel_grid_view);
//final ImageButton deleteButton = (ImageButton) findViewById(R.id .button_delete);
final ImageButton deleteButton = (ImageButton) findViewById(R.id .button_delete);
//final Button deleteAllButton = (Button) findViewById(R.id.button_delete_all);
final ImageButton ttsButton = (ImageButton) findViewById(R.id.button_tts);
......@@ -363,7 +363,7 @@ public class PictogramActivity extends Activity implements iVocabularyListener,
}
});
/* onClick deleteButton (eliminar del tape el último picto)
// onClick deleteButton (eliminar del tape el último picto)
deleteButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
......@@ -398,7 +398,7 @@ public class PictogramActivity extends Activity implements iVocabularyListener,
return false;
}
});*/
});
}
@Override
......
......@@ -183,19 +183,17 @@ public class SerialActivity extends Activity implements iRestapiListener {
String password = mSerialViewPass.getText().toString();
// DE PRUEBA
// Alumno
username = "faf0001";
password = "faf000";
//username = "faf0001";
//password = "faf000";
// Supervisor
//username = "dofer@ujaen.es";
//password = "dofer";
/*
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
SharedPreferences.Editor editor = settings.edit();
editor.putString("username", username);
editor.putString("password", password);
editor.commit();
*/
RestapiWrapper wrapper = PCBcontext.getRestapiWrapper();
if (username.contains("@")){
......@@ -248,88 +246,115 @@ public class SerialActivity extends Activity implements iRestapiListener {
public void result(JSONObject result) {
// Si llego aquí es porque hay un único valor, no un array
try {
Log.d(LOG_TAG, "User:"+result.toString());
// Saco el token y los demás valores
Vector<User> users = new Vector<User>(1);
String jsonToken = result.getString(TAG_TOKEN);
JSONObject user = result.getJSONObject(TAG_USER);
try{
Boolean is_student = user.has(TAG_ISSTUDENT);
if (is_student) {
// Es un estudiante
st_id = user.getInt(TAG_ID);
int st_id_int = st_id.intValue();
String st_name = user.getString(TAG_NAME);
String st_surname = user.getString(TAG_SURNAME);
String st_pic = user.getString(TAG_PIC);
String st_gender = user.getString(TAG_GENDER);
String st_lang = user.getString(TAG_LANG);
String st_attributes = user.getString(TAG_ATTRIBUTES);
//users=PCBcontext.getDevice().getUsers();
//if (users.contains(user)) users.remove(user);
User student = new User(st_id_int, st_name, st_surname, st_pic, st_gender, st_lang, st_attributes,
-1, "", "", "", "M", "es-es", "");
users.add(student);
Log.d(LOG_TAG, "jsonToken válido:" + jsonToken);
//User student = PCBcontext.getDevice().findUser(st_id_int, -1);
//Log.d(LOG_TAG, "student id:" + student.get_id_stu());
PCBcontext.set_user(student, jsonToken, new iImgDownloaderListener() {
@Override
public void loadComplete() {
progressDialog.dismiss();
Intent pictogramActivity = new Intent(SerialActivity.this, PictogramActivity.class);
startActivity(pictogramActivity);
}
@Override
public void loadImg(Img image) {
}
});
PCBcontext.getDevice().synchronizeUsers(users, new iImgDownloaderListener() {
@Override
public void loadComplete() {
}
//Log.d(LOG_TAG, "JSON en result:"+result.toString());
if (result.toString().contains("error")){
progressDialog.dismiss();
AlertDialog.Builder builder = new AlertDialog.Builder(SerialActivity.this);
if (result.toString().contains("Invalid password")){
builder.setMessage("La contraseña indicada no es correcta. Inténtelo de nuevo.")
.setCancelable(false)
.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
}
});
} else if (result.toString().contains("User not found")){
builder.setMessage("El usuario indicado no es correcto. Inténtelo de nuevo.")
.setCancelable(false)
.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
}
});
}
@Override
public void loadImg(Img image) {
Log.d(LOG_TAG, "Load a single image with ID: " + image.get_id());
setContentView(R.layout.activity_serial);
AlertDialog alert = builder.create();
alert.show();
} else{ // No hay error. Sigo
// Saco el token y los demás valores
Vector<User> users = new Vector<User>(1);
String jsonToken = result.getString(TAG_TOKEN);
JSONObject user = result.getJSONObject(TAG_USER);
try{
Boolean is_student = user.has(TAG_ISSTUDENT);
if (is_student) {
// Es un estudiante
st_id = user.getInt(TAG_ID);
int st_id_int = st_id.intValue();
String st_name = user.getString(TAG_NAME);
String st_surname = user.getString(TAG_SURNAME);
String st_pic = user.getString(TAG_PIC);
String st_gender = user.getString(TAG_GENDER);
String st_lang = user.getString(TAG_LANG);
String st_attributes = user.getString(TAG_ATTRIBUTES);
//users=PCBcontext.getDevice().getUsers();
//if (users.contains(user)) users.remove(user);
User student = new User(st_id_int, st_name, st_surname, st_pic, st_gender, st_lang, st_attributes,
-1, "", "", "", "M", "es-es", "");
users.add(student);
Log.d(LOG_TAG, "jsonToken válido:" + jsonToken);
//User student = PCBcontext.getDevice().findUser(st_id_int, -1);
//Log.d(LOG_TAG, "student id:" + student.get_id_stu());
PCBcontext.set_user(student, jsonToken, new iImgDownloaderListener() {
@Override
public void loadComplete() {
progressDialog.dismiss();
Intent pictogramActivity = new Intent(SerialActivity.this, PictogramActivity.class);
startActivity(pictogramActivity);
}
@Override
public void loadImg(Img image) {
}
});
PCBcontext.getDevice().synchronizeUsers(users, new iImgDownloaderListener() {
@Override
public void loadComplete() {
}
@Override
public void loadImg(Img image) {
Log.d(LOG_TAG, "Load a single image with ID: " + image.get_id());
setContentView(R.layout.activity_serial);
}
});
PCBcontext.getDevice().deleteDeprecatedImgs();
} else{
// Es un Supervisor
Log.d(LOG_TAG, "Es un SUPERVISOR. Sigo...");
Log.d(LOG_TAG, "jsonToken válido:" + jsonToken);
Integer su_id = user.getInt(TAG_ID);
int su_id_int = su_id.intValue();
//close the progress dialog
if (!username.contains("@")){
progressDialog.dismiss();
}
});
PCBcontext.getDevice().deleteDeprecatedImgs();
} else{
// Es un Supervisor
Log.d(LOG_TAG, "Es un SUPERVISOR. Sigo...");
Log.d(LOG_TAG, "jsonToken válido:" + jsonToken);
Integer su_id = user.getInt(TAG_ID);
int su_id_int = su_id.intValue();
//close the progress dialog
if (!username.contains("@")){
progressDialog.dismiss();
// Llamo a LoginActivity
Intent loginActivity = new Intent(this, LoginActivity.class);
loginActivity.putExtra("token", jsonToken);
loginActivity.putExtra("sup_id", su_id_int);
startActivity(loginActivity);
}
// Llamo a LoginActivity
Intent loginActivity = new Intent(this, LoginActivity.class);
loginActivity.putExtra("token", jsonToken);
loginActivity.putExtra("sup_id", su_id_int);
startActivity(loginActivity);
} catch (JSONException ex){
//Log.d(LOG_TAG, "ERROR 1");
ex.printStackTrace();
}
} catch (JSONException ex){
//Log.d(LOG_TAG, "ERROR 1");
ex.printStackTrace();
}
} catch (JSONException e) {
//Log.d(LOG_TAG, "ERROR 2");
......
......@@ -4,6 +4,7 @@
<string name="action_entrar">Login</string>
<string name="action_settings">Settings</string>
<string name="app_name">Pictogram</string>
<string name="db_script_error">Fail updating the data base</string>
<string name="error_invalid_serial">These access data are not correct</string>
<string name="prompt_serial_mail">User</string>
......@@ -12,12 +13,12 @@
<string name="title_activity_login_activity_fragment">Users login</string>
<string name="title_activity_login_activity_fragments">Users login</string>
<string name="title_activity_pictogram">PictogramActivity</string>
<string name="title_activity_serial">Write the access data</string>
<string name="title_activity_splash_screen">SplashScreenActivity</string>
<string name="db_script_error">Fail updating the data base</string>
<string name="loginTitle">Who are you?</string>
<string name="toggle_turn_on">Supervisor mode off</string>
<string name="toggle_turn_off">Supervisor mode on</string>
<string name="passErrorTxt">Invalid password</string>
<string name="passErrorMsg">This password is not correct. Try again.</string>
<string name="userErrorTxt">User not found</string>
<string name="userErrorMsg">The user is not correct. Try again.</string>
<!-- Alert dialogs -->
<string name="exitPictogram">Exit Pictogram</string>
......@@ -33,7 +34,6 @@
<string name="cancel">Cancel</string>
<string name="tabletNoYotta">Important: writes this ID number for your cabinet</string>
<string name="loginNoUsers">There are no students assigned with your tablet. Please, ask your cabinet</string>
<string name="serialRepeated"></string>
<!-- Login -->
<string name="systemMessage">System message</string>
......
......@@ -7,7 +7,7 @@
<string name="title_activity_login_activity_fragments">Entrada de usuarios</string>
<string name="title_activity_login_activity_fragment">Entrada de usuarios</string>
<string name="title_activity_pictogram">PictogramActivity</string>
<string name="db_script_error">Error al actualizar la base de datos</string>
<string name="title_activity_splash_screen">SplashScreenActivity</string>
......@@ -16,11 +16,11 @@
<string name="prompt_serial_mail">Usuario</string>
<string name="prompt_serial_pass">Contraseña</string>
<string name="action_entrar">Entrar</string>
<string name="error_invalid_serial">Este nº de serie no es correcto</string>
<string name="loginTitle">¿Quién eres?</string>
<string name="toggle_turn_on">Desactivar modo supervisor</string>
<string name="toggle_turn_off">Activar modo supervisor</string>
<string name="db_script_error">Error al actualizar la base de datos</string>
<string name="passErrorTxt">Invalid password</string>
<string name="passErrorMsg">La contraseña indicada no es correcta. Inténtelo de nuevo.</string>
<string name="userErrorTxt">User not found</string>
<string name="userErrorMsg">El usuario indicado no es correcto. Inténtelo de nuevo.</string>
<!-- Alert dialogs -->
<string name="exitPictogram">Salir de Pictogram</string>
......@@ -36,7 +36,6 @@
<string name="cancel">Cancelar</string>
<string name="tabletNoYotta">Importante: anote este nº de dispositivo para indicárselo al responsable de su asociación o gabinete</string>
<string name="loginNoUsers">No está asignado ningún alumno con tu tablet. Consulte con el responsable de su asociación o gabinete</string>
<string name="serialRepeated">Este tablet ya ha sido registrado previamente o el nº de serie no es correcto. Inténtelo de nuevo o consulte con nuestro servicio técnico</string>
<!-- Login -->
<string name="systemMessage">Mensaje del sistema</string>
......
......@@ -7,7 +7,7 @@
<string name="title_activity_login_activity_fragments">Entrada de usuarios</string>
<string name="title_activity_login_activity_fragment">Entrada de usuarios</string>
<string name="title_activity_pictogram">PictogramActivity</string>
<string name="db_script_error">Error al actualizar la base de datos</string>
<string name="title_activity_splash_screen">SplashScreenActivity</string>
......@@ -16,11 +16,11 @@
<string name="prompt_serial_mail">Usuario</string>
<string name="prompt_serial_pass">Contraseña</string>
<string name="action_entrar">Entrar</string>
<string name="error_invalid_serial">Este nº de serie no es correcto</string>
<string name="loginTitle">¿Quién eres?</string>
<string name="toggle_turn_on">Desactivar modo supervisor</string>
<string name="toggle_turn_off">Activar modo supervisor</string>
<string name="db_script_error">Error al actualizar la base de datos</string>
<string name="passErrorTxt">Invalid password</string>
<string name="passErrorMsg">La contraseña indicada no es correcta. Inténtelo de nuevo.</string>
<string name="userErrorTxt">User not found</string>
<string name="userErrorMsg">El usuario indicado no es correcto. Inténtelo de nuevo.</string>
<!-- Alert dialogs -->
<string name="exitPictogram">Salir de Pictogram</string>
......@@ -36,7 +36,6 @@
<string name="cancel">Cancelar</string>
<string name="tabletNoYotta">Importante: anote este nº de dispositivo para indicárselo al responsable de su asociación o gabinete</string>
<string name="loginNoUsers">No está asignado ningún alumno con tu tablet. Consulte con el responsable de su asociación o gabinete</string>
<string name="serialRepeated">Este tablet ya ha sido registrado previamente o el nº de serie no es correcto. Inténtelo de nuevo o consulte con nuestro servicio técnico</string>
<!-- Login -->
<string name="systemMessage">Mensaje del sistema</string>
......
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