public async Task <UserRegisteredModel> GetUserRegisteredResponse(Guid userId)
        {
            var user = await _messageRepository.GetUserDetails(userId);

            if (user != null)
            {
                var response = new UserRegisteredModel
                {
                    Data = user
                };

                return(response);
            }

            return(null);
        }
Exemple #2
0
        public async Task <IActionResult> Register([FromBody] UserRegisterModel user)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest($"{this.GetModelStateAllErrors()}"));
            }

            try
            {
                var applicationUser = new ApplicationUser
                {
                    Email    = user.Email,
                    UserName = user.Email
                };

                var userFromDatabase = await _userManager.FindByEmailAsync(applicationUser.Email);

                if (userFromDatabase != null)
                {
                    return(BadRequest("Email address already registered"));
                }

                var result = await _userManager.CreateAsync(applicationUser, user.Password);

                if (!result.Succeeded)
                {
                    _logger.LogError(LoggingEvents.ACCOUNT_REGISTER, $"Failed registration for user with email '{user.Email}' and password '{user.Password}'. Error messages: {string.Join(",", result.Errors)}");
                    return(BadRequest("Your registration could not be completed. Please refer to an admin of the site to help you"));
                }

                var registeredUser = new UserRegisteredModel
                {
                    Email = applicationUser.Email,
                    Id    = applicationUser.Id
                };
                return(Created($"/api/user/{registeredUser.Id}", registeredUser));
            }
            catch (Exception ex)
            {
                _logger.LogError(LoggingEvents.ACCOUNT_REGISTER, ex, $"Registration failed for user '{user.Email}' with password '{user.Password}'");
                return(this.InternalServerError());
            }
        }