예제 #1
0
        public async Task <IActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                User user = await _appService.GetUserByEmailAsync(model.Email);

                if (user == null)
                {
                    // добавляем пользователя в бд
                    await _appService.AddUserAsync(new User()
                    {
                        Email = model.Email, Password = model.Password
                    });

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

                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    ModelState.AddModelError("", "Некорректные логин и(или) пароль");
                }
            }
            return(View(model));
        }
예제 #2
0
        public async Task <IActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                User user = await _appService.GetUserByEmailAsync(model.Email);

                if (user == null)
                {
                    user = new User()
                    {
                        Email     = model.Email,
                        Password  = model.Password,
                        FirstName = model.FirstName,
                        LastName  = model.LastName,
                        Country   = model.Country,
                        Age       = (uint)model.Age,
                    };
                    if (user.IsValid())
                    {
                        // добавляем пользователя в бд
                        await _appService.AddUserAsync(user);
                    }
                    else
                    {
                        return(Content("invalid user")); //change to redirect
                    }

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

                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    ModelState.AddModelError("", "Некорректные логин и(или) пароль");
                }
            }
            return(View(model));
        }