Exemplo n.º 1
0
        public ActionResult Register(RegisterViewModel user)
        {
            if (ModelState.IsValid == false)
            {
                return(View(user));
            }
            IdentityResult result = accountAppService.Register(user);

            if (result.Succeeded)
            {
                CartAppService         cartAppService = new CartAppService();
                IAuthenticationManager owinMAnager    = HttpContext.GetOwinContext().Authentication;
                //SignIn
                SignInManager <ApplicationUserIdentity, string> signinmanager =
                    new SignInManager <ApplicationUserIdentity, string>(
                        new ApplicationUserManager(), owinMAnager
                        );
                ApplicationUserIdentity identityUser = accountAppService.Find(user.UserName, user.PasswordHash);
                signinmanager.SignIn(identityUser, true, true);

                /*
                 * var userSignIn = User.Identity.GetUserId();
                 * cartAppService.InsertCart(userSignIn);
                 */
                return(RedirectToAction("Index", "Home"));
            }
            else
            {
                ModelState.AddModelError("", result.Errors.FirstOrDefault());
                return(View(user));
            }
        }
Exemplo n.º 2
0
        public void Find_userTest()
        {
            var user = account.Find("bahy", "12345678");

            //Assert.That(user.UserName,Does.StartWith("b").And.EndsWith("y"));
            Assert.That(user.Email, Does.Contain("bahy"));
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Login([FromBody] LoginDto model)
        {
            var user = await _accountAppService.Find(model.UserName, model.PasswordHash);

            if (user != null)
            {
                dynamic token = await _accountAppService.CreateToken(user);

                return(Ok(token));
            }
            return(Unauthorized());
        }
Exemplo n.º 4
0
        public ActionResult Register(RegisterVM user)
        {
            if (ModelState.IsValid == false)
            {
                return(View(user));
            }
            IdentityResult result = accountAppService.Register(user);

            if (result.Succeeded)
            {
                IAuthenticationManager owinMAnager = HttpContext.GetOwinContext().Authentication;
                //SignIn
                SignInManager <ApplicationUserIdentity, string> signinmanager =
                    new SignInManager <ApplicationUserIdentity, string>(
                        new ApplicationUserManager(), owinMAnager
                        );
                ApplicationUserIdentity identityUser = accountAppService.Find(user.UserName, user.PasswordHash);

                accountAppService.AssignToRole(identityUser.Id, "Dealer"); //Add user to Role


                dealerAppService.SaveNewDealer(new DAL.Dealer {
                    Id = identityUser.Id,
                });                                                                          //To add UserId to Dealer table, like make the relatin manwal

                notificationAppService.SaveNewNotification(new Notification {
                    Id = identityUser.Id, MessageNotification = 0
                });                                                                                                             //To add UserId to Notification table, like make the relatin manwal

                signinmanager.SignIn(identityUser, true, true);
                return(RedirectToAction("Index", "Car", new { area = "Dealer" }));//Dealer area
            }
            else
            {
                ModelState.AddModelError("", result.Errors.FirstOrDefault());
                return(View(user));
            }
        }
Exemplo n.º 5
0
        public ActionResult Register(RegisterViewModel newUser, bool isHost = false)
        {
            if (!ModelState.IsValid)
            {
                return(View(newUser));
            }
            IdentityResult result = accountAppService.Register(newUser, isHost, User.IsInRole("Admin"));

            if (result.Succeeded)
            {
                ApplicationIdentityUser registeredUser = accountAppService.Find(newUser.UserName, newUser.PasswordHash);

                if (User.IsInRole("Admin"))
                {
                    accountAppService.AssignToRole(registeredUser.Id, "Admin");
                }
                else
                {
                    if (isHost)
                    {
                        accountAppService.AssignToRole(registeredUser.Id, "Host");
                    }
                    else
                    {
                        accountAppService.AssignToRole(registeredUser.Id, "User");
                        ShoppingCartAppService.Insert(registeredUser.Id);
                    }
                }
                return(RedirectToAction("Login"));
            }
            else
            {
                ModelState.AddModelError("", result.Errors.FirstOrDefault());
                return(View(newUser));
            }
        }
Exemplo n.º 6
0
        public void EventAppServiceStartup()
        {
            accountAppService = new AccountAppService();
            eventAppService   = new EventAppService();
            host = accountAppService.Find("TestHost", "TestHost");



            EventViewModel eventViewModel = new EventViewModel();

            eventViewModel.HostId   = host.Id;
            eventViewModel.Name     = "TestEvent1";
            eventViewModel.location = "Test";
            eventViewModel.price    = 4;
            eventViewModel.TotalAvailableTickets = 5;
            eventViewModel.category = 0;
            eventViewModel.date     = DateTime.Now;
            Event1 = eventAppService.SaveNewEvent(eventViewModel);
        }
Exemplo n.º 7
0
 public void ShoppingCartSetup()
 {
     accountAppService      = new AccountAppService();
     shoppingCartAppService = new ShoppingCartAppService();
     user = accountAppService.Find("TestUser", "TestUser");
 }
Exemplo n.º 8
0
 public void HostUserSetUp()
 {
     hostUserAppService = new HostUserAppService();
     accountAppService  = new AccountAppService();
     hostUser           = accountAppService.Find("TestHost", "TestHost");
 }