Beispiel #1
0
        public bool Login(string userName, string password, out Guid key)
        {
            key = Guid.Empty;

            //TODO: Need to change this so that it sends back Invalid username or password if the credentials are invalid and some other message for errors
            try
            {
                Business.UserAccount userAccount = null;
                if (!Utility.Global.GetUserDataAccessor().ValidateUserCredentials(userName, password, out userAccount))
                {
                    return(false);
                }

                //If the user is already logged in, we need to disconnect the existing connection and remove him from the list of connected clients
                RemoveUser(userAccount.Id);

                //Get the call back for the client
                IAuthenticationServiceCallback callback = OperationContext.Current.GetCallbackChannel <IAuthenticationServiceCallback>();

                //Create a CommunicationsStore to hold information about the connected client
                AuthenticationCommunicationsStore client = new AuthenticationCommunicationsStore(OperationContext.Current.InstanceContext, callback);
                client.UserAccount = userAccount;
                if (!OperationContext.Current.IncomingMessageProperties.ContainsKey(RemoteEndpointMessageProperty.Name))
                {
                    //This is for dev connections.
                    client.IPAddress = "127.0.0.1";
                }
                else
                {
                    client.IPAddress = ((RemoteEndpointMessageProperty)OperationContext.Current.IncomingMessageProperties[RemoteEndpointMessageProperty.Name]).Address;
                }

                //TODO:May need to lock the list here for thread safety
                key = Guid.NewGuid();
                AuthenticatedClients.Add(key, client);

                return(true);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                return(false);
            }
        }
Beispiel #2
0
 public AuthenticationCommunicationsStore(InstanceContext instanceContext, IAuthenticationServiceCallback callback)
 {
     this.InstanceContext = instanceContext;
     this.Callback        = callback;
 }