コード例 #1
0
ファイル: ManageController.cs プロジェクト: BredStik/allReady
        public async Task<IActionResult> Index(IndexViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return View(model);
            }
            var user = GetCurrentUser();

            if (!string.IsNullOrEmpty(user.Name))
            {
                user.Name = model.Name;
                await _userManager.RemoveClaimsAsync(user, User.Claims.Where(c=> c.Type == Security.ClaimTypes.DisplayName));
                await _userManager.AddClaimAsync(user, new Claim(Security.ClaimTypes.DisplayName, user.Name));
                
                await _signInManager.RefreshSignInAsync(user);
            }

            user.AssociatedSkills.RemoveAll(usk => model.AssociatedSkills == null || !model.AssociatedSkills.Any(msk => msk.SkillId == usk.SkillId));
            if (model.AssociatedSkills != null)
            {
                user.AssociatedSkills.AddRange(model.AssociatedSkills.Where(msk => !user.AssociatedSkills.Any(usk => usk.SkillId == msk.SkillId)));
            }
            user.AssociatedSkills?.ForEach(usk => usk.UserId = user.Id);

            await _dataAccess.UpdateUser(user);
            return RedirectToAction(nameof(Index));
        }
コード例 #2
0
ファイル: ManageController.cs プロジェクト: BredStik/allReady
        public async Task<IActionResult> Index(ManageMessageId? message = null)
        {
            ViewData["StatusMessage"] =
                message == ManageMessageId.ChangePasswordSuccess ? "Your password has been changed."
                : message == ManageMessageId.SetPasswordSuccess ? "Your password has been set."
                : message == ManageMessageId.SetTwoFactorSuccess ? "Your two-factor authentication provider has been set."
                : message == ManageMessageId.Error ? "An error has occurred."
                : message == ManageMessageId.AddPhoneSuccess ? "Your phone number was added."
                : message == ManageMessageId.RemovePhoneSuccess ? "Your phone number was removed."
                : "";

            var user = GetCurrentUser();
            var model = new IndexViewModel
            {
                HasPassword = await _userManager.HasPasswordAsync(user),
                EmailAddress = user.Email,
                IsEmailAddressConfirmed = user.EmailConfirmed,
                PhoneNumber = await _userManager.GetPhoneNumberAsync(user),
                TwoFactor = await _userManager.GetTwoFactorEnabledAsync(user),
                Logins = await _userManager.GetLoginsAsync(user),
                BrowserRemembered = await _signInManager.IsTwoFactorClientRememberedAsync(user),
                AssociatedSkills = user.AssociatedSkills,
                Name = user.Name
            };
            return View(model);
        }
コード例 #3
0
        public async Task<IActionResult> Index(IndexViewModel model)
        {
            var shouldRefreshSignin = false;

            var user = GetCurrentUser();

            if (!ModelState.IsValid)
            {
                var viewModelWithInputs = await user.ToViewModel(_userManager, _signInManager);
                viewModelWithInputs.Name = model.Name;
                viewModelWithInputs.TimeZoneId = model.TimeZoneId;
                viewModelWithInputs.AssociatedSkills = model.AssociatedSkills;
                return View(viewModelWithInputs);
            }

            if (!string.IsNullOrEmpty(model.Name))
            {
                user.Name = model.Name;
                shouldRefreshSignin = true;                
            }

            if (user.TimeZoneId != model.TimeZoneId)
            {
                user.TimeZoneId = model.TimeZoneId;
                await _userManager.RemoveClaimsAsync(user, User.Claims.Where(c => c.Type == Security.ClaimTypes.TimeZoneId));
                await _userManager.AddClaimAsync(user, new Claim(Security.ClaimTypes.TimeZoneId, user.TimeZoneId));
                shouldRefreshSignin = true;
            }

            user.AssociatedSkills.RemoveAll(usk => model.AssociatedSkills == null || !model.AssociatedSkills.Any(msk => msk.SkillId == usk.SkillId));
            if (model.AssociatedSkills != null)
            {
                user.AssociatedSkills.AddRange(model.AssociatedSkills.Where(msk => !user.AssociatedSkills.Any(usk => usk.SkillId == msk.SkillId)));
            }

            user.AssociatedSkills?.ForEach(usk => usk.UserId = user.Id);

            await _mediator.SendAsync(new UpdateUser { User = user });

            if (shouldRefreshSignin)
            {
                await _signInManager.RefreshSignInAsync(user);
            }

            await UpdateUserProfileCompleteness(user);

            return RedirectToAction(nameof(Microsoft.Data.Entity.Metadata.Internal.Index));
        }
コード例 #4
0
 public async Task<IActionResult> Index(IndexViewModel model)
 {
     if (!ModelState.IsValid)
     {
         return View(model);
     }
     var user = GetCurrentUser();
     user.Name = model.Name;
     user.AssociatedSkills.RemoveAll(usk => model.AssociatedSkills == null || !model.AssociatedSkills.Any(msk => msk.SkillId == usk.SkillId));
     if (model.AssociatedSkills != null)
     {
         user.AssociatedSkills.AddRange(model.AssociatedSkills.Where(msk => !user.AssociatedSkills.Any(usk => usk.SkillId == msk.SkillId)));
     }
     user.AssociatedSkills?.ForEach(usk => usk.UserId = user.Id);
     await _dataAccess.UpdateUser(user);
     return RedirectToAction(nameof(Index));
 }
コード例 #5
0
ファイル: ManageViewModels.cs プロジェクト: jwendl/allReady
 public static async Task<IndexViewModel> ToViewModel(this ApplicationUser user, UserManager<ApplicationUser> userManager, SignInManager<ApplicationUser> signInManager)
 {
     var result = new IndexViewModel
     {
         HasPassword = await userManager.HasPasswordAsync(user),
         EmailAddress = user.Email,
         IsEmailAddressConfirmed = user.EmailConfirmed,
         IsPhoneNumberConfirmed = user.PhoneNumberConfirmed,
         PhoneNumber = await userManager.GetPhoneNumberAsync(user),
         TwoFactor = await userManager.GetTwoFactorEnabledAsync(user),
         Logins = await userManager.GetLoginsAsync(user),
         BrowserRemembered = await signInManager.IsTwoFactorClientRememberedAsync(user),
         AssociatedSkills = user.AssociatedSkills,
         TimeZoneId = user.TimeZoneId,
         Name = user.Name,
         ProposedNewEmailAddress = user.PendingNewEmail
     };
     return result;
 }