Example #1
0
        public ActionResult MLogon(MLogonModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                if (model.Mobile != null)
                {
                    model.Mobile = model.Mobile.Trim();
                }
                UserLoginResults loginResult = _accountService.ValidateUserByMobile(model.Mobile, model.Password);
                if (loginResult == UserLoginResults.UserNotExist)
                {
                    loginResult = _accountService.ValidateUser(model.Mobile, model.Password);
                }
                switch (loginResult)
                {
                case UserLoginResults.Successful:
                {
                    User user = _service.GetUserByMobile(model.Mobile) ?? _service.GetUserByUsername(model.Mobile);
                    //sign in new customer
                    AuthenticationService.SignIn(user, true);

                    if (String.IsNullOrEmpty(returnUrl) || !Url.IsLocalUrl(returnUrl))
                    {
                        return(RedirectToAction("Index", "Home"));
                    }
                    return(Redirect(returnUrl));
                }

                case UserLoginResults.UserNotExist:
                    ModelState.AddModelError("", "用户不存在");
                    break;

                case UserLoginResults.IsIllegal:
                    ModelState.AddModelError("", "您的账户已被禁用");
                    break;

                case UserLoginResults.Deleted:
                    ModelState.AddModelError("", "用户已删除");
                    break;

                case UserLoginResults.NotActive:
                    ModelState.AddModelError("", "用户没有激活");
                    break;

                case UserLoginResults.NotRegistered:
                    ModelState.AddModelError("", "用户未注册");
                    break;

                case UserLoginResults.WrongPassword:
                default:
                    ModelState.AddModelError("", "密码错误");
                    break;
                }
            }
            return(View(model));
        }
Example #2
0
        public ActionResult Logon(LogOnModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                if (model.UserName != null)
                {
                    model.UserName = model.UserName.Trim();
                }
                UserLoginResults loginResult = _accountService.ValidateUser(model.UserName, model.Password);
                if (loginResult == UserLoginResults.UserNotExist)
                {
                    loginResult = _accountService.ValidateUserByMobile(model.UserName, model.Password);
                }

                switch (loginResult)
                {
                case UserLoginResults.Successful:
                {
                    User user = _service.GetUserByUsername(model.UserName) ?? _service.GetUserByMobile(model.UserName);
                    //sign in new customer
                    AuthenticationService.SignIn(user, model.RememberMe);
                    user.LastActivityDateUtc = DateTime.Now;
                    _service.UpdateUser(user);

                    return(RedirectToAction("Index", "Home", new { Area = "Admin" }));
                }

                case UserLoginResults.UserNotExist:
                    ModelState.AddModelError("", "用户不存在");
                    break;

                case UserLoginResults.Deleted:
                    ModelState.AddModelError("", "用户已删除");
                    break;

                case UserLoginResults.NotActive:
                    ModelState.AddModelError("", "用户没有激活");
                    break;

                case UserLoginResults.NotRegistered:
                    ModelState.AddModelError("", "用户未注册");
                    break;

                case UserLoginResults.WrongPassword:
                default:
                    ModelState.AddModelError("", "密码错误");
                    break;
                }
            }
            return(View(model));
        }
Example #3
0
        public ActionResult LogonJson(string mobile, string password, bool isreme)
        {
            UserLoginResults loginResult = _accountService.ValidateUserByMobile(mobile, password);

            if (loginResult == UserLoginResults.UserNotExist)
            {
                loginResult = _accountService.ValidateUser(mobile, password);
            }
            switch (loginResult)
            {
            case UserLoginResults.Successful:
            {
                User user = _service.GetUserByMobile(mobile) ?? _service.GetUserByUsername(mobile);
                //sign in new customer
                AuthenticationService.SignIn(user, isreme);
                return(Json(1));
            }

            case UserLoginResults.UserNotExist:
                return(Json("用户不存在"));

            case UserLoginResults.IsIllegal:
                return(Json("您的账户已被禁用"));

            case UserLoginResults.Deleted:
                return(Json("用户已删除"));

            case UserLoginResults.NotActive:
                return(Json("用户没有激活"));

            case UserLoginResults.NotRegistered:
                return(Json("用户未注册"));

            default:
                return(Json("密码错误"));
            }
        }
