Esempio n. 1
0
        public ActionResult PasswordReset(PasswordResetViewModel pass)
        {
            var message = "";

            if (ModelState.IsValid)
            {
                using (ClinicSysDbEntities dc = new ClinicSysDbEntities())
                {
                    var user = dc.Users.Where(a => a.ResetPasswordCode == pass.ResetCode).FirstOrDefault();
                    if (user != null)
                    {
                        user.Password          = Encryption.PasswordHash(pass.NewPassword);
                        user.ResetPasswordCode = "";
                        dc.Configuration.ValidateOnSaveEnabled = false;
                        dc.SaveChanges();
                        message = "New password updated successfully";
                    }
                }
            }
            else
            {
                message = "Error!";
            }
            ViewBag.Message = message;
            return(View(pass));
        }
Esempio n. 2
0
        public ActionResult ForgotPassword(string email)
        {
            string message = "";
            bool   status  = false;

            if (string.IsNullOrEmpty(email))
            {
                message = "Error: Email is a required field!";
            }
            else
            {
                using (ClinicSysDbEntities db = new ClinicSysDbEntities())
                {
                    var account = db.Users.Where(a => a.Email == email).FirstOrDefault();
                    if (account != null)
                    {
                        string resetCode = Guid.NewGuid().ToString();
                        SendVerificationLinkEmail(account.Email, resetCode, "ResetPassword");
                        account.ResetPasswordCode = resetCode;
                        db.Configuration.ValidateOnSaveEnabled = false;
                        db.SaveChanges();
                        message = "Reset password link successfully sent to your email.";
                    }
                    else
                    {
                        message = "Error: Account not found!";
                    }
                }
            }

            ViewBag.Message = message;
            return(View());
        }
Esempio n. 3
0
        public ActionResult VerifyAccount(string id)
        {
            bool Status = false;

            using (ClinicSysDbEntities dc = new ClinicSysDbEntities())
            {
                dc.Configuration.ValidateOnSaveEnabled = false;
                var v = dc.Users.Where(a => a.ActivationCode == new Guid(id)).FirstOrDefault();
                if (v != null)
                {
                    v.IsEmailVerified = true;
                    dc.SaveChanges();
                    Status = true;
                }
                else
                {
                    ViewBag.Message = "Request Not Valid!";
                }
            }
            ViewBag.Status = Status;
            return(View());
        }
Esempio n. 4
0
        public ActionResult PasswordReset(string id)
        {
            if (string.IsNullOrWhiteSpace(id))
            {
                return(HttpNotFound());
            }

            using (ClinicSysDbEntities db = new ClinicSysDbEntities())
            {
                var user = db.Users.Where(a => a.ResetPasswordCode == id).FirstOrDefault();
                if (user != null)
                {
                    PasswordResetViewModel model = new PasswordResetViewModel();
                    model.ResetCode = id;
                    return(View(model));
                }
                else
                {
                    return(HttpNotFound());
                }
            }
        }
Esempio n. 5
0
        public ActionResult Login(UserLogin user, string ReturnUrl = "")
        {
            if (!string.IsNullOrEmpty(user.EmailID))
            {
                if (!string.IsNullOrEmpty(user.Password))
                {
                    if (ModelState.IsValid)
                    {
                        string message = "";

                        using (ClinicSysDbEntities dc = new ClinicSysDbEntities())
                        {
                            var userData = dc.Users.Where(a => a.Email == user.EmailID).FirstOrDefault();

                            if (userData != null)
                            {
                                if (!userData.IsEmailVerified)
                                {
                                    ViewBag.Message = "Please verify your email first";
                                    return(View());
                                }

                                if (string.Compare(Encryption.PasswordHash(user.Password), userData.Password) == 0)
                                {
                                    int    timeout   = user.RememberMe ? 525600 : 20;
                                    var    ticket    = new FormsAuthenticationTicket(user.EmailID, user.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
                                    {
                                        Session["FirstName"] = userData.Name;
                                        Session["LastName"]  = userData.LastName;
                                        Session["ID"]        = userData.ID_Number;
                                        Session["Address"]   = userData.Address;
                                        Session["Phone"]     = userData.Phone;
                                        Session["Email"]     = userData.Email;



                                        //Analyics
                                        Session["AppointmentCount"]  = dc.PatientAppointments.ToList().Count();
                                        Session["UserCount"]         = dc.Users.ToList().Count();
                                        Session["PatientCount"]      = dc.Patients.ToList().Count();
                                        Session["StockCount"]        = dc.Inventories.ToList().Count();
                                        Session["CommentCount"]      = dc.Comments.ToList().Count();
                                        Session["PractitionerCount"] = dc.MedicalPractitioners.ToList().Count();
                                        Session["ClinicCount"]       = dc.HealthClinics.ToList().Count();

                                        return(RedirectToAction("Launcher", "Home"));
                                    }
                                }
                                else
                                {
                                    message = "Invalid credential provided";
                                }
                            }
                            else
                            {
                                message = "Invalid credential provided";
                            }
                        }
                        ViewBag.Message = message;
                        return(View());
                    }
                }
                else
                {
                    ViewBag.Message = "Error: Password is a required field!";
                }
            }
            else
            {
                ViewBag.Message = "Error: Username/Email is a required field!";
            }

            return(View());
        }
Esempio n. 6
0
        public ActionResult Registration([Bind(Exclude = "IsEmailVerified,ActivationCode,ResetPasswordCode")] User user)
        {
            bool   Status  = false;
            string message = "";

            ViewBag.GenderID = new SelectList(db.Genders, "Id", "Name", user.GenderID);
            ViewBag.TitleID  = new SelectList(db.UserTitles, "Id", "TitleName", user.TitleID);


            if (ModelState.IsValid)
            {
                #region
                var isExist = HelperClass.IsMailValid(user.Email);
                if (isExist)
                {
                    ModelState.AddModelError("EmailExist", "Email already exist");
                    return(View());
                }


                #endregion

                #region Generate Activation Code
                user.ActivationCode = Guid.NewGuid();
                #endregion

                #region  Password Hashing
                user.Password        = Encryption.PasswordHash(user.Password);
                user.ConfirmPassword = Encryption.PasswordHash(user.ConfirmPassword);
                #endregion
                user.IsEmailVerified = false;

                #region Save to Database
                using (ClinicSysDbEntities db = new ClinicSysDbEntities())
                {
                    try
                    {
                        db.Users.Add(user);
                        db.SaveChanges();
                        TempData["successMessage"] = $"User successfully saved";

                        SendVerificationLinkEmail(user.Email, user.ActivationCode.ToString());
                        message = " Registration successfully done. Account activation link " +
                                  " has been sent to your email: " + user.Email + "\nKindly click on the link to activate your account.\n" +
                                  " Clinic-System";
                        Status = true;
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }
                #endregion
            }
            else
            {
                message = "Invalid Request";
            }

            ViewBag.Message = message;
            ViewBag.Status  = Status;

            return(View(user));
        }