예제 #1
0
        // GET: api/LogInDetails/5
        public async Task <HttpResponseMessage> Post([FromBody] LogInDetails value)
        {
            try
            {
                string          UserName   = value.UserName;
                string          Password   = value.Password;
                LoginDetailsRef loginref   = new LoginDetailsRef();
                LogInDetails    loginmodel = new LogInDetails();
                List <string>   Errors     = new List <string>();
                loginref.ErrorMessage = new List <string>();
                var regexSpace = new Regex(@"\s");
                if (UserName == null || UserName == string.Empty || string.IsNullOrWhiteSpace(UserName.Trim()) || Password == null || Password == string.Empty || string.IsNullOrWhiteSpace(Password.Trim()))
                {
                    if (UserName == null || UserName == string.Empty || string.IsNullOrWhiteSpace(UserName.Trim()))
                    {
                        Errors.Add("UserName is required");
                    }
                    if (Password == null || Password == string.Empty || string.IsNullOrWhiteSpace(Password.Trim()))
                    {
                        Errors.Add("Password is required");
                    }
                }
                else
                {
                    string specialCharacters      = @"%!#$%^&*(-)?/><,:;'\|}]{[~`+=" + "\"";
                    char[] specialCharactersArray = specialCharacters.ToCharArray();
                    int    index = UserName.IndexOfAny(specialCharactersArray);
                    //index == -1 no special characters
                    if (index == -1)
                    {
                    }
                    else
                    {
                        Errors.Add("UserName allows only three special characters '_' '.' '@' ");
                    }
                    if (regexSpace.IsMatch(UserName.Trim()))
                    {
                        Errors.Add("UserName should not have space");
                    }
                    string justNumber  = new String(UserName.Trim().Where(Char.IsDigit).ToArray());
                    string justStrings = new String(UserName.Trim().Where(Char.IsLetter).ToArray());

                    if (justStrings == null || justStrings == string.Empty && UserName.Length <= 20)
                    {
                        Errors.Add("UserName does not allow only numeric values");
                    }
                }
                if (regexSpace.IsMatch(Convert.ToString(Password).Trim()))
                {
                    Errors.Add("Password should not have space");
                }

                if (Errors != null && Errors.Count() > 0)
                {
                    loginref.Status       = "Failure";
                    loginref.ErrorMessage = Errors;
                    return(Request.CreateResponse <LoginDetailsRef>(HttpStatusCode.BadRequest, loginref));
                }
                else
                {
                    if (await CommonUseFunctionClass.CheckUser(UserName, Password))
                    {
                        string str = CommonUseFunctionClass.GenerateToken(UserName, 20);
                        if (str != string.Empty || str != null || string.IsNullOrWhiteSpace(str.Trim()))
                        {
                            loginref.Status       = "Success";
                            loginref.Access_Token = str;
                            loginmodel.UserName   = UserName;
                            loginref.LogInData    = loginmodel;
                            return(Request.CreateResponse <LoginDetailsRef>(HttpStatusCode.OK, loginref));
                        }
                        else
                        {
                            loginref.Status = "Failure";
                            loginref.ErrorMessage.Add("Token Is Not generated");
                            return(Request.CreateResponse <LoginDetailsRef>(HttpStatusCode.BadRequest, loginref));
                        }
                    }
                    else
                    {
                        loginref.Status = "Failure";
                        loginref.ErrorMessage.Add("UserName or Password are not valid.");
                        return(Request.CreateResponse <LoginDetailsRef>(HttpStatusCode.BadRequest, loginref));
                    }
                }
            }
            catch (Exception xp)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, xp.Message));
            }
            return(null);
        }
