Limit access in app areas for different users

0

I'm working on an app project for a company and I ended up getting into a problem I did not find how to fix it.

I'd like to limit access to certain parts of the app to different users.

Ex: I would like company administrators with their logins to see things in the app that employees, with their logins, could not see.

  • Allow only admin-only pages, so other users can not access.

I'm using Firebase and Android Studio , I'd like to know if there's a class or API for it.

    
asked by anonymous 28.09.2017 / 04:46

2 answers

1

1. You have to have value that defines who is admin or user in your user bank. Example: level="admin"          level="official"

  • You can use the Realtime Database Firebase. to create a new user. Example.

    private void writeNewUserIfNeeded(final String userId, final String username, final String name) {
    final DatabaseReference usersRef = rootRef.child("users").child(userId);
    
    usersRef.addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            if (!dataSnapshot.exists())
                usersRef.setValue(new User(username, name));
        }
    
        @Override
        public void onCancelled(DatabaseError databaseError) {
    
        }
    });
    

    }

  • 3.At each screen call that you want to limit to the user level you have to make a condition. Example:

           if(user.nivel.equals("admin")){
    
            //ABRIR A TELA PARA ADMIN
            }else{
            // BLOQUEADO! 
            }
    
        
    28.09.2017 / 05:19
    0

    You could add view conditions, for example:

    By signing in the method would return the group that the user would belong to

    public GrupoDeUsuario autenticar(usuario, senha){
    
    } 
    
    boolean isAdm = GrupoDeUsuario.Administrador;
    

    In your Views you could check and only show View if it was for the interest group

    btnAcessoPeloAdm = findViewByID(R.id.btnAdm);
    btnAcessoPeloAdm.setVisibility(isAdm ? View.VISIBLE : View.GONE);
    
        
    29.09.2017 / 18:27