public async Task <IActionResult> RegisterAdmin(MegaViewModel avm, string returnUrl = null) { ViewData["ReturnUrl"] = returnUrl; if (ModelState.IsValid) { var user = new ApplicationUser { UserName = avm.RegisterViewModel.Email, Email = avm.RegisterViewModel.Email }; var result = await _userManager.CreateAsync(user, avm.RegisterViewModel.Password); //If user is created correctly, assign them and admin role if (result.Succeeded) { List <Claim> memberClaims = new List <Claim>(); Claim admin = new Claim(ClaimTypes.Role, "Admin", ClaimValueTypes.String); memberClaims.Add(admin); var addClaims = await _userManager.AddClaimsAsync(user, memberClaims); //Sign in the new administrator if (addClaims.Succeeded) { await _signInManager.SignInAsync(user, isPersistent : false); return(RedirectToAction("Index", "Home")); } } } return(View()); }
public async Task <IActionResult> Login(MegaViewModel lvm) { if (ModelState.IsValid) { //bind viewmodel data to user and sign in. var result = await _signInManager.PasswordSignInAsync(lvm.LoginViewModel.Email, lvm.LoginViewModel.Password, lvm.LoginViewModel.RememberMe, lockoutOnFailure : false); if (result.Succeeded) { var userIdentity = new ClaimsIdentity("Registration"); var userPrinciple = new ClaimsPrincipal(userIdentity); await HttpContext.SignInAsync( "CookieLogin", userPrinciple, new AuthenticationProperties { ExpiresUtc = DateTime.UtcNow.AddMinutes(45), IsPersistent = false, AllowRefresh = false }); return(RedirectToAction("Index", "Home")); } } string error = "Unable to log you in. Please try again or contact your system admin."; ModelState.AddModelError("", error); return(RedirectToAction("Index", "UserAuth")); }
public void MegaViewModelRegisterConfirmPassword() { MegaViewModel mega = new MegaViewModel { RegisterViewModel = new RegisterViewModel { ConfirmPassword = "******" } }; string result = mega.RegisterViewModel.ConfirmPassword; Assert.Equal(result, mega.RegisterViewModel.ConfirmPassword); }
public void MegaViewModelRegisterConfirmPasswordIsString() { MegaViewModel mega = new MegaViewModel { RegisterViewModel = new RegisterViewModel { ConfirmPassword = "******" } }; string result = mega.RegisterViewModel.ConfirmPassword; Assert.IsType <string>(result); }
public void MegaViewModelRegisterEmailIsString() { MegaViewModel mega = new MegaViewModel { RegisterViewModel = new RegisterViewModel { Email = "*****@*****.**" } }; string result = mega.RegisterViewModel.Email; Assert.IsType <string>(result); }
public void MegaViewModelLoginEmailIsString() { MegaViewModel mega = new MegaViewModel { LoginViewModel = new LoginViewModel { Email = "*****@*****.**" } }; string result = mega.LoginViewModel.Email; Assert.IsType <string>(result); }
public void MegaViewModelRegisterEmail() { MegaViewModel mega = new MegaViewModel { RegisterViewModel = new RegisterViewModel { Email = "*****@*****.**" } }; string result = mega.RegisterViewModel.Email; Assert.Equal(result, mega.RegisterViewModel.Email); }
public void MegaViewModelLoginEmail() { MegaViewModel mega = new MegaViewModel { LoginViewModel = new LoginViewModel { Email = "*****@*****.**" } }; string result = mega.LoginViewModel.Email; Assert.Equal(result, mega.LoginViewModel.Email); }
public void MegaViewModelLoginRememberMeIsBool() { MegaViewModel mega = new MegaViewModel { LoginViewModel = new LoginViewModel { RememberMe = true } }; bool result = mega.LoginViewModel.RememberMe; Assert.IsType <bool>(result); }
public void MegaViewModelLoginRememberMe() { MegaViewModel mega = new MegaViewModel { LoginViewModel = new LoginViewModel { RememberMe = true } }; bool result = mega.LoginViewModel.RememberMe; Assert.Equal(result, mega.LoginViewModel.RememberMe); }
public void MegaViewModelLoginPasswordIsString() { MegaViewModel mega = new MegaViewModel { LoginViewModel = new LoginViewModel { Password = "******" } }; string result = mega.LoginViewModel.Password; Assert.IsType <string>(result); }
public void MegaViewModelLoginPassword() { MegaViewModel mega = new MegaViewModel { LoginViewModel = new LoginViewModel { Password = "******" } }; string result = mega.LoginViewModel.Password; Assert.Equal(result, mega.LoginViewModel.Password); }
public async Task <IActionResult> Register(MegaViewModel rvm, string returnUrl = null) { ViewData["ReturnUrl"] = returnUrl; if (ModelState.IsValid) { var user = new ApplicationUser { UserName = rvm.RegisterViewModel.Email, Email = rvm.RegisterViewModel.Email }; var result = await _userManager.CreateAsync(user, rvm.RegisterViewModel.Password); if (result.Succeeded) { await _signInManager.SignInAsync(user, isPersistent : false); return(RedirectToAction("Index", "Home")); } } return(RedirectToAction("Index", "UserAuth")); }
public void MegaViewModelRegisterLoginPasswordsMatch() { MegaViewModel mega = new MegaViewModel { RegisterViewModel = new RegisterViewModel { Password = "******" } }; MegaViewModel mega2 = new MegaViewModel { LoginViewModel = new LoginViewModel { Password = "******" } }; string result = mega.RegisterViewModel.Password; string result2 = mega2.LoginViewModel.Password; Assert.Equal(result, result2); }