Пример #1
0
        public async Task<IHttpActionResult> Register(UserModel userModel)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var result = await _userProvider.RegisterUser(userModel);
            var errorResult = GetErrorResult(result);

            if (errorResult != null)
            {
                return errorResult;
            }

            _userGroupManager.CreateUserGroup(userModel.UserName);

            return Ok();
        }
Пример #2
0
        /// <summary>
        /// Creates new user in the database
        /// </summary>
        public async Task<IdentityResult> RegisterUser(UserModel userModel)
        {
            var user = new IdentityUser
            {
                UserName = userModel.UserName
            };

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

            //add additional claims to store the user's first and last names
            if (result.Succeeded)
            {
                _userManager.AddClaim(user.Id, new Claim(SecurityGlobal.FirstNameClaim, userModel.FirstName));
                _userManager.AddClaim(user.Id, new Claim(SecurityGlobal.LastNameClaim, userModel.LastName));
                _userManager.AddClaim(user.Id, new Claim(SecurityGlobal.FullNameClaim, $"{userModel.FirstName} {userModel.LastName}"));
            }

            return result;
        }