Ejemplo n.º 1
0
        public ActionResult UpdateLogin()
        {
            var model = new UpdateLoginViewModel
            {
                Username = Username
            };

            return View(model);
        }
        public ActionResult UpdateLogin(UpdateLoginViewModel model)
        {
            if (ModelState.IsValid)
            {
                bool result = _userService.UpdateEmail(model.Email, _authProvider.CurrentUserId);
                if (result)
                {
                    return(RedirectToAction("Index"));
                }

                ModelState.AddModelError("", "Login is already taken");
            }
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 3
0
        public async Task<ActionResult> UpdateLogin(UpdateLoginViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return View(model);
            }

            // update identity user
            var updateUserLoginRequest = Mapper.Map<UpdateUserLoginServiceRequest>(model);
            updateUserLoginRequest.Username = Username;
            await IdentityService.UpdateLoginAsync(updateUserLoginRequest);

            return RedirectToAction("Logout");
        }
Ejemplo n.º 4
0
        // GET: UpdateLogin
        public async Task <ActionResult> UpdateLoginView()
        {
            UpdateLoginViewModel model = new UpdateLoginViewModel();
            var user = await UserManager.FindByNameAsync(User.Identity.Name);

            using (ApplicationDbContext data = new ApplicationDbContext())
            {
                var admin = data.AdminUsers.FirstOrDefault(a => a.ApplicationUserId == user.Id);

                model.FullName  = admin.FirstName + " " + admin.LastName;
                model.FirstName = admin.FirstName;
                model.LastName  = admin.LastName;
                model.Email     = user.Email;
                model.Username  = user.UserName;
                model.Number    = admin.PhoneNumber;
            }

            return(View("UpdateLogin", model));
        }
