Esempio n. 1
0
        /// <summary>
        /// 验证用户名密码
        /// </summary>
        /// <param name="userName">用户名</param>
        /// <param name="userPassword">密码</param>
        /// <returns>Models.LoginResult</returns>
        public static LoginResult Authenticate(string userName, string userPassword)
        {
            var result = new LoginResult();
            var icfg   = OpenCfg();

            try
            {
                RequestAuthenticate request = RequestAuthenticate.Create(userName, userPassword);
                IMessage            msg     = icfg.Protocol.Request(request, new TimeSpan(0, 0, 5));
                if (msg.Name == "EventAuthenticated")
                {
                    result.EventAuthenticated = true;
                }
                else if (msg.Name == "EventError")
                {
                    var ev = (EventError)msg;
                    result.ErrorMessage = ev.Description;
                }
            }
            catch (Exception err)
            {
                throw err;
            }
            finally
            {
                CloseCfg(icfg);
            }
            return(result);
        }
Esempio n. 2
0
        /// <summary>
        /// Authenticates the user.
        /// </summary>
        internal OutputValues AuthenticateUser(string userName, string password)
        {
            OutputValues output = new OutputValues();

            try
            {
                RequestAuthenticate requestAuthenticate = RequestAuthenticate.Create(userName, password);
                IMessage            response            = ProtocolManagers.Instance().ProtocolManager[ServerType.Configserver.ToString()].Request(requestAuthenticate);
                if (response != null)
                {
                    switch (response.Id)
                    {
                    case EventAuthenticated.MessageId:
                    {
                        output.MessageCode = "200";
                        output.Message     = "User " + userName + "  Authenticated ";
                        _logger.Info("User " + userName + "  Authenticated ");

                        CfgPersonQuery qPerson = new CfgPersonQuery();
                        qPerson.UserName = userName;

                        CfgPerson person = _configContainer.ConfServiceObject.RetrieveObject <CfgPerson>(qPerson);
                        if (person != null)
                        {
                            CfgTenant tenant = person.Tenant;
                            if (tenant != null)
                            {
                                _configContainer.TenantDbId = tenant.DBID;
                            }
                        }
                        break;
                    }

                    case EventError.MessageId:
                    {
                        EventError eventError = (EventError)response;
                        if (eventError.Description != null)
                        {
                            _logger.Warn("User " + userName + "  is not Authenticated   " + eventError.Description);
                        }
                        output.MessageCode = "2001";
                        output.Message     = "User " + userName + "  not Authenticated ";
                        _logger.Warn("User " + userName + "  is not Authenticated   ");
                        break;
                    }
                    }
                }
            }
            catch (Exception commonException)
            {
                _logger.Error("Error occurred while authenticating user " + userName + "  " + commonException.ToString());
            }
            return(output);
        }
Esempio n. 3
0
        internal static bool AuthenticateUser(string userName, string password)
        {
            bool output = false;

            try
            {
                RequestAuthenticate requestAuthenticate = RequestAuthenticate.Create(userName, password);
                IMessage            response            = _configContainer.ConfServiceObject.Protocol.Request(requestAuthenticate);
                if (response != null)
                {
                    switch (response.Id)
                    {
                    case EventAuthenticated.MessageId:
                    {
                        output = true;
                        _logger.Info("User " + userName + "  Authenticated ");
                        break;
                    }

                    case EventError.MessageId:
                    {
                        EventError eventError = (EventError)response;
                        if (eventError.Description != null)
                        {
                            _logger.Warn("User " + userName + "  is not Authenticated   " + eventError.Description);
                        }
                        output = false;
                        _logger.Warn("User " + userName + "  is not Authenticated   ");
                        break;
                    }
                    }
                }
            }
            catch (Exception commonException)
            {
                _logger.Error("Error occurred while authenticating user " + userName + "  " + commonException.ToString());
            }
            return(output);
        }