Example #1
0
        public async Task <IActionResult> Register([FromBody] UserRegisterRequest req)
        {
            // Yuck
            UserLogin?login = null;

            bus.Listen <UserRegisterEvent>(e => login = ((UserRegisterEvent)e).Login);

            var result = await mediator.Command(new RegisterUserCommand()
            {
                Registration = new UserRegistration(req.Username, req.Password, req.Email)
            });


            result.Match <IActionResult>(
                result => login != null ? Ok(new { Id = result.InsertId, AuthToken = tokenHandler.IssueToken(login) }) : BadRequest() as IActionResult,
                error => BadRequest(error.Message)
                );

            if (login != null)
            {
                return(Ok(login));
            }
            else
            {
                return(BadRequest(result.Right().Message));
            }
        }
Example #2
0
        public async Task <ActionResult> Register([FromBody] UserRegisterRequest req)
        {
            var result = await userRegistrar.Handle(new UserRegisterParams(req.Username, req.Password, req.Email));

            return(result.Match <ActionResult>(
                       login => Ok(login),
                       fail => BadRequest(fail)
                       ));
        }