Beispiel #1
0
 public static EditUserViewModel FromUser(AppUser user)
 {
     return new EditUserViewModel()
     {
         Id = user.Id,
         UserName = user.UserName,
         Email = user.Email,
     };
 }
Beispiel #2
0
 public async Task SignInAsync(AppUser user, bool isPersistent, bool rememberBrowser)
 {
     // Clear any partial cookies from external or two factor partial sign ins
     AuthenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie, DefaultAuthenticationTypes.TwoFactorCookie);
     var userIdentity = await user.GenerateUserIdentityAsync(UserManager);
     if (rememberBrowser)
     {
         var rememberBrowserIdentity = AuthenticationManager.CreateTwoFactorRememberBrowserIdentity(user.Id);
         AuthenticationManager.SignIn(new AuthenticationProperties { IsPersistent = isPersistent }, userIdentity, rememberBrowserIdentity);
     }
     else
     {
         AuthenticationManager.SignIn(new AuthenticationProperties { IsPersistent = isPersistent }, userIdentity);
     }
 }
Beispiel #3
0
 public async Task<ActionResult> Create(CreateUserViewModel model)
 {
     if (model != null && ModelState.IsValid)
     {
         AppUser user = new AppUser
         {
             UserName = model.Name,
             Email = model.Email
         };
         IdentityResult result = await UserManager.CreateAsync(user, model.Password);
         if (result.Succeeded)
         {
             this.TempData["success"] = string.Format("Потребителя {0} беше създаден успешно.", model.Name);
             return RedirectToAction("Index");
         }
         else
         {
             AddErrorsFromResult(result);
         }
     }
     return View(model);
 }
Beispiel #4
0
 private async Task SignInAsync(AppUser user, bool isPersistent)
 {
     AuthManager.SignOut(DefaultAuthenticationTypes.ExternalCookie, DefaultAuthenticationTypes.TwoFactorCookie);
     AuthManager.SignIn(new AuthenticationProperties { IsPersistent = isPersistent }, await user.GenerateUserIdentityAsync(UserManager));
 }
Beispiel #5
0
 /// <summary>
 /// Validates the curent password async.
 /// </summary>
 /// <param name="user">The user.</param>
 /// <param name="controlUser">The control user.</param>
 /// <returns></returns>
 private Task<IdentityResult> ValidateCurentPasswordAsync(EditUserViewModel user, AppUser controlUser)
 {
     // TODO: Implement this method
     throw new NotImplementedException();
 }
Beispiel #6
0
        private async Task<SignInStatus> SignInOrTwoFactor(AppUser user, bool isPersistent)
        {
            if (await UserManager.GetTwoFactorEnabledAsync(user.Id) &&
                !await AuthenticationManager.TwoFactorBrowserRememberedAsync(user.Id))
            {
                var identity = new ClaimsIdentity(DefaultAuthenticationTypes.TwoFactorCookie);
                identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, user.Id));
                AuthenticationManager.SignIn(identity);
                return SignInStatus.RequiresTwoFactorAuthentication;
            }
            await SignInAsync(user, isPersistent, false);
            return SignInStatus.Success;

        }