public ActionResult ChangeUserName(ChangeUserNameModel model)
 {
     if (ModelState.IsValid)
     {
         if (Membership.ValidateUser(User.Identity.Name, model.Password))
         {
             using (var context = new UsersContext())
             {
                 var user = context.UserProfiles.SingleOrDefault(u => u.UserName == model.UserName);
                 if (user == null)
                 {
                     user = context.UserProfiles.SingleOrDefault(u => u.UserName == User.Identity.Name);
                     if (user != null)
                     {
                         user.UserName             = model.UserName;
                         context.Entry(user).State = EntityState.Modified;
                         context.SaveChanges();
                         Membership.Logout();
                         Membership.Login(model.UserName, model.Password);
                         ViewBag.StatusMessage = "Your user name has been changed.";
                     }
                 }
                 else
                 {
                     ModelState.AddModelError("", "The current user name is duplicate or incorrect.");
                 }
             }
         }
         else
         {
             ModelState.AddModelError("", "The current password provided is incorrect.");
         }
     }
     return(View("Index", new ManageViewModel(model.UserName)));
 }
示例#2
0
        public virtual async Task <ActionResult> Put(ChangeUserName command)
        {
            if (command == null)
            {
                return(View(MVC.Errors.Views.BadRequest));
            }

            var view = await _queries.Execute(new UserViewBy(command.UserId));

            if (view == null)
            {
                return(HttpNotFound());
            }

            if (!ModelState.IsValid)
            {
                var model = new ChangeUserNameModel
                {
                    UserView = view,
                    Command  = command,
                };

                return(View(MVC.Security.Views.User.Settings, model));
            }

            await _commands.Execute(command);

            Response.ClientCookie(command.SignedIn.Id, _queries);
            return(RedirectToAction(await MVC.UserName.Index()));
        }
        public ActionResult Change(ChangeUserNameModel model)
        {
            UsersContext   db = new UsersContext();
            MembershipUser u;

            u = Membership.GetUser(WebSecurity.CurrentUserName);
            var User = (from p in db.UserProfiles where p.UserId == WebSecurity.CurrentUserId select p.Email).FirstOrDefault();

            if (User == model.OldEmail)
            {
                u.Email = model.NewEmail;
                Membership.UpdateUser(u);
            }
            TempData["Mess"] = "User Name Updated Successfully...";
            //if (User==model)
            //{
            //    u.Email = model.NewUserName;
            //    //u.UserName = "******";
            //    Membership.UpdateUser(u);
            //    //UserProfile user = new UserProfile();
            //    //user.UserName = model.NewUserName;
            //    //db.SaveChanges();
            //    TempData["Mess"] = "User Name Updated Successfully...";
            //}
            return(RedirectToAction("Change"));
        }
示例#4
0
        public virtual async Task<ActionResult> Index()
        {
            var view = await _queries.Execute(new UserViewBy(User.Identity.GetUserId<int>()));
            if (view == null) return HttpNotFound();

            var model = new ChangeUserNameModel
            {
                UserView = view,
                Command = new ChangeUserName
                {
                    UserId = view.UserId,
                    UserName = view.UserName,
                },
            };

            return View(MVC.Security.Views.User.Settings, model);
        }
示例#5
0
        public virtual async Task <ActionResult> Index()
        {
            var view = await _queries.Execute(new UserViewBy(User.Identity.GetUserId <int>()));

            if (view == null)
            {
                return(HttpNotFound());
            }

            var model = new ChangeUserNameModel
            {
                UserView = view,
                Command  = new ChangeUserName
                {
                    UserId   = view.UserId,
                    UserName = view.UserName,
                },
            };

            return(View(MVC.Security.Views.User.Settings, model));
        }
示例#6
0
        public virtual async Task<ActionResult> Put(ChangeUserName command)
        {
            if (command == null) return View(MVC.Errors.Views.BadRequest);

            var view = await _queries.Execute(new UserViewBy(command.UserId));
            if (view == null) return HttpNotFound();

            if (!ModelState.IsValid)
            {
                var model = new ChangeUserNameModel
                {
                    UserView = view,
                    Command = command,
                };

                return View(MVC.Security.Views.User.Settings, model);
            }

            await _commands.Execute(command);
            Response.ClientCookie(command.SignedIn.Id, _queries);
            return RedirectToAction(await MVC.UserName.Index());
        }