/// <summary>
        /// Creates the log on view.
        /// </summary>
        /// <param name="infoMessage">The information message.</param>
        /// <param name="errorMessage">The error message.</param>
        /// <param name="userName">Name of the user.</param>
        /// <param name="returnUrl"></param>
        /// <returns></returns>
        public ILogOnView CreateLogOnView(string infoMessage, string errorMessage, string userName, string returnUrl)
        {
            var model = new LogOnView
            {
                InfoMessage  = infoMessage ?? "",
                ErrorMessage = errorMessage ?? "",
                Email        = userName ?? "",
                ReturnUrl    = returnUrl ?? ""
            };

            return(model);
        }
Exemplo n.º 2
0
            public void authCode_IS_Incorect()
            {
                //parameter
                var userName = "******";
                var passWord = "******";
                var authCode = "1234";
                LogOnView model = new LogOnView { UserName = userName, Password = passWord, RememberMe = false };

                //mock
                this._authCodeValidateServiceMock.Setup<bool>(s => s.validateAuthCode(authCode)).Returns(false);

                var ret = _accountController.LogOn(model, "/AppStoresUI/AppManage", authCode);

                Assert.Equal("{ msgType = 1, url = /AppStoresUI/AppManage, ret = False }", ((System.Web.Mvc.JsonResult)ret).Data.ToString());
            }
Exemplo n.º 3
0
        public ActionResult Login(LogOnView model)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }



            if (!this.ModelState.IsValid)
            {
                return(View("Login", model));
            }


            var isUserValid = this.accountService.SignIn(model);


            if (isUserValid)
            {
                var url = string.Empty;

                var roles = (String[])this.session.GetSessionValue(SessionKey.UserRoles);

                if (!string.IsNullOrEmpty(model.ReturnUrl))
                {
                    url = model.ReturnUrl;
                }
                else

                if (roles.Contains("Administration") || roles.Contains("CompanyAdmin"))
                {
                    url = "/Account/MyCompanies";
                }

                else if (roles.Contains("Employee"))
                {
                    url = "/Home/EmployeeDashBoard";
                }

                return(Redirect(url));
            }

            this.ModelState.AddModelError("", Messages.IncorrectPasswordText);

            return(this.View("Login", model));
        }
Exemplo n.º 4
0
            public void normal_result_remeberMe_State()
            {
                //parameter
                var userName = "******";
                var passWord = "******";
                var authCode = "1234";
                const int CookieTimeoutSeconds = 1209600;
                LogOnView model = new LogOnView { UserName = userName, Password = passWord, RememberMe = true };

                //mock
                this._authCodeValidateServiceMock.Setup<bool>(s => s.validateAuthCode(authCode)).Returns(true);
                this._authCodeValidateServiceMock.Setup<AuthenticationResultType>(s => s.Login(true)).Returns(AuthenticationResultType.Successful);
                this._membershipServiceMock.Setup<bool>(s => s.ValidateUser(userName, passWord)).Returns(true);
                this._formsAuthenticationService.Setup(s => s.SetAuthCookie(model));
                this._cookieServiceMock.Setup(s => s.Set("RememberMe", model.RememberMe.ToString(), CookieTimeoutSeconds));
                this._cookieServiceMock.Setup(s => s.Remove("RememberMe"));

                var ret = _accountController.LogOn(model, "/AppStoresUI/AppManage", "1234");
                Assert.Equal("{ msgType = 0, url = /AppStoresUI/AppManage, ret = True }", ((System.Web.Mvc.JsonResult)ret).Data.ToString());
            }
        // GET: Logon
        public ActionResult Index(LogOnView model)
        {
            Response.Cache.SetExpires(DateTime.UtcNow.AddMinutes(-1)); //設為過期
            Response.Cache.SetCacheability(HttpCacheability.NoCache);  //設定Cache-Control的HTTP標頭,Header的Cache-Control, Pragma, Expires一次設足,就可以確保網頁內容不被Cache住了,用來確保網頁是最新的狀態而不是完全不用cache
            Response.Cache.SetNoStore();
            Session.Abandon();
            Session.Clear();
            FormsAuthentication.SignOut();
            var path = _settingService.GetSetting("BK_img", MobileHis.Data.SettingTypes.Info)?.Value;

            if (!path.IsNullOrEmpty())
            {
                if (Storage.GetStorage(StorageScope.backgroundImg).FileExist(path))
                {
                    //ViewBag.BackgroundImage = path;
                    model.BackgroundIMG = path;
                }
            }
            //ViewBag.HospitalName = _settingService.GetSetting("Hospital_Name", MobileHis.Data.SettingTypes.Info).Value;
            model.HospitalName = _settingService.GetSetting("Hospital_Name", MobileHis.Data.SettingTypes.Info).Value;
            //ViewBag.PartnerPathList = _settingService.GetPartnerImagePath();
            model.PartnerPathList = _settingService.GetPartnerImagePath();
            return(View());
        }
        public ActionResult Index(LogOnView model, string ReturnUrl)
        {
            //using (SettingDal setting = new SettingDal())
            //{
            //    var path = setting.GetSetting("BK_img", SettingType.Default).Value;
            //    if (!string.IsNullOrEmpty(path))
            //    {
            //        var s = MobileHis.Misc.Storage.GetStorage(StorageScope.backgroundImg);
            //        if (s.FileExist(path))
            //        {
            //            ViewBag.BK_img = path;//s.Open(category, path);
            //        }
            //    }
            //    var hospitalName = setting.GetSetting("Hospital_Name", SettingType.info).Value;
            //    ViewBag.hospitalName = hospitalName;
            //    var partnerPathList = setting.GetPartnerImagePath();
            //    ViewBag.partnerPathList = partnerPathList;
            //}
            //if (!ModelState.IsValid)
            //{
            //    //ViewBag.Message = string.Join(",", ModelState.Values
            //    //                        .SelectMany(x => x.Errors)
            //    //                        .Select(x => x.ErrorMessage));

            //}
            if (ModelState.IsValid)
            {
                var account = _accountService.LogOn(model.Email + Config.AppSetting("EmailDomain"), model.Password);
                if (account == null)
                {
                    ViewBag.Message = "Login Failed";
                }
                else
                {
                    //CustomPrincipalSerializeModel serializeModel = new CustomPrincipalSerializeModel();

                    //serializeModel.ID = account.ID;
                    //serializeModel.Name = account.Name;
                    //serializeModel.Email = account.Email;
                    //serializeModel.Roles = string.Join(",", account.Account2Role.Select(x => x.Role.name).ToArray());
                    WrappedPrincipal serializePrincipal = new WrappedPrincipal(
                        id: account.ID,
                        email: account.Email,
                        name: account.Name,
                        roles: string.Join(",", account.Account2Role.Select(x => x.Role.name).ToArray())
                        );
                    string userData = JsonConvert.SerializeObject(serializePrincipal);

                    FormsAuthenticationTicket authTicket = null;
                    var expiration = model.IsRemember == "1" ? DateTime.Now.AddDays(15) : DateTime.Now.AddHours(3);
                    authTicket = new FormsAuthenticationTicket(1, account.Email, DateTime.Now, expiration, false, userData);
                    string     encTicket = FormsAuthentication.Encrypt(authTicket);
                    HttpCookie faCookie  = new HttpCookie(FormsAuthentication.FormsCookieName, encTicket)
                    {
                        Expires = authTicket.Expiration, Path = "/"
                    };

                    Session["userAuth"] = JsonConvert.SerializeObject(
                        _accountService.AuthRole(
                            account.Account2Role.Select(x => x.Role.name).ToList(),
                            Server.MapPath("~/menu_all.xml")));      //為了生成SessionId
                    Response.Cookies.Add(faCookie);
                    #region 紀錄登入資訊

                    Log(account.Name + "  Login", FunctionType.Login, account.Name);
                    #endregion

                    if (string.IsNullOrWhiteSpace(ReturnUrl))
                    {
                        return(RedirectToAction("Index", "Home"));
                    }
                    else
                    {
                        return(Redirect(ReturnUrl));
                    }
                }
            }

            return(View(model));
        }
