Authenticating KeyPressToCommand

Topics: Questions
Feb 24, 2013 at 6:35 PM
Hi.
I want to use catel authentication provider but i have an issue with it.
How can i authenticate KeyPressToCommand behavior? Now if an unhallowed user for example presses Ctrl + S command works (but it should not to work!)
Coordinator
Feb 25, 2013 at 6:26 AM
Did you provide a tag for the command on the VM? In the end, all catel commands are forwarded to the authentication provider. Can you provide a repro?
Feb 25, 2013 at 6:57 AM
How can i provide tag for command in VM?
Coordinator
Feb 25, 2013 at 7:06 AM
Feb 25, 2013 at 12:35 PM
My application has two type of users: Administrator and Guest. Administrator has full access but Guest has limited access. for example i have a button for Delete command that has an access key like Ctrl + D.
this is my AuthenticationProvider :
 public string Role { get; set; }

        public bool CanCommandBeExecuted(ICatelCommand command, object commandParameter)
        {
            return true;
        }

        public bool HasAccessToUIElement(System.Windows.FrameworkElement element, object tag, object authenticationTag)
        {
            var authenticationTagAsString = authenticationTag as string;
            if (authenticationTagAsString != null)
            {
                if (string.Compare(authenticationTagAsString, Role, true) == 0)
                {
                    return true;
                }
            }

            return false;
        }
and this is my Delete command in constructor:
Delete = new Command(OnDeleteExecute, OnDeleteCanExecute, tag: "Guest");
how can i use command tag for limiting guest user for executing a command?
please provide an example in to catelexamples project that shows how to use command tags.

thanks.
Coordinator
Feb 25, 2013 at 3:54 PM
A command is not a UI Element. You have implemented the HasAccessToUIElement, but not the CanCommandBeExecuted. You must implement the latter for commands.
Also, it's better to use String.Equals (then you don't have to check for == 0).