Guest User

Untitled

a guest
Nov 24th, 2017
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.66 KB | None | 0 0
  1. <?php
  2. require_once('../Con/Conexion.php');
  3. $username = $_POST['userName'];
  4. $passw = $_POST['userPwd'];
  5. $statement=mysqli_prepare($connection,"SELECT idTrabajador,`Nombre del Trabajador`,`Unidades por Vender` FROM `tablausuario` WHERE `Usuario`=? AND Contrasena=?");
  6. mysqli_stmt_bind_param($statement,"ss",$username,$passw);
  7. mysqli_stmt_execute($statement);
  8. mysqli_stmt_store_result($statement);
  9. mysqli_stmt_bind_result($statement,$idTrabajador,$name,$uxv);
  10. $response = array();
  11. $response["success"] = false;
  12. while(mysqli_stmt_fetch($statement)){
  13. $response["success"] = true;
  14. $response["idTrabajador"] = $idTrabajador;
  15. $response["Nombre del Trabajador"] = $name;
  16. $response["Unidades por Vender"] = $uxv;
  17. }
  18. echo json_encode($response);
  19. mysqli_close($connection);
  20. ?>
  21.  
  22. public class LoginActivity extends AppCompatActivity {
  23.  
  24. EditText editUsuario, editPass;
  25. Button btnLogin, btnOlvide;
  26. ImageView img;
  27. @Override protected void onCreate(Bundle savedInstanceState) {
  28. super.onCreate(savedInstanceState);
  29. setContentView(R.layout.activity_login);
  30.  
  31. editUsuario = (EditText) findViewById(R.id.userLog);
  32. editPass = (EditText) findViewById(R.id.passLog);
  33. btnLogin = (Button) findViewById(R.id.btnLog);
  34. btnOlvide = (Button) findViewById(R.id.btnolvLog);
  35. img = (ImageView) findViewById(R.id.imgL);
  36.  
  37. Display display = getWindowManager().getDefaultDisplay();
  38. int heg = display.getHeight();
  39. img.setMaxHeight(heg/3);
  40.  
  41. btnLogin.setOnClickListener(new View.OnClickListener() {
  42. @Override
  43. public void onClick(View v) {
  44. final String userPass = editPass.getText().toString();
  45. final String userNam = editUsuario.getText().toString();
  46. Response.Listener<String> responseListener = new Response.Listener<String>() {
  47. @Override
  48. public void onResponse(String response) {
  49. try {
  50. JSONObject jsonResponse = new JSONObject(response);
  51. boolean success = jsonResponse.getBoolean("success");
  52. if (success) {
  53. String idTra = jsonResponse.getString("idTrabajador");
  54. String naMe = jsonResponse.getString("Nombre del Trabajador");
  55. String uxv = jsonResponse.getString("Unidades por Vender");
  56. Intent openLog = new Intent(LoginActivity.this, MenuPrincipal.class);
  57. openLog.putExtra("idTrabajador", idTra);
  58. openLog.putExtra("Nombre del Trabajador", naMe);
  59. openLog.putExtra("Unidades por Vender", uxv);
  60. LoginActivity.this.startActivity(openLog);
  61. } else {
  62. AlertDialog.Builder builder = new AlertDialog.Builder(LoginActivity.this);
  63. builder.setMessage("Error de Login, Verifique su conexion o los datos ingresados")
  64. .setNegativeButton("Reintentar", null).create().show();
  65.  
  66. }
  67. } catch (JSONException e) {
  68. e.printStackTrace();
  69. }
  70. }
  71. };
  72. RequestLogin loginRequest = new RequestLogin(userNam, userPass, responseListener);
  73. RequestQueue queue = Volley.newRequestQueue(LoginActivity.this);
  74. queue.add(loginRequest);
  75. }
  76. });
  77.  
  78.  
  79. btnOlvide.setOnClickListener(new View.OnClickListener() {
  80. @Override
  81. public void onClick(View v) {
  82. Intent emailIntent = new Intent(Intent.ACTION_SEND);
  83. emailIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{"XXX"});
  84. emailIntent.putExtra(Intent.EXTRA_CC, new String[]{"XXX"});
  85. emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Resetear la contraseña");
  86. //Recordad que la barra invertida más "n" es un salto de linea "n" así, escribiremos el email con varios saltos de linea.
  87. String textoApp = "Buenas tardes. rnrn" +
  88. "He olvidado mi Contraseña, solicito el reseteo de la misma. rnrn " +
  89. "Mi nombre completo es: rnrn" +
  90. "Mi usuario es:rnrn" +
  91. "Numero de contacto:rnrn" +
  92. "Gracias.";
  93. emailIntent.putExtra(Intent.EXTRA_TEXT, textoApp);
  94. emailIntent.setType("message/rfc822");
  95. //Damos la opción al usuario que elija desde que app enviamos el email.
  96. startActivity(Intent.createChooser(emailIntent, "Selecciona aplicación de Correo..."));
  97. }
  98. });
  99. }
  100. @Override
  101. public void onBackPressed() {
  102. super.onBackPressed();
  103. System.exit(0);
  104. }
Add Comment
Please, Sign In to add comment