コード例 #1
0
 protected async void UpdateForm()
 {
     if (Request["isUpdate"] == "true")
     {
         string newpass = Request["txt_newpass"];
         string oldpass = Request["txt_oldpass"];
         if (!string.IsNullOrEmpty(newpass))
         {
             if (!string.IsNullOrEmpty(oldpass))
             {
                 if (newpass == Request["txt_newpass2"])
                 {
                     store = new UserStore<User>(new ApplicationDbContext());
                     manager = new Microsoft.AspNet.Identity.UserManager<User>(store);
                     User user1 = manager.FindById(HttpContext.Current.User.Identity.GetUserId());
                     var task = await manager.ChangePasswordAsync(u.Id, oldpass, newpass);
                     if (task.Errors.ToList().Count > 0)
                     {
                         SiteLogic.AddError(task.Errors.ToList()[0]);
                     } else {
                         FormMessage.ShowSuccess(GetLocalResourceObject("err1").ToString());
                     }
                 }
                 else SiteLogic.AddError(GetLocalResourceObject("err2").ToString());
             }
             else SiteLogic.AddError(GetLocalResourceObject("err3").ToString());
         }
         else SiteLogic.AddError(GetLocalResourceObject("err4").ToString());
     }
 }
コード例 #2
0
        // GET: Playlist
        public ActionResult Index()
        {
            String  userId = User.Identity.GetUserId();
            AppUser user   = userManager.FindById(userId);

            ViewBag.Date = user.DateJoined;
            var playlists = db.Playlist.Where(a => a.OwnerID == userId);

            return(View(playlists));
        }
コード例 #3
0
        public ActionResult ChangeProfile()
        {
            ViewBag.Current = "Users";

            string          Uid  = this.User.Identity.GetUserId();
            ApplicationUser user = UserManager.FindById(Uid);



            if (user == null)

            {
                return(RedirectToAction("HttpNotFoundError", "ErrorController"));
            }
            EditUserNameAndPassword ED = new EditUserNameAndPassword()
            {
                OldUserName = user.UserName
            };

            return(View());
        }
コード例 #4
0
ファイル: ServiceUser.cs プロジェクト: nourWag/GWA
        public List <string> GetUserRoles(string username)
        {
            var           roleManager     = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(context));
            var           UserManager     = new Microsoft.AspNet.Identity.UserManager <User>(new UserStore <User>(context));
            List <string> ListOfRoleNames = new List <string>();
            var           ListOfRoleIds   = UserManager.FindById(username).Roles.Select(x => x.RoleId).ToList();

            foreach (string id in ListOfRoleIds)
            {
                string rolename = roleManager.FindById(id).Name;
                ListOfRoleNames.Add(rolename);
            }

            return(ListOfRoleNames);
        }
コード例 #5
0
    private void UpdateFormNew()
    {
        if (!string.IsNullOrEmpty(Request["isUpdate"]) && Request["isUpdate"] == "true")
        {
            store = new UserStore<User>(new ApplicationDbContext());
            manager = new Microsoft.AspNet.Identity.UserManager<User>(store);

            User user = manager.FindById(HttpContext.Current.User.Identity.GetUserId());
            TryUpdateModel(user, new FormValueProvider(ModelBindingExecutionContext));

            if (ModelState.IsValid)
            {
                var result = Task.Run(() => manager.UpdateAsync(user)).Result;
                store.Context.SaveChanges();
                UL.SetLoggedUser(user);
                FormMessage.ShowSuccess(GetLocalResourceObject("Success").ToString());
            }
            else
            {
                u.Email = u.UserName;
            }
        }
    }