예제 #1
0
        public ActionResult Login(LoginModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                if (Membership.ValidateUser(model.UserName, model.Password))
                {
                    FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);
                    if (Url.IsLocalUrl(returnUrl))
                    {
                        return Redirect(returnUrl);
                    }
                    else
                    {
                        return RedirectToAction("Index", "Home");
                    }
                }
                else
                {
                    ModelState.AddModelError("", "The user name or password provided is incorrect.");
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
예제 #2
0
        public ActionResult Index(LoginModel model, string returnUrl)
        {
            ViewBag.Message = "Energy Billing System";
            ViewBag.ReturnUrl = returnUrl;
            if (ModelState.IsValid)
            {
                if (System.Web.Security.Membership.ValidateUser(model.UserName.Trim(), model.Password.Trim()))
                {
                    FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);

                    if (Url.IsLocalUrl(returnUrl))
                    {
                        return Redirect(returnUrl);
                    }
                    else
                    {
                        String MemberID = System.Web.Security.Membership.GetUser(model.UserName.ToUpper()).ProviderUserKey.ToString();
                        LoginSession loginSession = new LoginSession();
                        loginSession = BAL.BALLoginSessionModels.LoginDetails(model.UserName);
                        Session["Login"] = loginSession;
                        if (loginSession.UserType == "Consumer")
                        {
                            UserConsumerDetails Consumer = null;
                            Consumer = BAL.SearchModel.UserConsumer(loginSession.UserID.ToString());
                            if (Consumer != null)
                            {
                                return RedirectToAction("ConsumerDetails", "Search", new
                                {
                                    consID = BAL.Security.URLEncrypt(Consumer.ConsumerID.ToString()),
                                    OwnerID = BAL.Security.URLEncrypt(Consumer.OwnerID.ToString()),
                                    PropID = BAL.Security.URLEncrypt(Consumer.PropertyID.ToString()),
                                    SiteID = BAL.Security.URLEncrypt(Convert.ToString(Consumer.SiteID)),
                                    ClientID = BAL.Security.URLEncrypt(Convert.ToString(Consumer.ClientID)),
                                    MeterID = BAL.Security.URLEncrypt(Convert.ToString(Consumer.MeterID))
                                });
                            }
                            else
                            {
                                FormsAuthentication.SignOut();
                                Session["USER"] = "";
                                Session.Abandon();
                                return RedirectToAction("Index", "Home");

                            }

                        }
                        else
                        {
                            return RedirectToAction("Dashboard", "Home");
                        }

                    }
                }
                else
                {
                    ModelState.AddModelError("", "");
                }
            }
            else
            {
                return RedirectToAction("Index", "Home");
            }
            return View();
        }