Exemplo n.º 1
0
        public async Task <VoidInteractorResult> Call(RegisterRequest request)
        {
            return(await PerformCall(async() =>
            {
                if (request.Password != request.PasswordConfirmation)
                {
                    return VoidInteractorResult.ForFailure(Message.For("PasswordMismatch", "The passwords did not match."));
                }

                var user = new ApplicationUser
                {
                    UserName = request.Email,
                    Email = request.Email,
                    Name = request.Name
                };
                var validation = user.Validate();
                if (!validation.IsValid)
                {
                    return VoidInteractorResult.ForFailure(validation.Messages);
                }

                var result = await _userManager.CreateAsync(user, request.Password);
                if (!result.Succeeded)
                {
                    return VoidInteractorResult.ForFailure(
                        result.Errors.Select(x => Message.For(x.Code, x.Description)).ToList()
                        );
                }

                await _signInManager.SignInAsync(user, false);

                return VoidInteractorResult.ForSuccess();
            }));
        }
 public async Task <VoidInteractorResult> Call()
 {
     return(await PerformCall(async() =>
     {
         await _signInManager.SignOutAsync();
         return VoidInteractorResult.ForSuccess();
     }));
 }
        public async Task <VoidInteractorResult> Call(LoginRequest request)
        {
            return(await PerformCall(async() =>
            {
                var result = await _signInManager.PasswordSignInAsync(request.Email, request.Password, request.RememberMe, true);

                if (!result.Succeeded)
                {
                    return VoidInteractorResult.ForFailure(Message.For("InvalidLogin", "Log in failed. Please check info and try again."));
                }
                if (result.IsLockedOut)
                {
                    return VoidInteractorResult.ForFailure(Message.For("AccountLockedOut", "Login attempts exceeded maximum. Account locked."));
                }

                return VoidInteractorResult.ForSuccess();
            }));
        }
 protected JsonResult Result(VoidInteractorResult interactorResult)
 {
     return(Result(HttpStatusCode.OK, interactorResult));
 }