Esempio n. 1
0
        public ActionResult Login(LoginModel model, string returnUrl) {
            //if(ModelState.IsValid) {
            //    if(WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe.Value)) {
            //        return Redirect(returnUrl ?? "/");
            //    }
            //    ModelState.AddModelError("", "The user name or password provided is incorrect.");
            //}

            // If we got this far, something failed, redisplay form
            return View(model);
        }
Esempio n. 2
0
        public ActionResult Index(LoginModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                User user = new User();
                user = AdminServiceProvider.Login(model);

                if (user != null)
                {
                    if (user.IsLicensed)
                    {
                        if (user.ExpiryDate >= DateTime.Now)
                        {
                            CustomPrincipalSerializeModel serializeModel = new CustomPrincipalSerializeModel();
                            serializeModel.Id = user.UserId;
                            serializeModel.Email = user.Email;
                            //serializeModel.Role = user.Roles;
                            serializeModel.IsLicensed = user.IsLicensed;
                            serializeModel.ExpiryDate = user.ExpiryDate;

                            JavaScriptSerializer serializer = new JavaScriptSerializer();
                            string userData = serializer.Serialize(serializeModel);

                            FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(1, model.Email,
                                DateTime.Now, DateTime.Now.AddMinutes(15), false, userData);
                            string encTicket = FormsAuthentication.Encrypt(authTicket);

                            HttpCookie faCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encTicket);
                            Response.Cookies.Add(faCookie);

                            ViewData["userFile"] = UpdateUserMainMenuXml(user.UserId);
                            return RedirectToAction("UploadFile", "UploadControl");
                        }else
                        ViewData["ErrorMsg"] = "Kindly, Be notified that your license has expired ! Expiry Date: " + user.ExpiryDate;
                    } else
                    ViewData["ErrorMsg"] = "Your license is not activated! Expiry Date is " + user.ExpiryDate;
                }else
                ViewData["ErrorMsg"] = "Wrong Email and/or password! ";
            }
            return View(model);
        }