예제 #1
0
        public async Task <IActionResult> OnPostUserLogin(UserLoginModel model,
                                                          [FromServices] GetShopUser getShopUser)
        {
            if (ModelState.IsValid)
            {
                //User user = await _context.Users
                //    .Include(u => u.Role)
                //    .FirstOrDefaultAsync(u => u.Email == model.Email && u.Password == model.Password);
                var user = getShopUser.Do(model.Input.Email, model.Input.Password);
                if (user != null)
                {
                    ShopUserViewModel userViewModel = new ShopUserViewModel {
                        Email    = user?.Email,
                        RoleName = user?.Role?.Name
                    };

                    await Authenticate(userViewModel); // аутентификация

                    string url = Url.Page("VueLoginOrder", new { email = user.Email });
                    return(Redirect(url));
                }
                ModelState.AddModelError("", "Invalid login or password");
                return(Page());
            }
            return(Page());
        }
예제 #2
0
        public async Task <IActionResult> OnPostUserRegister(UserRegisterModel model,
                                                             [FromServices] GetShopUser getShopUser,
                                                             [FromServices] CreateShopUser createShopUser)
        {
            if (ModelState.IsValid)
            {
                //var user = await _context.Users.FirstOrDefaultAsync(u => u.Email == model.Email);
                var user = getShopUser.Do(model.Input.Email);
                if (user == null)
                {
                    // добавляем пользователя в бд
                    var userResponse = createShopUser.Do(
                        model.Input.UserName, model.Input.Password, model.Input.Email);

                    ShopUserViewModel userViewModel = new ShopUserViewModel {
                        Email    = userResponse?.Email,
                        RoleName = userResponse?.RoleName
                    };

                    await Authenticate(userViewModel); // аутентификация

                    return(RedirectToPage("../Index"));
                }
                else
                {
                    ModelState.AddModelError("", "already existing");
                    return(Page());
                }
            }
            return(Page());
        }