Example #4
0
        public IHttpActionResult Login(ExecutiveMaster login)
        {
            UserLoginResults loginResult = new UserLoginResults();
            string           status = string.Empty; string value = string.Empty;

            try
            {
                string pwd = _encryptionService.EncryptText(login.Password, _execcutiveService.KeyValue("encriptionkey"));
                //string test_pwd = _encryptionService.DecryptText("VFL2yVFWp+S2z/in3jjI/EaK2E5OhOgi", _execcutiveService.KeyValue("encriptionkey"));

                loginResult = _UserService.ValidateUserLogin(login.Emailid, login.Password, "");

                //Added By Sanjeet Singh 0n 30th may 2016
                #region
                //ExecutiveLoginHistory exloginHistory = new ExecutiveLoginHistory();
                //exloginHistory.ExecutiveUserName = login.Emailid;
                //exloginHistory.LoginTime = DateTime.Now;
                //exloginHistory.LogoutTime = null;
                //if (loginResult.ToString() == "Successful")
                //{
                //    ExecutiveLoginHistory exeHistory = _execcutiveService.GetExecutiveHistoryByUserName(login.Emailid);

                //    string executiveStatus = _execcutiveService.ExecutiveLoginHistoryCheck(exloginHistory);

                //    if (executiveStatus == "Y")
                //    {
                //        if (string.IsNullOrEmpty(exeHistory.LogoutTime.ToString()))
                //        {
                //            loginResult = UserLoginResults.AllReadyLogged;
                //        }
                //        else
                //        {
                //            exeHistory.LoginTime = DateTime.Now;
                //            exeHistory.LogoutTime = null;
                //            _execcutiveService.UpdateExecutiveLoginHistory(exeHistory);
                //        }
                //    }
                //    else
                //    {
                //        _execcutiveService.InsertExecutiveLoginHistory(exloginHistory);
                //    }
                //}
                //else
                //{
                //    ExecutiveMaster objExecutive = _UserService.GetUserDetailByUserName(login.Emailid);

                //    if (objExecutive.block == "N")
                //    {
                //        LoginHistory loginHistory = new LoginHistory();
                //        loginHistory.UserName = login.Emailid;
                //        loginHistory.UserPassword = pwd;
                //        //To check on daily basis
                //        loginHistory.EntryDate = DateTime.Now.Date;
                //        string duplicate = _execcutiveService.LoginHistoryCheck(loginHistory);
                //        if (duplicate != "Y")
                //        {
                //            loginHistory.Attempt = 1;
                //            _execcutiveService.InsertLoginHistory(loginHistory);
                //        }
                //        else
                //        {
                //            LoginHistory objloginHistory = _execcutiveService.GetLoginHistoryByUserName(loginHistory);
                //            objloginHistory.Attempt = objloginHistory.Attempt + 1;
                //            // _execcutiveService.UpdateLoginHistory(objloginHistory);

                //            if (objloginHistory.Attempt >= 3)
                //            {
                //                //  ExecutiveMaster objExecutive = _UserService.GetUserDetailByUserName(login.Emailid);
                //                objExecutive.block = "Y";
                //                _execcutiveService.UpdateExecutive(objExecutive);

                //            }
                //            else
                //            {
                //                _execcutiveService.UpdateLoginHistory(objloginHistory);
                //            }
                //        }
                //    }
                //    else
                //    {
                //        //To show message for blocked user
                //        loginResult = UserLoginResults.UserBlocked;
                //        //
                //    }
                //    //
                //}
                #endregion
                //

                switch (loginResult)
                {
                case UserLoginResults.Successful:
                {
                    //var contact = _contactService.GetContactDetailByEmailID(login.Email);

                    ////sign in new customer
                    //_authenticationService.SignIn(contact, false);// at the place of "false" use the boolean property to set the "remember me"
                    // status = _localizationService.GetResource("Common.Login.Successful");

                    status = "Successful";
                    break;
                }

                case UserLoginResults.CustomerNotExist:
                    // status = _localizationService.GetResource("Common.Login.WrongCredentials.ContactNotExist");
                    status = "Invalid UserName";

                    break;

                case UserLoginResults.Deleted:
                    //   status = _localizationService.GetResource("Common.Login.WrongCredentials.Deleted");
                    break;

                case UserLoginResults.NotActive:
                    //  status = _localizationService.GetResource("Common.Login.WrongCredentials.NotActive");
                    status = "Employee Not Active";
                    break;

                case UserLoginResults.NotRegistered:
                    //  status = _localizationService.GetResource("Common.Login.WrongCredentials.NotRegistered"); value = _encryptionService.EncryptText(_contactService.GetContactDetailByEmailID(login.Username).Id.ToString(), "");// link generate to set password
                    status = "Employee Not Registered";
                    break;

                //Added by sanjeet singh
                case UserLoginResults.AllReadyLogged:
                    status = "User All Ready Logged";
                    break;

                case UserLoginResults.UserBlocked:
                    status = "You are blocked";
                    break;

                //
                case UserLoginResults.WrongPassword:
                default:
                    // status = _localizationService.GetResource("Common.Login.WrongCredentials");
                    status = "Wrong Password";

                    //status = "Worng password";
                    break;
                }
            }
            catch (ACSException ex)
            {
                status = ex.InnerException.Message;
            }
            catch (Exception ex)
            {
                status = ex.InnerException.Message;
            }

            //return Json(new { status, value });
            return(Json(new { status }));
        }