예제 #1
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                ClientProfileDto clientDto = new ClientProfileDto
                {
                    Email    = model.Email,
                    Password = model.Password,
                    Name     = model.UserName,
                    UserName = model.UserName,
                };

                OperationDetails operationDetails = await clientSevice.CreateUser(clientDto);

                if (operationDetails.Succedeed)
                {
                    ClaimsIdentity claim = await clientSevice.Authenticate(clientDto);

                    AuthenticationManager.SignIn(new AuthenticationProperties {
                        IsPersistent = true
                    }, claim);
                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    ModelState.AddModelError(operationDetails.Property, operationDetails.Message);
                }
            }
            return(View(model));
        }