示例#1
0
        public async Task<IdentityResult> RegisterUser(RegisterUserBindingModel registerUserModel)
        {
            AbitInfoIdentityUser user = new AbitInfoIdentityUser
            {
                UserName = registerUserModel.Username,
                CreationTime = DateTime.UtcNow,
                Email = registerUserModel.Email,
                EmailConfirmed = true,
                Banned = false
            };

            using (IdentityDbContext<AbitInfoIdentityUser> context = _identityProvider.Context)
            {
                UserManager<AbitInfoIdentityUser> userManager =
                    _identityProvider.GetUserManager(context);

                IdentityResult result = await userManager.
                    CreateAsync(user, registerUserModel.Password);
                if (result.Succeeded)
                {
                    userManager.AddToRole(user.Id, "User");
                }
                return result;
            }
        }
示例#2
0
        public async Task<IHttpActionResult> Register(RegisterUserBindingModel registerUserModel)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }
            IdentityResult result = await _authService.RegisterUser(registerUserModel);
            IHttpActionResult errorResult = GetErrorResult(result);
            if (errorResult != null)
            {
                return errorResult;
            }
            var user = await _authService.FindUser(registerUserModel.Username, registerUserModel.Password);

            Uri locationHeader = new Uri("");
            return Created(locationHeader, user);
        }