Ejemplo n.º 5
0
        // GET: UpdateLogin
        public async Task <ActionResult> UpdateLogin(UpdateLoginViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await UserManager.FindByNameAsync(User.Identity.Name);

                //var newFullName = model.FullName;
                var newFirstName = model.FirstName;
                var newLastName  = model.LastName;
                var oldPassword  = model.OldPassword;
                var newPassword  = model.Password;
                var newUsername  = model.Username;
                var newNumber    = model.Number;

                using (ApplicationDbContext data = new ApplicationDbContext())
                {
                    var admin = data.AdminUsers.FirstOrDefault(a => a.ApplicationUserId == user.Id);

                    if (admin.Username == newUsername && admin.PhoneNumber == newNumber && newPassword == null && admin.FirstName == newFirstName && admin.LastName == newLastName)
                    {
                        if (oldPassword != null)
                        {
                            ModelState.AddModelError("", "You have supplied an old password without specifying a new password");
                            return(View(model));
                        }
                        ModelState.AddModelError("", "You haven't made any changes to any form fields");
                        return(View(model));
                    }

                    if (newFirstName != null)
                    {
                        admin.FirstName = newFirstName;
                        data.Entry(admin).Property(m => m.FirstName).IsModified = true;
                    }

                    if (newLastName != null)
                    {
                        admin.LastName = newLastName;
                        data.Entry(admin).Property(m => m.LastName).IsModified = true;
                    }

                    if (newNumber != null)
                    {
                        admin.PhoneNumber = newNumber;
                        data.Entry(admin).Property(m => m.PhoneNumber).IsModified = true;
                    }

                    if (newUsername != null)
                    {
                        user.UserName = newUsername;
                        var updateResult = await UserManager.UpdateAsync(user);

                        if (!updateResult.Succeeded)
                        {
                            AddErrors(updateResult);
                            return(View(model));
                        }
                        else
                        {
                            admin.Username = model.Username;
                            data.Entry(admin).Property(m => m.Username).IsModified = true;
                        }
                    }

                    if (oldPassword != null)
                    {
                        var passwordCheck = await UserManager.CheckPasswordAsync(user, oldPassword);

                        if (passwordCheck == true)
                        {
                            if (newPassword != null)
                            {
                                if (newPassword != oldPassword)
                                {
                                    var passwordResult = await UserManager.ChangePasswordAsync(user.Id, oldPassword, newPassword);

                                    if (!passwordResult.Succeeded)
                                    {
                                        AddErrors(passwordResult);
                                        return(View(model));
                                    }
                                }
                                else
                                {
                                    ModelState.AddModelError("", "Your new password is the same as your old password. Please specify a different password");
                                    return(View(model));
                                }
                            }
                            else
                            {
                                ModelState.AddModelError("", "Your new password cannot be blank. Enter a password");
                                return(View(model));
                            }
                        }
                        else
                        {
                            ModelState.AddModelError("", "The Old Password you entered is incorrect");
                            return(View(model));
                        }
                    }
                    else if (oldPassword == null && newPassword != null)
                    {
                        ModelState.AddModelError("", "You have entered a new password without supplying your old password");
                        return(View(model));
                    }

                    data.SaveChanges();
                }

                AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie);
                return(RedirectToAction("Login", "Account"));
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Ejemplo n.º 6
0
        // GET: AddUser
        public async Task <ActionResult> EditUser(UpdateLoginViewModel model, string Id)
        {
            if (ModelState.IsValid)
            {
                var user = await UserManager.FindByIdAsync(Id);

                string newFullName = model.FullName;

                string[] firstAndLastName = newFullName.Split(' ');

                var newFirstName = model.FirstName;
                var newLastName  = model.LastName;
                var oldPassword  = model.OldPassword;
                var newPassword  = model.Password;
                var newUsername  = model.Username;
                var newNumber    = model.Number;

                using (ApplicationDbContext data = new ApplicationDbContext())
                {
                    var admin = data.AdminUsers.FirstOrDefault(a => a.ApplicationUserId == user.Id);

                    if (admin.Username == newUsername && admin.PhoneNumber == newNumber && newPassword == null && admin.FirstName == newFirstName && admin.LastName == newLastName)
                    {
                        if (oldPassword != null)
                        {
                            ModelState.AddModelError("", "You have supplied an old password without specifying a new password");
                            return(View(model));
                        }
                        ModelState.AddModelError("", "You haven't made any changes to any form fields");
                        return(View(model));
                    }

                    if (newFirstName != null && newLastName != null)
                    {
                        admin.FirstName = newFirstName;
                        admin.LastName  = newLastName;

                        data.Entry(admin).Property(m => m.FirstName).IsModified = true;
                        data.Entry(admin).Property(m => m.LastName).IsModified  = true;
                    }

                    if (newNumber != null)
                    {
                        admin.PhoneNumber = newNumber;
                    }

                    if (newUsername != null)
                    {
                        user.UserName = newUsername;
                        var updateResult = await UserManager.UpdateAsync(user);

                        if (!updateResult.Succeeded)
                        {
                            AddErrors(updateResult);
                            return(View(model));
                        }
                        else
                        {
                            admin.Username = model.Username;

                            data.Entry(admin).Property(m => m.Username).IsModified = true;
                        }
                    }


                    if (oldPassword != null)
                    {
                        var passwordCheck = await UserManager.CheckPasswordAsync(user, oldPassword);

                        if (passwordCheck == true)
                        {
                            if (newPassword != null)
                            {
                                if (newPassword != oldPassword)
                                {
                                    var passwordResult = await UserManager.ChangePasswordAsync(user.Id, oldPassword, newPassword);

                                    if (!passwordResult.Succeeded)
                                    {
                                        AddErrors(passwordResult);
                                        return(View(model));
                                    }
                                }
                                else
                                {
                                    ModelState.AddModelError("", "Your new password is the same as your old password. Please specify a different password");
                                    return(View(model));
                                }
                            }
                            else
                            {
                                ModelState.AddModelError("", "Your new password cannot be blank. Enter a password");
                                return(View(model));
                            }
                        }
                        else
                        {
                            ModelState.AddModelError("", "The Old Password you entered is incorrect");
                            return(View(model));
                        }
                    }
                    else if (oldPassword == null && newPassword != null)
                    {
                        ModelState.AddModelError("", "You have entered a new password without supplying your old password");
                        return(View(model));
                    }

                    //Save changes made to the AdminUsers table
                    data.SaveChanges();
                }

                List <AdminUser> Users = new List <AdminUser>();

                using (ApplicationDbContext data = new ApplicationDbContext())
                {
                    Users = data.AdminUsers.Include("ApplicationUser").ToList();
                }

                return(View("ManageUsers", Users));
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
        public ActionResult UpdateLogin(UpdateLoginViewModel model)
        {
            if (ModelState.IsValid)
            {
               bool result = _userService.UpdateEmail(model.Email, _authProvider.CurrentUserId);
               if (result)
               {
                   return RedirectToAction("Index");
               }

               ModelState.AddModelError("", "Login is already taken");
            }
            return RedirectToAction("Index");
        }