Exemplo n.º 1
0
        public async Task <AuthResponseDto> RegisterAsync(RegistrationCommand userInput)
        {
            var userFound = await _userManager.FindByNameAsync(userInput.Username);

            if (userFound != null)
            {
                throw new RestException(HttpStatusCode.BadRequest, new { Username = "******" });
            }
            var user = new User(userInput.Username, null, new PersonName("", "", ""), null);

            var created = await _userService.CreateUser(user, userInput.Password, userInput.Role);

            if (created)
            {
                return(new AuthResponseDto(_tokenGenerator.CreateJwtToken(user),
                                           user.UserName,
                                           new List <string> {
                    userInput.Role
                },
                                           DateTime.Now.AddHours(JwtExpireTimeEnum.HoursToExpire.GetValue())
                                           ));
            }
            throw new SmartHubException("Problem Registering new User");
        }
Exemplo n.º 2
0
        public async Task <ServiceResponse <AuthResponseDto> > Handle(RegistrationCommand request, CancellationToken cancellationToken)
        {
            var result = await _registrationService.RegisterAsync(request).ConfigureAwait(false);

            return(new ServiceResponse <AuthResponseDto>(result, true, "Successful"));
        }