예제 #2
0
        public async System.Threading.Tasks.Task <ActionResult> AgentLogin(string UserName, string Password)
        {
            try
            {
                LoginDetailsRef loginref   = new LoginDetailsRef();
                LogInDetails    loginmodel = new LogInDetails();
                List <string>   Errors     = new List <string>();
                loginref.ErrorMessage = new List <string>();
                loginmodel.Errors     = new List <string>();
                var regexSpace = new Regex(@"\s");
                if (UserName == null || UserName == string.Empty || string.IsNullOrWhiteSpace(UserName.Trim()) || Password == null || Password == string.Empty || string.IsNullOrWhiteSpace(Password.Trim()))
                {
                    if (UserName == null || UserName == string.Empty || string.IsNullOrWhiteSpace(UserName.Trim()))
                    {
                        Errors.Add("User Name is required");
                    }
                    if (Password == null || Password == string.Empty || string.IsNullOrWhiteSpace(Password.Trim()))
                    {
                        Errors.Add("Password is required");
                    }
                }
                else
                {
                    string specialCharacters      = @"%!#$%^&*(-)?/><,:;'\|}]{[~`+=" + "\"";
                    char[] specialCharactersArray = specialCharacters.ToCharArray();
                    int    index = UserName.IndexOfAny(specialCharactersArray);
                    //index == -1 no special characters
                    if (index == -1)
                    {
                    }
                    else
                    {
                        Errors.Add("User Name allows only three special characters '_' '.' '@' ");
                    }
                    if (regexSpace.IsMatch(UserName.Trim()))
                    {
                        Errors.Add("User Name should not have space");
                    }
                    string justNumber  = new String(UserName.Trim().Where(Char.IsDigit).ToArray());
                    string justStrings = new String(UserName.Trim().Where(Char.IsLetter).ToArray());

                    if (justStrings == null || justStrings == string.Empty && UserName.Length <= 20)
                    {
                        Errors.Add("User Name does not allow only numeric values");
                    }
                }
                if (regexSpace.IsMatch(Convert.ToString(Password).Trim()))
                {
                    Errors.Add("Password should not have space");
                }

                if (Errors != null && Errors.Count() > 0)
                {
                    loginref.Status       = "Failure";
                    loginref.ErrorMessage = Errors;
                    return(View());
                }
                else
                {
                    //#region Remove
                    //LogInDetailsClass ld = new LogInDetailsClass();

                    //LoginDetailsRef LoginDetailsRef = new LoginDetailsRef();
                    //LoginDetailsRef.ErrorMessage = new List<string>();
                    //LoginDetailsRef = await ld.GetLogInDetailsPage(UserName, Password);
                    //{
                    //    if(LoginDetailsRef.ErrorMessage!=null && LoginDetailsRef.ErrorMessage.Count()>0)
                    //    {
                    //        loginmodel.Errors = LoginDetailsRef.ErrorMessage;
                    //        return View(loginmodel);
                    //    }
                    //}
                    //#endregion
                    if (await CommonUseFunctionClass.CheckUser(UserName, Password))
                    {
                        string str = CommonUseFunctionClass.GenerateToken(UserName, 20);
                        if (str != string.Empty || str != null || string.IsNullOrWhiteSpace(str.Trim()))
                        {
                            Session["IyId"]       = 9262;
                            loginref.Status       = "Success";
                            loginref.Access_Token = str;
                            loginmodel.UserName   = UserName;
                            loginref.LogInData    = loginmodel;
                            return(RedirectToAction("CustomerSearch", "Customer"));
                        }
                        else
                        {
                            loginref.Status = "Failure";
                            loginref.ErrorMessage.Add("Token is not generated");
                            ViewBag.ErrorMessage = "";
                            return(View());
                        }
                    }
                    else
                    {
                        loginref.Status = "Failure";
                        loginref.ErrorMessage.Add("User Name or Password are not valid.");
                        ViewBag.ErrorMessage = "User Name or Password are not valid.";
                        return(View());
                    }
                }
            }

            catch (Exception ex)
            {
                ViewBag.ErrorMessage = "User Name or Password are not valid.";
                return(View());
            }

            return(View());
        }