Ejemplo n.º 1
0
        public async Task<IdentityResult> RegisterUser(UserModel userModel)
        {
            IdentityUser user = new IdentityUser
            {
                UserName = userModel.UserName
            };

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

            return result;
        }
 public async Task<IHttpActionResult> Register(UserModel userModel)
 {
     if(!ModelState.IsValid)
     {
         return BadRequest(ModelState);
     }
     IdentityResult result = await _repo.RegisterUser(userModel);
     IHttpActionResult errorResult = GetErrorResult(result);
     if (errorResult != null)
     {
         return errorResult;
     }
     return Ok();
 }
Ejemplo n.º 3
0
        public async Task<IHttpActionResult> Register(UserModel userModel)
        {
            _repo.CreateRole("Users");

            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            IdentityResult result = await _repo.RegisterUser(userModel);


            IHttpActionResult errorResult = GetErrorResult(result);

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

            _repo.AddUserToRole(userModel.UserName, "Users");
            //_repo.AddUserToRole(userModel.UserName, "Admins");
            return Ok();
        }