Exemplo n.º 7
0
        public ActionResult Login(LogOnView model)
        {
            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            if (!this.ModelState.IsValid)
            {
                return(View("Login", model));
            }



            var isUserValid = this.accountService.SignIn(model);

            if (isUserValid)
            {
                //TODO : Account that are not validated should be able to request for anotherr activation code incase they loose the first
                var userStatus = this.accountService.GetActivationStatus(model);


                if (userStatus == false)
                {
                    this.accountService.SignOff();

                    this.ModelState.AddModelError("", "Ensure to verify your email");


                    return(this.View(model));
                }


                userStatus = this.accountService.GetUserStatus(model);


                if (userStatus == false)
                {
                    this.accountService.SignOff();

                    this.ModelState.AddModelError("", "Contact Your Admin");


                    return(this.View(model));
                }



                return(!string.IsNullOrEmpty(model.ReturnUrl)
                    ? (ActionResult)this.Redirect(model.ReturnUrl)
                    : this.RedirectToAction("Index", "Home"));
            }

            //Check if the User Account is Validated



            //Get The Currently Logged User Id



            this.ModelState.AddModelError("", "Incorrect Email or Password");


            return(this.View(model));
        }
Exemplo n.º 8
0
            public void userName_OR_pwd_incorrect()
            {
                //parameter
                var userName = "******";
                var passWord = "******";
                var authCode = "1234";
                LogOnView model = new LogOnView { UserName = userName, Password = passWord, RememberMe = false };

                //mock
                this._authCodeValidateServiceMock.Setup<bool>(s => s.validateAuthCode(authCode)).Returns(true);
                this._authCodeValidateServiceMock.Setup<AuthenticationResultType>(s => s.Login(true)).Returns(AuthenticationResultType.Successful);
                this._membershipServiceMock.Setup<bool>(s => s.ValidateUser(userName, passWord)).Returns(false);
                this._membershipServiceMock.Setup<MembershipUser>(s => s.GetUser(userName));

                //call service
                var ret = _accountController.LogOn(model, "/AppStoresUI/AppManage", authCode);

                //validate
                Assert.Equal("{ msgType = 2, url = /AppStoresUI/AppManage, ret = False }", ((System.Web.Mvc.JsonResult)ret).Data.ToString());
            }