Beispiel #1
0
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.Add(new Route(
                           "{lang}/{controller}/{action}/{id}",
                           new RouteValueDictionary(new
            {
                lang       = Codehelper.GetLang(Codehelper.DefaultCountry),
                controller = "Account",
                action     = "Logon",
                id         = UrlParameter.Optional
            }),
                           new MultiLangRouteHandler()));
        }
Beispiel #2
0
        public ActionResult LogOff()
        {
            FormsAuthentication.SignOut();
            HttpCookie cookie = new HttpCookie("settingauth", "")
            {
                HttpOnly = true,
                Expires  = DateTime.Now.AddDays(-5)
            };
            HttpCookie cafebrand = new HttpCookie("cafebrand", "")
            {
                HttpOnly = true,
                Expires  = DateTime.Now.AddDays(-5)
            };

            Response.Cookies.Add(cookie);
            Response.Cookies.Add(cafebrand);
            return(RedirectToAction("LogOn", "Account", new { lang = Codehelper.GetLang(Codehelper.DefaultCountry) }));
        }
Beispiel #3
0
        public async Task <ActionResult> LogOn(LogOnViewModel user)
        {
            if (ModelState.IsValid)
            {
                UserLoginProfile profile = await LoginManager.Authenticate(user, HttpContext.IsDebuggingEnabled);

                if (profile != null)
                {
                    bool confirm = false;
                    if (!string.IsNullOrEmpty(profile.error))
                    {
                        if (profile.error.IndexOf("패스워드가 만료 되었습니다", StringComparison.InvariantCultureIgnoreCase) >= 0 ||
                            profile.error.IndexOf("密碼已經過期", StringComparison.InvariantCultureIgnoreCase) >= 0 ||
                            profile.error.IndexOf("password has been expired", StringComparison.InvariantCultureIgnoreCase) >= 0 ||
                            profile.error.IndexOf("密码已经过期", StringComparison.InvariantCultureIgnoreCase) >= 0)
                        {
                            return(View("ChangePassword", (object)user.Username));
                        }

                        if (profile.error.IndexOf("密碼將於", StringComparison.InvariantCultureIgnoreCase) >= 0 &&
                            profile.error.IndexOf("天後到期", StringComparison.InvariantCultureIgnoreCase) >= 0 ||
                            profile.error.IndexOf("days left to be password expiration",
                                                  StringComparison.InvariantCultureIgnoreCase) >= 0 ||
                            profile.error.IndexOf("패스워드 만료가", StringComparison.InvariantCultureIgnoreCase) >= 0 &&
                            profile.error.IndexOf("일 남았습니다", StringComparison.InvariantCultureIgnoreCase) >= 0)
                        {
                            confirm = true;
                        }

                        if (!confirm)
                        {
                            ModelState.AddModelError("", profile.error);
                            return(View(user));
                        }
                    }
                    await UpdateUsername(user.Username, profile.UserName);

                    RequestResult <string[]> result = GetAccessableBrands(user.Username);
                    if (!string.IsNullOrEmpty(result.ErrorMessage))
                    {
                        ModelState.AddModelError("", result.ErrorMessage);
                        return(View(user));
                    }
                    string lang = Codehelper.GetLang(profile.Language);
                    if (HttpContext.IsDebuggingEnabled)
                    {
                        FormsAuthenticationHelper.SetAuthCookie(user.Username, false, string.Join(",", result.ReturnValue));
                        return(RedirectToAction("Index", "Home", new { lang }));
                    }
                    FormsAuthenticationHelper.SetAuthCookie(user.Username, false, string.Join(",", result.ReturnValue));
                    if (confirm)
                    {
                        ViewBag.Msg      = profile.error;
                        ViewBag.Country  = profile.Country;
                        ViewBag.Language = lang;
                        return(View("ConfirmChangePassword"));
                    }
                    if (!Codehelper.DefaultCountry.EqualsIgnoreCaseAndBlank(profile.Country))
                    {
                        return(RedirectToAction("SwitchSite", new { country = profile.Country, language = lang }));
                    }
                    return(RedirectToAction("Index", "Home", new { lang }));
                }
            }
            ModelState.AddModelError("", StringResource.INVALID_USERNAME_OR_PASSWORD);
            return(View(user));
        }