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"));
        }
Exemple #3
0
        public void MegaViewModelRegisterConfirmPassword()
        {
            MegaViewModel mega = new MegaViewModel
            {
                RegisterViewModel = new RegisterViewModel
                {
                    ConfirmPassword = "******"
                }
            };
            string result = mega.RegisterViewModel.ConfirmPassword;

            Assert.Equal(result, mega.RegisterViewModel.ConfirmPassword);
        }
Exemple #4
0
        public void MegaViewModelRegisterConfirmPasswordIsString()
        {
            MegaViewModel mega = new MegaViewModel
            {
                RegisterViewModel = new RegisterViewModel
                {
                    ConfirmPassword = "******"
                }
            };
            string result = mega.RegisterViewModel.ConfirmPassword;

            Assert.IsType <string>(result);
        }
Exemple #5
0
        public void MegaViewModelRegisterEmailIsString()
        {
            MegaViewModel mega = new MegaViewModel
            {
                RegisterViewModel = new RegisterViewModel
                {
                    Email = "*****@*****.**"
                }
            };
            string result = mega.RegisterViewModel.Email;

            Assert.IsType <string>(result);
        }
Exemple #6
0
        public void MegaViewModelLoginEmailIsString()
        {
            MegaViewModel mega = new MegaViewModel
            {
                LoginViewModel = new LoginViewModel
                {
                    Email = "*****@*****.**"
                }
            };
            string result = mega.LoginViewModel.Email;

            Assert.IsType <string>(result);
        }
Exemple #7
0
        public void MegaViewModelRegisterEmail()
        {
            MegaViewModel mega = new MegaViewModel
            {
                RegisterViewModel = new RegisterViewModel
                {
                    Email = "*****@*****.**"
                }
            };
            string result = mega.RegisterViewModel.Email;

            Assert.Equal(result, mega.RegisterViewModel.Email);
        }
Exemple #8
0
        public void MegaViewModelLoginEmail()
        {
            MegaViewModel mega = new MegaViewModel
            {
                LoginViewModel = new LoginViewModel
                {
                    Email = "*****@*****.**"
                }
            };
            string result = mega.LoginViewModel.Email;

            Assert.Equal(result, mega.LoginViewModel.Email);
        }
Exemple #9
0
        public void MegaViewModelLoginRememberMeIsBool()
        {
            MegaViewModel mega = new MegaViewModel
            {
                LoginViewModel = new LoginViewModel
                {
                    RememberMe = true
                }
            };
            bool result = mega.LoginViewModel.RememberMe;

            Assert.IsType <bool>(result);
        }
Exemple #10
0
        public void MegaViewModelLoginRememberMe()
        {
            MegaViewModel mega = new MegaViewModel
            {
                LoginViewModel = new LoginViewModel
                {
                    RememberMe = true
                }
            };
            bool result = mega.LoginViewModel.RememberMe;

            Assert.Equal(result, mega.LoginViewModel.RememberMe);
        }
Exemple #11
0
        public void MegaViewModelLoginPasswordIsString()
        {
            MegaViewModel mega = new MegaViewModel
            {
                LoginViewModel = new LoginViewModel
                {
                    Password = "******"
                }
            };
            string result = mega.LoginViewModel.Password;

            Assert.IsType <string>(result);
        }
Exemple #12
0
        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"));
        }
Exemple #14
0
        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);
        }