コード例 #1
0
        public async Task <ActionResult> Register(UserViewModel user)
        {
            if (ModelState.IsValid)
            {
                var userModel = UserViewModelAssembler.FromViewModelToModel(user);
                OperationDetails operationDetails = await UserService.Create(userModel);

                if (operationDetails.Succedeed)
                {
                    TempData["Sucess"] = "Регистрация прошла успешно";
                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    ModelState.AddModelError(operationDetails.Property, operationDetails.Message);
                }
            }
            return(View(user));
        }
コード例 #2
0
        public async Task <ActionResult> Login(UserViewModel user)
        {
            if (ModelState.IsValid)
            {
                var            userModel = UserViewModelAssembler.FromViewModelToModel(user);
                ClaimsIdentity claim     = await UserService.Authenticate(userModel);

                if (claim == null)
                {
                    ModelState.AddModelError("", "Неверный логин или пароль.");
                }
                else
                {
                    AuthenticationManager.SignOut();
                    AuthenticationManager.SignIn(new AuthenticationProperties
                    {
                        IsPersistent = true
                    }, claim);
                    return(RedirectToAction("Index", "Home"));
                }
            }
            return(View(user));
        }