Example #1
0
        /// <summary>
        /// Execute the query
        /// </summary>
        /// <param name="trxContext"></param>
        /// <param name="vo"></param>
        /// <returns></returns>
        public override ValueObject Execute(TransactionContext trxContext, ValueObject vo)
        {
            LoginInVo inVo = (LoginInVo)vo;

            StringBuilder sqlQuery = new StringBuilder();

            sqlQuery.Append(" select Count(*) userCount");
            sqlQuery.Append(" from m_login_password lp");
            sqlQuery.Append(" inner join m_mes_user usr on usr.user_cd = lp.user_cd ");
            sqlQuery.Append(" inner join m_user_factory usrfac on usr.user_cd = usrfac.user_cd ");
            sqlQuery.Append(" inner join m_factory fac on usrfac.factory_cd = fac.factory_cd ");
            sqlQuery.Append(" where usr.user_cd = :usercode ");
            sqlQuery.Append(" and lp.password = :password ; ");

            LoginOutVo outVo = new LoginOutVo();

            DbCommandAdaptor sqlCommandAdapter = base.GetDbCommandAdaptor(trxContext, sqlQuery.ToString());

            //create parameter
            DbParameterList sqlParameter = sqlCommandAdapter.CreateParameterList();

            sqlParameter.AddParameter("usercode", inVo.InputUserId);
            sqlParameter.AddParameter("password", inVo.InputPassword);

            //execute SQL
            IDataReader dataReader = sqlCommandAdapter.ExecuteReader(trxContext, sqlParameter);

            while (dataReader.Read())
            {
                outVo.ResultCount = Convert.ToInt32(dataReader["userCount"]);
            }

            dataReader.Close();
            return(outVo);
        }
Example #2
0
        /// <summary>
        /// Bind UserData by loggedin user
        /// </summary>
        /// <returns></returns>
        private UserData BindLoggedInUserData()
        {
            LoginInVo inVo = new LoginInVo
            {
                InputUserId   = LoginName_txt.Text,
                InputPassword = Password_txt.Text
            };

            LoginOutVo outVo = null;

            try
            {
                outVo = (LoginOutVo)DefaultCbmInvoker.Invoke(loginCbm, inVo);
            }
            catch (ApplicationException exception)
            {
                popUpMessage.ApplicationError(exception.GetMessageData(), Text);
                return(null);
            }

            if (outVo == null)
            {
                messageData = new MessageData("llce00005", Properties.Resources.llce00005, inVo.InputUserId);
                Logger.Info(messageData);
                popUpMessage.Information(messageData, this.Text);
                return(null);
            }

            //Get empty userdata
            UserData userData = UserData.GetUserData();

            userData.UserCode        = outVo.UserId;
            userData.UserName        = outVo.UserName;
            userData.LocaleId        = outVo.LocaleId;
            userData.LanguageCode    = outVo.LanguageCode;
            userData.Country         = outVo.CountryCode;
            userData.FactoryCodeList = outVo.FactoryCodeList;
            userData.ControlList     = outVo.ControlList;
            userData.IpAddress       = LocalIpAddress();

            string currentCulture = outVo.LanguageCode + "-" + outVo.CountryCode;

            CultureInfo newCulture = CultureInfo.CreateSpecificCulture(currentCulture);

            Thread.CurrentThread.CurrentCulture   = newCulture;
            Thread.CurrentThread.CurrentUICulture = newCulture;

            userData.DateTimeFormat = newCulture.DateTimeFormat;
            userData.NumberFormat   = newCulture.NumberFormat;

            //sessionid for each loggedin user
            userData.SessionId = userData.UserCode + System.Guid.NewGuid().ToString();

            return(userData);
        }
Example #3
0
        /// <summary>
        /// Execute the query
        /// </summary>
        /// <param name="trxContext"></param>
        /// <param name="vo"></param>
        /// <returns></returns>
        public override ValueObject Execute(TransactionContext trxContext, ValueObject vo)
        {
            LoginInVo inVo = (LoginInVo)vo;

            StringBuilder sqlQuery = new StringBuilder();

            sqlQuery.Append(" select distinct usr.user_cd,usr.user_name,cn.country,cn.language,cn.locale_id, ");
            sqlQuery.Append(" fac.factory_cd,usrfac.display_order,actrl.authority_control_cd");
            sqlQuery.Append(" from m_mes_user usr ");
            sqlQuery.Append(" inner join m_country_language cn on usr.locale_id = cn.locale_id");
            sqlQuery.Append(" inner join m_user_factory usrfac on usr.user_cd = usrfac.user_cd ");
            sqlQuery.Append(" inner join m_factory fac on usrfac.factory_cd = fac.factory_cd ");
            sqlQuery.Append(" left join m_mes_user_role usrrol on usrrol.user_cd = usr.user_cd ");
            sqlQuery.Append(" left join m_mes_role rol on rol.role_cd = usrrol.role_cd ");
            sqlQuery.Append(" left join m_role_authority_control rolactrl on rolactrl.role_cd = rol.role_cd ");
            sqlQuery.Append(" left join m_authority_control actrl on actrl.authority_control_cd = rolactrl.authority_control_cd ");
            sqlQuery.Append(" where usr.user_cd = :usercode ");
            sqlQuery.Append(" order by usrfac.display_order; ");

            LoginOutVo outVo = new LoginOutVo();

            DbCommandAdaptor sqlCommandAdapter = base.GetDbCommandAdaptor(trxContext, sqlQuery.ToString());

            //create parameter
            DbParameterList sqlParameter = sqlCommandAdapter.CreateParameterList();

            sqlParameter.AddParameter("usercode", inVo.InputUserId);

            //execute SQL
            IDataReader dataReader = sqlCommandAdapter.ExecuteReader(trxContext, sqlParameter);

            int recordCount = 0;

            String FactoryCode;
            String AuthorityCode;

            while (dataReader.Read())
            {
                if (recordCount == 0)
                {
                    outVo.UserId       = ConvertDBNull <string>(dataReader, "user_cd");
                    outVo.UserName     = ConvertDBNull <string>(dataReader, "user_name");
                    outVo.LocaleId     = ConvertDBNull <int>(dataReader, "locale_id");
                    outVo.CountryCode  = ConvertDBNull <string>(dataReader, "country");
                    outVo.LanguageCode = ConvertDBNull <string>(dataReader, "language");
                }

                FactoryCode = ConvertDBNull <string>(dataReader, "factory_cd");
                if (!outVo.FactoryCodeList.Contains(FactoryCode))
                {
                    outVo.FactoryCodeList.Add(FactoryCode);
                }

                AuthorityCode = ConvertDBNull <string>(dataReader, "authority_control_cd");
                if (!outVo.ControlList.Contains(AuthorityCode))
                {
                    outVo.ControlList.Add(AuthorityCode);
                }
                recordCount += 1;
            }
            if (recordCount == 0)
            {
                outVo = null;
            }

            dataReader.Close();
            return(outVo);
        }
