Guest User

Untitled

a guest
Apr 1st, 2018
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.99 KB | None | 0 0
  1. 04-01 15:49:51.910 16167-17235/? E/Volley: [43499] BasicNetwork.performRequest: Unexpected response code 400 for https://securetoken.googleapis.com/v1/token?alt=proto&key=API_KEY
  2. 04-01 15:50:07.573 16167-17232/? E/Volley: [43496] BasicNetwork.performRequest: Unexpected response code 400 for https://securetoken.googleapis.com/v1/token?alt=proto&key=API_KEY
  3. 04-01 15:50:34.689 16167-17233/? E/Volley: [43497] BasicNetwork.performRequest: Unexpected response code 400 for https://securetoken.googleapis.com/v1/token?alt=proto&key=API_KEY
  4.  
  5. package com.rrr.cafemat;
  6.  
  7. import android.app.ProgressDialog;
  8. import android.content.Intent;
  9. import android.content.pm.ActivityInfo;
  10. import android.support.annotation.NonNull;
  11. import android.support.v7.app.AppCompatActivity;
  12. import android.os.Bundle;
  13. import android.util.Patterns;
  14. import android.view.View;
  15. import android.widget.Button;
  16. import android.widget.EditText;
  17. import android.widget.Toast;
  18.  
  19. import com.google.android.gms.tasks.OnCompleteListener;
  20. import com.google.android.gms.tasks.Task;
  21. import com.google.firebase.auth.AuthResult;
  22. import com.google.firebase.auth.FirebaseAuth;
  23. import com.google.firebase.auth.FirebaseUser;
  24. import com.google.firebase.database.DataSnapshot;
  25. import com.google.firebase.database.DatabaseError;
  26. import com.google.firebase.database.DatabaseReference;
  27. import com.google.firebase.database.FirebaseDatabase;
  28. import com.google.firebase.database.ValueEventListener;
  29. import com.rengwuxian.materialedittext.MaterialEditText;
  30. import com.rrr.cafemat.CurrentUser.Client;
  31. import com.rrr.cafemat.Modelo.User;
  32.  
  33. /* .java de activity Sign_in (Iniciar sesión) */
  34.  
  35. public class SignIn extends AppCompatActivity implements View.OnClickListener{
  36.  
  37. //private static final int PER_LOGIN = 1000; //Maximo LogIn a la vez
  38. EditText edtMatricula, edtPassword, edtPhone;
  39. Button btnSignIn, btnSendEmail,btn_about_more,btn_singUp_invitation;
  40. User user;
  41. private String email, password;
  42. //private int emailPress;
  43.  
  44. private FirebaseAuth mAuth;
  45.  
  46. /**
  47. * @param savedInstanceState almacena el estado de instancia
  48. */
  49. @Override
  50. protected void onCreate(Bundle savedInstanceState) {
  51. super.onCreate(savedInstanceState);
  52. setContentView(R.layout.activity_sign_in);
  53.  
  54. mAuth = FirebaseAuth.getInstance(); //Instancia con datos de un usuario
  55.  
  56. //Desactivar rotación
  57. setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
  58.  
  59. edtMatricula = (MaterialEditText)findViewById(R.id.edit_text_matricula);
  60. edtPassword = (MaterialEditText)findViewById(R.id.edit_text_contraseña);
  61. edtPhone = (MaterialEditText)findViewById(R.id.editPhone);
  62.  
  63. btn_singUp_invitation = findViewById(R.id.btn2_invitation);
  64. btn_about_more = findViewById(R.id.btn1_about);
  65. btnSignIn = findViewById(R.id.btn3_sign_in);
  66. btnSendEmail = findViewById(R.id.btnSendEmail);
  67.  
  68.  
  69. btn_about_more.setOnClickListener(this);
  70. btn_singUp_invitation.setOnClickListener(this);
  71.  
  72. //Init Firebase
  73. final FirebaseDatabase database = FirebaseDatabase.getInstance();
  74. final DatabaseReference table_user = database.getReference("User");
  75.  
  76.  
  77. btnSignIn.setOnClickListener(new View.OnClickListener(){
  78.  
  79. /**
  80. * @param view almacena un objeto tipo view (TextView, ImageView,etc)
  81. */
  82. @Override
  83. public void onClick(View view){
  84.  
  85. final ProgressDialog mDialog = new ProgressDialog(SignIn.this);
  86. mDialog.setMessage(getString(R.string.esperar));
  87. mDialog.show();
  88.  
  89. table_user.addValueEventListener(new ValueEventListener() {
  90.  
  91. /**
  92. * @param dataSnapshot almacena una captura de informacion
  93. */
  94. @Override
  95. public void onDataChange(DataSnapshot dataSnapshot) {
  96. boolean nullMat = edtMatricula.getText().toString().equals("");
  97. boolean nullPass = edtPassword.getText().toString().equals("");
  98.  
  99. String matricula = edtMatricula.getText().toString();
  100. String password = edtPassword.getText().toString();
  101.  
  102. //Revisar si usuario no existe en base de datos
  103. if(dataSnapshot.child(matricula).exists() && !(nullMat)) {
  104.  
  105. //Agarra info de usuario
  106. mDialog.dismiss();
  107.  
  108. // Info de user en firebase
  109. user = dataSnapshot.child(matricula).getValue(User.class);
  110.  
  111. if (user.getPassword().equals(password)) { //Contraseña correcta
  112.  
  113. if(!(user.isBan())){ //No tiene ban
  114.  
  115. if(user.isPago()){ //Pago inscripcion
  116.  
  117.  
  118. verifDatos(); //Para ver si datos estan correctos
  119.  
  120. //Si usuario introduce telefono en signIn
  121. boolean phoneNull = edtPhone.getText().toString().equals("");
  122. if(!phoneNull){
  123. String phoneS = edtPhone.getText().toString();
  124. table_user.child(matricula).child("phone").setValue(phoneS);
  125. }
  126. }
  127. else
  128. Toast.makeText(SignIn.this, R.string.no_pay, Toast.LENGTH_SHORT).show();
  129. }
  130. else
  131. Toast.makeText(SignIn.this, R.string.ban, Toast.LENGTH_SHORT).show();
  132. }
  133. else
  134. Toast.makeText(SignIn.this, R.string.fPassword, Toast.LENGTH_SHORT).show();
  135. }
  136. else if(nullMat || nullPass) {
  137. mDialog.dismiss();
  138. Toast.makeText(SignIn.this, R.string.cuentaNull, Toast.LENGTH_SHORT).show();
  139. }
  140. else{
  141. mDialog.dismiss();
  142. Toast.makeText(SignIn.this, R.string.noCuenta, Toast.LENGTH_SHORT).show();
  143. }
  144. }
  145.  
  146. /**
  147. * @param databaseError almacena un error de base de datos
  148. */
  149. @Override
  150. public void onCancelled(DatabaseError databaseError) {
  151.  
  152. }
  153. });
  154. }
  155. });
  156.  
  157. btnSendEmail.setOnClickListener(new View.OnClickListener() {
  158. /**
  159. * @param view almacena un objeto tipo view (TextView, ImageView,etc)
  160. */
  161. @Override
  162. public void onClick(View view) {
  163.  
  164. if(mAuth != null) {
  165. FirebaseUser user = mAuth.getCurrentUser(); //Agarrar Firebase user info
  166.  
  167. if (User.getEmailSent() < 1 && user != null) {
  168.  
  169. if (verifEmail() == 0) {
  170. user.sendEmailVerification().addOnCompleteListener(new OnCompleteListener<Void>() {
  171. /**
  172. * @param task la tarea de mandar un correo de verificacion
  173. */
  174. @Override
  175. public void onComplete(@NonNull Task<Void> task) {
  176. Toast.makeText(SignIn.this, R.string.eVerif_sent, Toast.LENGTH_LONG).show();
  177. User.setEmailSent();
  178. }
  179. });
  180. } else
  181. Toast.makeText(SignIn.this, R.string.eVerified, Toast.LENGTH_LONG).show();
  182. }
  183. else
  184. Toast.makeText(SignIn.this, R.string.eAlready_sent, Toast.LENGTH_SHORT).show();
  185. }
  186. }
  187.  
  188. });
  189. }
  190.  
  191.  
  192.  
  193. private void verifDatos(){
  194. String m = edtMatricula.getText().toString().trim();
  195.  
  196. if((m.charAt(0) == 'a' || m.charAt(0) == 'A') && Character.isDigit(m.charAt(1))) //Estudiante
  197. email = m +"@alumnos.uady.mx";
  198. else { // Maestro
  199. for (int i = 0; i < m.length(); i++){
  200. if(Character.isDigit(m.charAt(i))){
  201. Toast.makeText(SignIn.this, "Introduzca matricula correcta", Toast.LENGTH_SHORT).show();
  202. return;
  203. }
  204. }
  205. email = m + "@correo.uady.mx";
  206. }
  207.  
  208. password = edtPassword.getText().toString().trim();
  209.  
  210. if(!Patterns.EMAIL_ADDRESS.matcher(email).matches()){ //Si no existe email
  211. Toast.makeText(SignIn.this, "Correo no existe", Toast.LENGTH_SHORT).show();
  212. return;
  213. }
  214.  
  215. mAuth.signInWithEmailAndPassword(email, password).addOnCompleteListener(new OnCompleteListener<AuthResult>() {
  216. @Override
  217. public void onComplete(@NonNull Task<AuthResult> task) {
  218. if (task.isSuccessful()) { //Si se puede crear user
  219. // Sign up success
  220. if(verifEmail() == 1) {
  221. Intent intent = new Intent(SignIn.this, LocationFMAT.class);
  222. Client.usuarioActual = user;
  223. startActivity(intent);
  224. finish();
  225.  
  226. }
  227. } else {
  228.  
  229. // If sign in fails, informale al usuario.
  230. Toast.makeText(SignIn.this, "Sign in no valido", Toast.LENGTH_SHORT).show();
  231.  
  232. }
  233. }
  234. });
  235. }
  236.  
  237.  
  238. /**
  239. * @return 0 si correo universitario aun no verificado
  240. * 1 si correo universitario ya verificado
  241. */
  242. private int verifEmail(){
  243. FirebaseUser user = mAuth.getCurrentUser();
  244.  
  245. if(user != null) {
  246.  
  247. if (!(user.isEmailVerified())){ //Email no verificada
  248. Toast.makeText(SignIn.this, R.string.eNoVerified, Toast.LENGTH_SHORT).show();
  249. return 0;
  250. }
  251. else
  252. return 1; //Email verificado
  253. }
  254. else
  255. Toast.makeText(SignIn.this, "Usuario nulo", Toast.LENGTH_SHORT).show();
  256.  
  257. return 0;
  258. }
  259.  
  260. /**
  261. * @param v almacena un objeto tipo view (TextView, ImageView,etc)
  262. */
  263. @Override
  264. public void onClick(View v) {
  265. Intent i;
  266.  
  267. switch (v.getId()) {
  268. case R.id.btn1_about: i = new Intent(this, About.class); startActivity(i);
  269. break;
  270. case R.id.btn2_invitation: i = new Intent(this, SignUp.class); startActivity(i);
  271. break;
  272. }
  273. }
  274. }
  275.  
  276. <?xml version="1.0" encoding="utf-8"?>
  277. <LinearLayout
  278. xmlns:android="http://schemas.android.com/apk/res/android"
  279. xmlns:app="http://schemas.android.com/apk/res-auto"
  280. xmlns:tools="http://schemas.android.com/tools"
  281. android:layout_width="match_parent"
  282. android:layout_height="match_parent"
  283. android:background="@android:color/white"
  284. tools:context="com.rrr.cafemat.SignIn"
  285. android:orientation="vertical">
  286.  
  287. <LinearLayout
  288. android:layout_width="match_parent"
  289. android:layout_height="wrap_content"
  290. android:orientation="vertical"
  291. android:padding="30dp"
  292. android:background="@color/colorPrimaryDark">
  293.  
  294. <TextView
  295. android:id="@+id/text1_logIn"
  296. android:layout_width="wrap_content"
  297. android:layout_height="wrap_content"
  298. android:textSize="40dp"
  299. android:textColor="#fff"
  300. android:text="@string/logIn_activity" />
  301.  
  302. <TextView
  303. android:id="@+id/text2_logIn"
  304. android:layout_width="wrap_content"
  305. android:layout_height="wrap_content"
  306. android:textColor="#fff"
  307. android:text="@string/logIn_activity_description"
  308. android:textSize="15sp"
  309. android:layout_marginTop="25dp"/>
  310.  
  311. <LinearLayout
  312. android:layout_marginTop="50dp"
  313. android:layout_width="wrap_content"
  314. android:layout_height="wrap_content"
  315. android:orientation="horizontal"
  316. android:layout_gravity="center">
  317.  
  318. <Button
  319. android:id="@+id/btn1_about"
  320. android:clickable="true"
  321. android:layout_margin="10dp"
  322. android:textColor="@color/colorPrimaryDark"
  323. android:background="@drawable/buttonstyle"
  324. android:layout_width="wrap_content"
  325. android:layout_height="wrap_content"
  326. android:text="@string/btn1_about"/>
  327.  
  328. <Button
  329. android:id="@+id/btn2_invitation"
  330. android:clickable="true"
  331. android:layout_margin="10dp"
  332. android:textColor="@color/colorPrimaryDark"
  333. android:background="@drawable/buttonstyle"
  334. android:layout_width="wrap_content"
  335. android:layout_height="wrap_content"
  336. android:text="@string/btn2_invitation"/>
  337.  
  338. </LinearLayout>
  339.  
  340.  
  341.  
  342. </LinearLayout>
  343.  
  344. <LinearLayout
  345. android:layout_width="wrap_content"
  346. android:layout_height="15dp">
  347. </LinearLayout>
  348.  
  349. <LinearLayout
  350. android:gravity="center"
  351. android:layout_width="match_parent"
  352. android:layout_height="match_parent"
  353. android:orientation="vertical">
  354.  
  355. <com.rengwuxian.materialedittext.MaterialEditText
  356. android:id="@+id/edit_text_matricula"
  357. android:drawablePadding="5dp"
  358. android:drawableLeft="@drawable/ic_fingerprint_black_24dp"
  359. android:layout_width="300dp"
  360. android:layout_height="wrap_content"
  361. android:hint="@string/editText_1"
  362. android:singleLine="true"/>
  363.  
  364. <com.rengwuxian.materialedittext.MaterialEditText
  365. android:id="@+id/edit_text_contraseña"
  366. android:drawablePadding="5dp"
  367. android:drawableLeft="@drawable/ic_lock_black_24dp"
  368. android:layout_width="300dp"
  369. android:layout_height="wrap_content"
  370. android:hint="@string/editText_2"
  371. android:inputType="textPassword"
  372. android:singleLine="true"/>
  373.  
  374. <com.rengwuxian.materialedittext.MaterialEditText
  375. android:id="@+id/editPhone"
  376. android:drawablePadding="5dp"
  377. android:drawableLeft="@drawable/phone1"
  378. android:layout_width="300dp"
  379. android:layout_height="wrap_content"
  380. android:hint="@string/editText_5_singUp"
  381. android:singleLine="true"
  382. android:inputType="textPassword"/>
  383.  
  384. <LinearLayout
  385. android:layout_marginTop="20dp"
  386. android:layout_width="wrap_content"
  387. android:layout_height="wrap_content"
  388. android:orientation="horizontal"
  389. android:layout_gravity="center">
  390.  
  391. <Button
  392. android:id="@+id/btnSendEmail"
  393. android:clickable="true"
  394. android:layout_marginRight="10dp"
  395. android:drawableRight="@drawable/ic_send_black_24dp"
  396. android:textColor="@color/colorPrimaryDark"
  397. android:background="@drawable/buttonstyle3"
  398. android:layout_width="wrap_content"
  399. android:layout_height="wrap_content"
  400. android:text="Verificar Correo"/>
  401.  
  402. <Button
  403. android:id="@+id/btn3_sign_in"
  404. android:clickable="true"
  405. android:drawablePadding="5dp"
  406. android:drawableRight="@drawable/ic_send_black_24dp"
  407. android:layout_marginTop="0dp"
  408. android:layout_width="160dp"
  409. android:layout_height="wrap_content"
  410. android:background="@drawable/buttonstyle3"
  411. android:text="@string/btn3_sign_in"/>
  412.  
  413. </LinearLayout>
  414.  
  415. </LinearLayout>
  416.  
  417. </LinearLayout>
Add Comment
Please, Sign In to add comment