Exemplo n.º 1
0
        /// Public method to authenticate user by user name and password.

        public int Authenticate(string userLogin, string password, int?subscriptionTypeId, out string invalidMsg)
        {
            ApiValidateUserReturnModel user;
            int rtn;

            using (var db = new DBAMPContext())
            {
                try
                {
                    user = db.ApiValidateUser(userLogin, password, subscriptionTypeId, out rtn).FirstOrDefault();

                    if (rtn > 0)
                    {
                        if (rtn == 3)
                        {
                            invalidMsg = "Invalid username and/or password.";
                        }
                        else if (rtn == 4)
                        {
                            invalidMsg = "User does not have access.";
                        }
                        else
                        {
                            invalidMsg = "Other Errors";
                        }

                        return(0);
                    }
                    else
                    {
                        invalidMsg = string.Empty;

                        return(user.UserID);
                    }
                }
                catch (Exception ex)
                {
                    string sqlParam   = "ApiValidateUser(" + userLogin + "," + password + "," + subscriptionTypeId + ", out rtn)";
                    string methodName = "JCRAPI/Business/UserServices/Authenticate";
                    exceptionLog.ExceptionLogInsert(ex.Message.ToString(), "", methodName, null, null, sqlParam, string.Empty);
                    invalidMsg = "Other Errors";
                    return(0);
                }
            }
        }