android - User login can'd identify user position -


user register student or tutor during registration saved in firebase database when login cannot identify user position saved in firebase database should do? please can give suggestion or advice me how this.

the database save uid email authentication node under root rest details children of uid.

enter image description here

the code this

 private firebaseauth auth; private edittext un, pw; private string getun, getpw, uid; private button bl; private firebasedatabase db; private databasereference ref;  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_login);      auth = firebaseauth.getinstance();     db = firebasedatabase.getinstance();     ref = db.getreference();     uid = auth.getcurrentuser().getuid();     ref = db.getreference("users").child(uid);      un = (edittext) findviewbyid(r.id.lun);     pw = (edittext) findviewbyid(r.id.lpw);      bl = (button) findviewbyid(r.id.lbt);      final textview rl = (textview) findviewbyid(r.id.lreg);      //login     bl.setonclicklistener(new view.onclicklistener() {         @override         public void onclick(view v) {             getun = un.gettext().tostring().trim();             getpw = pw.gettext().tostring().trim();             loginaction(getun, getpw);         }     });      //open register page     rl.setonclicklistener(new view.onclicklistener() {         @override         public void onclick(view v) {             intent ri = new intent(login.this,register.class);             login.this.startactivity(ri);         }     }); }   private void loginaction(string a, string b){      auth.signinwithemailandpassword(a, b).addoncompletelistener(this, new oncompletelistener<authresult>() {         @override         public void oncomplete(@nonnull task<authresult> task) {             log.d("login", "login success" + task.issuccessful());              if (!task.issuccessful()) {                 log.w("login", "login failed", task.getexception());                 toast.maketext(login.this, "login failed. please try again", toast.length_short).show();              }else{                  toast.maketext(login.this, "login success", toast.length_short).show();                  ref.orderbychild("position").addvalueeventlistener(new valueeventlistener() {                     @override                     public void ondatachange(datasnapshot datasnapshot) {                              string ps  = datasnapshot.getvalue().tostring();                              if(ps.equalsignorecase("student")){                                  intent = new intent(login.this, studenthomepage.class);                                 startactivity(i);                              }else if (ps.equalsignorecase("tutor")){                                  intent = new intent(login.this, tutorhomepage.class);                                 startactivity(i);                              }else{                                  toast.maketext(login.this,                                         "wrong input. please check again email , password.", toast.length_short).show();                                 return;                             }                     }                      @override                     public void oncancelled(databaseerror databaseerror) {                      }                 });              }              // ...         }     });  } 

create 2 child nodes users. 1 students , 1 tutors.(give both child values value of true, otherwise firebase doesn't save children.)

firebase tree structure

have 2 registration buttons ..one students , 1 tutors. registration tutor code.....

mregistration.setonclicklistener(new    view.onclicklistener() {         @override         public void onclick(view v) {             final string email = memail.gettext().tostring();             final string password = mpassword.gettext().tostring();             mauth.createuserwithemailandpassword(email,password).addoncompletelistener(driverloginactivity.this, new oncompletelistener<authresult>() {                 @override                 public void oncomplete(@nonnull task<authresult> task) {                     if (!task.issuccessful()){                         toast.maketext(tutorsloginactivity.this, "sign in error", toast.length_short).show();                     }else{                         string user_id= mauth.getcurrentuser().getuid();                         databasereference current_user_db= firebasedatabase.getinstance().getreference().child("users").child("tutors").child(user_id);                         current_user_db.setvalue(true);                      }                  }             });          }      }); 

do same students. change .child("tutors") .child("students") give uids 2 different groups. , can same when logging in. think better way proceed.


Comments

Popular posts from this blog

Sort a complex associative array in PHP -

vb.net - How to ignore if a cell is empty nothing -

recursion - Can every recursive algorithm be improved with dynamic programming? -