Пример #1
0
        public IActionResult DeleteImageConfirmed(int ImageID)
        {
            Image image = _context.Images.FirstOrDefault(i => i.ImageID == ImageID);

            if (image != null)
            {
                _context.Images.Remove(image);
                _context.SaveChanges();
                return(RedirectToAction("Details", new RouteValueDictionary(
                                            new { action = "Details", Id = image.CarID })));
            }

            return(View());
        }
Пример #2
0
        public IActionResult SetPassword([Bind("NewPassword,ConfirmPassword")] SetPasswordViewModel fpvm)
        {
            if (!ModelState.IsValid)
            {
                return(View(fpvm));
            }
            string email = HttpContext.Session.GetString("userID");
            User   user  = _context.User.FirstOrDefault(x => x.UserID == email);

            if (user == null)
            {
                return(NotFound());
            }

            PasswordEncryption.CreatePasswordHash(fpvm.ConfirmPassword, out byte[] hash, out byte[] salt);

            user.PasswordHash = hash;
            user.PasswordSalt = salt;

            try
            {
                _context.User.Update(user);
                _context.SaveChanges();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            HttpContext.Session.Clear();
            return(RedirectToAction("Login"));
        }
Пример #3
0
        public ActionResult ChangePassword(ProfileViewModel pvm)
        {
            string mail = HttpContext.Session.GetString("Email");

            User user = _context.User.FirstOrDefault(x => x.UserID == mail);



            if (user == null)
            {
                // ViewBag.Verified = false;
                return(RedirectToAction("Login", "Users"));
            }

            // verifying old password that was inserted by user
            bool verified = PasswordEncryption.VerifyPasswordHash(pvm.OldPassword, user.PasswordHash, user.PasswordSalt);

            if (!verified)
            {
                //This viewbag is checked in the view to display Wrong password error
                // ViewBag.Verified = false;
                return(View(pvm));
            }

            PasswordEncryption.CreatePasswordHash(pvm.ConfirmPassword, out byte[] hash, out byte[] salt);
            user.PasswordHash = hash;
            user.PasswordSalt = salt;

            try
            {
                _context.User.Update(user);
                _context.SaveChanges();
            }
            catch (Exception ex)
            {
                throw new Exception();
            }

            // this view is declared to show login again with new pass in Login Page

            return(RedirectToAction("Login", "Users"));
        }