コード例 #1
0
        public async Task SignUp(UserRegistrerModel userModel)
        {
            var user = new User {
                FirstName = userModel.FirstName, LastName = userModel.LastName, Email = userModel.Email, UserName = userModel.Email
            };
            var result = await _userManager.CreateAsync(user, userModel.Password);

            if (result.Succeeded)
            {
                await _userManager.AddClaimsAsync(user, new Claim[] { new Claim(ClaimTypes.Role, "Client"),
                                                                      new Claim(ClaimTypes.NameIdentifier, user.Id.ToString()),
                                                                      new Claim("FirstName", userModel.FirstName),
                                                                      new Claim("LastName", userModel.LastName) });

                return;
            }

            foreach (var error in result.Errors)
            {
                throw new SignUpFailException(error.Description);
            }

            throw new SignUpFailException("Signup faild!");
        }
コード例 #2
0
        public async Task <IActionResult> Register(UserRegistrerModel userModel)
        {
            await _userService.SignUp(userModel);

            return(Ok());
        }