/// <summary> /// Éste metodo valida si el cliente existe y retorna la entidad representando el cliente /// </summary> /// <param name="userName"> /// Nombre de usuario del cliente /// </param> /// <param name="password"> /// Clave del cliente /// </param> /// <returns>La entidad del Cliente</returns> public static CustomerEntity ValidateAndGetCustomer(string userName, string password) { if (String.IsNullOrEmpty(userName) || String.IsNullOrEmpty(password)) { throw new ArgumentException( global::PresentationLayer.GeneralResources.UserNameEmpty); } Collection <CustomerEntity> customers = new Collection <CustomerEntity>(); SessionManagerClient sessionManagerClient = new SessionManagerClient(SessionManagerClient.CreateDefaultBinding(), new EndpointAddress(UtnEmall.Client.SmartClientLayer.Connection.ServerUri + "SessionManager")); string session = sessionManagerClient.ValidateCustomer(userName, Utilities.CalculateHashString(password)); CustomerClient customerClient = new CustomerClient(CustomerClient.CreateDefaultBinding(), new EndpointAddress(UtnEmall.Client.SmartClientLayer.Connection.ServerUri + "Customer")); customers = customerClient.GetCustomerWhereEqual(CustomerEntity.DBUserName, userName, true, session); if (customers.Count == 0) { throw new UtnEmallBusinessLogicException( global::PresentationLayer.GeneralResources.LoginFailedUserIncorrect); } string passwordHash = Utilities.CalculateHashString(password); CustomerEntity customer = customers[0]; if (String.Compare(customer.Password, passwordHash, StringComparison.Ordinal) != 0) { throw new UtnEmallBusinessLogicException( global::PresentationLayer.GeneralResources.LoginFailedPasswordIncorrect); } return(customer); }
/// <summary> /// Itenta obtener la configuración del usuario (cliente) y pregunta por uno nuevo si no encuentra configuración previa /// </summary> /// <returns>True si el usuario se configuro exitosamente</returns> public bool ConfigureCustomer() { bool existCustomerConfiguration = CheckCustomerConfiguration(); if (!existCustomerConfiguration) { try { SessionManagerClient sessionManagerClient = new SessionManagerClient(SessionManagerClient.CreateDefaultBinding(), new EndpointAddress(UtnEmall.Client.SmartClientLayer.Connection.ServerUri + "SessionManager")); sessionManagerClient.ValidateCustomer("", ""); CustomerConfigurationForm customerConfigurationForm = new CustomerConfigurationForm(); customerConfigurationForm.Owner = mainMenu; customerConfigurationForm.ShowDialog(); } catch (TargetInvocationException invocationException) { Debug.WriteLine(invocationException.Message); HelpForm helpForm = new HelpForm(global::PresentationLayer.GeneralResources.ServerNotFoundHelp); helpForm.ShowDialog(); return(false); } catch (CommunicationException communicationError) { Debug.WriteLine(communicationError.Message); HelpForm helpForm = new HelpForm(global::PresentationLayer.GeneralResources.ServerNotFoundHelp); helpForm.ShowDialog(); return(false); } } return(true); }