Ejemplo n.º 1
0
        public ActionResult Registration(Patient user)
        {
            bool   Status  = false;
            string message = "";

            //
            // Model Validation
            if (ModelState.IsValid)
            {
                #region Save to Database
                using (PatientDBEntities1 dc = new PatientDBEntities1())
                {
                    dc.Patients.Add(user);
                    dc.SaveChanges();
                    Status = true;
                }
                #endregion
            }
            else
            {
                message = "Invalid Request";
            }

            ViewBag.Message = message;
            ViewBag.Status  = Status;
            return(View(user));
        }
Ejemplo n.º 2
0
        public ActionResult Login(UserLogin login, string ReturnUrl = "")
        {
            string message = "";

            using (PatientDBEntities1 dc = new PatientDBEntities1())
            {
                var v = dc.Patients.Where(a => a.Email == login.Email).FirstOrDefault();
                if (v != null)
                {
                    if (string.Compare(login.Password, v.Password) == 0)
                    {
                        int    timeout   = login.RememberMe ? 525600 : 20; // 525600 min = 1 year
                        var    ticket    = new FormsAuthenticationTicket(login.Email, login.RememberMe, timeout);
                        string encrypted = FormsAuthentication.Encrypt(ticket);
                        var    cookie    = new HttpCookie(FormsAuthentication.FormsCookieName, encrypted);
                        cookie.Expires  = DateTime.Now.AddMinutes(timeout);
                        cookie.HttpOnly = true;
                        Response.Cookies.Add(cookie);


                        if (Url.IsLocalUrl(ReturnUrl))
                        {
                            return(Redirect(ReturnUrl));
                        }
                        else
                        {
                            return(RedirectToAction("Index", "Home"));
                        }
                    }
                    else
                    {
                        message = "Invalid credential provided";
                    }
                }
                else
                {
                    message = "Invalid credential provided";
                }
            }
            ViewBag.Message = message;
            return(View());
        }