Example #4
0
        /// <summary>
        /// Execute the dao
        /// </summary>
        /// <param name="trxContext"></param>
        /// <param name="vo"></param>
        /// <returns></returns>
        public ValueObject Execute(TransactionContext trxContext, ValueObject vo)
        {
            LoginInVo inVo = (LoginInVo)vo;

            LoginOutVo outVo = new LoginOutVo();

            string ldapConnectionHost = ConfigurationDataTypeEnum.LDAP_CONNECTION_HOST.GetValue(); //Properties.Settings.Default.LdapConnectionHost;
            string searchDN           = "dc=nidec,dc=com";
            string searchFilterFormat = "(&(exgEnabledFlag=enabled)(uid={0}))";
            string distinguishedName  = string.Empty;

            // search DistinguishedName
            LdapConnection ldapconnection = new LdapConnection(ldapConnectionHost);

            ldapconnection.AuthType = AuthType.Anonymous;
            ldapconnection.SessionOptions.ProtocolVersion = 3;
            ldapconnection.Bind();

            SearchRequest searchRequest = new SearchRequest(
                searchDN,
                string.Format(searchFilterFormat, inVo.InputUserId),
                SearchScope.Subtree
                );
            SearchResponse response = null;

            try
            {
                response = (SearchResponse)ldapconnection.SendRequest(searchRequest);
            }
            catch (ObjectDisposedException ex)
            {
                MessageData messageData = new MessageData("llce00014", Properties.Resources.llce00014, ex.Message);

                SystemException sysEx = new SystemException(messageData, ex);

                throw sysEx;
            }
            catch (ArgumentNullException ex)
            {
                MessageData messageData = new MessageData("llce00015", Properties.Resources.llce00015, ex.Message);

                SystemException sysEx = new SystemException(messageData, ex);

                throw sysEx;
            }
            catch (NotSupportedException ex)
            {
                MessageData messageData = new MessageData("llce00016", Properties.Resources.llce00016, ex.Message);

                SystemException sysEx = new SystemException(messageData, ex);

                throw sysEx;
            }
            catch (LdapException ex)
            {
                MessageData messageData = new MessageData("llce00017", Properties.Resources.llce00017, ex.Message);

                SystemException sysEx = new SystemException(messageData, ex);

                throw sysEx;
            }
            catch (DirectoryOperationException ex)
            {
                MessageData messageData = new MessageData("llce00018", Properties.Resources.llce00018, ex.Message);

                SystemException sysEx = new SystemException(messageData, ex);

                throw sysEx;
            }


            if (response != null)
            {
                SearchResultEntryCollection collection = response.Entries;

                foreach (SearchResultEntry searchResultEntry in collection)
                {
                    distinguishedName = searchResultEntry.DistinguishedName;
                    break;
                }
            }

            // authenticate
            if (string.IsNullOrEmpty(distinguishedName))
            {
                outVo.ResultCount = 0;
                return(outVo);// user does not exist.
            }

            ldapconnection.AuthType = AuthType.Basic;
            ldapconnection.SessionOptions.ProtocolVersion = 3;
            try
            {
                ldapconnection.Bind(new NetworkCredential(distinguishedName, inVo.InputPassword));
            }
            catch (ObjectDisposedException ex)
            {
                MessageData messageData = new MessageData("llce00019", Properties.Resources.llce00019, ex.Message);

                SystemException sysEx = new SystemException(messageData, ex);

                throw sysEx;
            }
            catch (LdapException ex)
            {
                MessageData messageData = new MessageData("llce00020", Properties.Resources.llce00020, ex.Message);

                SystemException sysEx = new SystemException(messageData, ex);

                throw sysEx;
            }
            catch (InvalidOperationException ex)
            {
                MessageData messageData = new MessageData("llce00021", Properties.Resources.llce00021, ex.Message);

                SystemException sysEx = new SystemException(messageData, ex);

                throw sysEx;
            }
            outVo.ResultCount = 1;
            return(outVo);
        }