Exemple #1
0
        public IHttpActionResult Logon(LogonInfo jsonData)
        {
            if (jsonData == null)
            {
                throw new ArgumentNullException("jsonData", "jsonData cannot be a null reference (Nothing in Visual Basic)!");
            }
            if (string.IsNullOrEmpty(jsonData.Account))
            {
                throw new NullReferenceException("jsonData.Account cannot be a null reference (Nothing in Visual Basic)!");
            }
            if (string.IsNullOrEmpty(jsonData.Password))
            {
                throw new NullReferenceException("jsonData.Password cannot be a null reference (Nothing in Visual Basic)!");
            }
            string mRetVal       = "false";
            bool   mDomainPassed = false;

            if (jsonData.Account.Contains("\\"))
            {
                mDomainPassed = true;
            }
            if (ConfigSettings.AuthenticationType.ToUpper() == "LDAP" & !mDomainPassed)
            {
                jsonData.Account = ConfigSettings.LdapDomain + "\\" + jsonData.Account;
            }
            if (AccountUtility.Authenticated(jsonData.Account, jsonData.Password))
            {
                MAccountProfile mAccountProfile = AccountUtility.GetProfile(jsonData.Account);
                mAccountProfile.LastLogOn = DateTime.Now;
                if (mAccountProfile.Status == Convert.ToInt32(SystemStatus.Disabled))
                {
                    mAccountProfile.Status = Convert.ToInt32(SystemStatus.Active);
                }
                mAccountProfile.FailedAttempts = 0;
                AccountUtility.Save(mAccountProfile, false, false);
                AccountUtility.SetPrincipal(mAccountProfile);
                mRetVal = "true";
            }
            else
            {
                MAccountProfile mAccountProfile = AccountUtility.GetProfile(jsonData.Account);
                if (mAccountProfile != null)
                {
                    if (mAccountProfile.Account.ToUpper(new CultureInfo("en-US", false)) == jsonData.Account.ToUpper(new CultureInfo("en-US", false)))
                    {
                        if (ConfigSettings.AuthenticationType.ToUpper() == "INTERNAL")
                        {
                            if (mAccountProfile.Status != Convert.ToInt32(SystemStatus.Disabled) || mAccountProfile.Status != Convert.ToInt32(SystemStatus.Inactive))
                            {
                                mRetVal = "Request";
                            }
                            else
                            {
                                MMessageProfile mMessageProfile = MessageUtility.GetProfile("DisabledAccount");
                                if (mMessageProfile != null)
                                {
                                    mRetVal = mMessageProfile.Body;
                                }
                            }
                        }
                        else
                        {
                            MMessageProfile mMessageProfile = MessageUtility.GetProfile("Logon Error");
                            if (mMessageProfile != null)
                            {
                                mRetVal = mMessageProfile.Body;
                            }
                        }
                    }
                }
                else
                {
                    MMessageProfile mMessageProfile = MessageUtility.GetProfile("Logon Error");
                    if (mMessageProfile != null)
                    {
                        mRetVal = mMessageProfile.Body;
                    }
                }
            }

            return(Ok(mRetVal));
        }