/// <summary>
 /// Valide ou non la connection
 /// </summary>
 /// <param name="userName"></param>
 /// <param name="password"></param>
 public override void Validate(string userName, string password)
 {
     try
     {
         if (!UserAccessModel.UserValid(userName, password))
         {
             throw new FaultException("Either the user or the password is invalid");
         }
     }
     catch (FaultException fe)
     {
         throw fe;
     }
     catch (Exception e)
     {
         throw new FaultException(e.Message);
     }
 }
Exemple #2
0
        /// <summary>
        /// Appelé avant l'invocation
        /// </summary>
        /// <param name="operationName"></param>
        /// <param name="inputs"></param>
        /// <returns></returns>
        public object BeforeCall(string operationName, object[] inputs)
        {
            if (inputs == null || inputs.Length == 0)
            {
                throw new FaultException <InputValidationFaultContract>(new InputValidationFaultContract()
                {
                    Error = "Inputs are required"
                }, "No inputs");
            }

            String name = inputs[0].ToString(), token = inputs[1].ToString();

            if (name == null || name.Count() == 0 || token == null || token.Count() == 0)
            {
                throw new FaultException <InputValidationFaultContract>(new InputValidationFaultContract()
                {
                    Error = "No valid data provided"
                }, "Invalid data");
            }


            if (!UserAccessModel.UserExists(name))
            {
                throw new FaultException <InputValidationFaultContract>(new InputValidationFaultContract()
                {
                    Error = "User not registered in database"
                }, "User not registered");
            }

            if (!Boolean.Parse(ValidateToken("SystemAdministrator", "defaultpassword", token).Result))
            {
                throw new FaultException <InputValidationFaultContract>(new InputValidationFaultContract()
                {
                    Error = "Invalid Token"
                }, "Invalid Token");
            }

            return(null);
        }