Esempio n. 1
0
        public async Task <IActionResult> Register([FromBody] UserModel userModel)
        {
            if (string.IsNullOrEmpty(userModel.UserName) || string.IsNullOrEmpty(userModel.Password))
            {
                return(BadRequest());
            }

            User user;

            user = await _userManager.FindByNameAsync(userModel.UserName);

            if (user != null)
            {
                return(BadRequest());
            }
            user = new User
            {
                UserName = userModel.UserName
            };
            var userCreation = await _userManager.CreateAsync(user, userModel.Password);

            if (userCreation.Succeeded)
            {
                var jwtToken = GenerateJwtToken(user);
                return(Ok(new { token = jwtToken }));
            }
            return(BadRequest());
        }
Esempio n. 2
0
        public async Task <IActionResult> Add([FromBody] PersonModel model)
        {
            var user = await _userManagerWrapper.FindByNameAsync(User.Identity.Name);

            model.UserId = user.Id;
            var addPersonCommand = new AddPersonCommand {
                Person = model
            };
            await _endpointInstance.Send("LifeManager.People", addPersonCommand).ConfigureAwait(false);

            return(Ok());
        }
Esempio n. 3
0
        public string GetTenantID()
        {
            var identity = httpContextAccessor.HttpContext.User?.Identity;

            if (identity == null || !identity.IsAuthenticated)
            {
                return("");
            }
            var user = userManager.FindByNameAsync(identity.Name).Result;

            return(user.TenantID);
        }