/// <summary>
        /// Obtiene la cuenta de usuario asociado al token generado
        /// </summary>
        /// <param name="token">Token generado</param>
        /// <returns>Cuenta de Usuario</returns>
        public CuentaUsuario ObtenerUsuarioPorToken(string token)
        {
            CuentaUsuario resultado = null;

            if (token != null)
            {
                AuthenticateServiceClient service = new AuthenticateServiceClient();
                WebUser oWebUser = service.GetUserByToken(token);
                resultado = CuentaUsuarioAdapter.ObtenerCuentaUsuario(oWebUser);
            }
            return(resultado);
        }
 /// <summary>
 /// btnLogin_Click event.
 /// </summary>
 /// <param name="sender">Sender object.</param>
 /// <param name="e">Event arguments.</param>
 protected void btnLogin_Click(object sender, EventArgs e)
 {
     try
     {
         string userName = txtUserName.Text;
         string password = txtPassword.Text;
         int    status   = 0;
         if (!string.IsNullOrEmpty(userName) || !string.IsNullOrEmpty(password))
         {
             AuthenticateServiceClient client = new AuthenticateServiceClient();
             status = client.AuthenticateUser(userName, password);
             if (status == 1)
             {
                 Response.Redirect("SuccessfulAuthenticate.aspx", false);
             }
         }
     }
     catch (Exception ex)
     {
         Logger.Log(ex, "Exception occure in authenticating an user", Framework.Enums.Enums.ErrorLevel.ERROR);
     }
 }
Exemple #3
0
        private static bool _authenticate(CswNbtResources CswNbtResources, out string ErrorMsg)
        {
            ErrorMsg = "";
            bool ret = false;

            try
            {
                string cwUsername = CswNbtResources.ConfigVbls.getConfigVariableValue(CswEnumNbtConfigurationVariables.chemwatchusername.ToString());
                string cwPassword = CswNbtResources.ConfigVbls.getConfigVariableValue(CswEnumNbtConfigurationVariables.chemwatchpassword.ToString());
                string cwDomain   = CswNbtResources.ConfigVbls.getConfigVariableValue(CswEnumNbtConfigurationVariables.chemwatchdomain.ToString());

                AuthenticateServiceClient cwAuthClient = new AuthenticateServiceClient();
                cwAuthClient.Endpoint.Behaviors.Add(_cookieBehavior);
                UserCredential cwUserCredential = new UserCredential()
                {
                    UserName = cwUsername,
                    Password = cwPassword,
                    //TODO: Uncomment below when Alexei from ChemWatch provides us with new Authentication service
                    //Domain = cwDomain
                };
                GeneralResponseOfAuthenticationResponse cwAuthResponse = cwAuthClient.Authenticate(cwUserCredential);   //providing invalid credentials will throw an exception
                if (cwAuthResponse.ErrorCode == 0)
                {
                    ret = true;
                }
                else
                {
                    ErrorMsg = cwAuthResponse.ErrorMessage;
                }
            }
            catch (Exception ex)
            {
                ErrorMsg = ex.Message;
            }
            return(ret);
        }