コード例 #1
0
        public async Task<IHttpActionResult> Register(RegisterBindingModel model)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            IdentityUser user = new IdentityUser
            {
                UserName = model.UserName
            };

            IdentityResult result = await UserManager.CreateAsync(user, model.Password);
            IHttpActionResult errorResult = GetErrorResult(result);

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

            return Ok();
        }
コード例 #2
0
        public async Task<IHttpActionResult> Register(RegisterBindingModel model)
        {
            if (!ModelState.IsValid)
            {
                return BadRequest(ModelState);
            }

            var user = new ApplicationUser() { UserName = model.Email, Email = model.Email };

            IdentityResult result = await UserManager.CreateAsync(user, model.Password);

            if (!result.Succeeded)
            {
                return GetErrorResult(result);
            }

            return Ok();
        }
コード例 #3
0
        public async Task<Models.ApiResult> Register(RegisterBindingModel model)
        {
            var result = new Models.ApiResult();
            result.isSuccess = false;
            result.data = null;
            result.multipleData = null;

            /** want registerResult.Errors below 
            if (!ModelState.IsValid)
            {
                result.message = "Invalid user data";
                return result;
            }
             ****/

            var user = new ApplicationUser() { UserName = model.Email, Email = model.Email };

            IdentityResult registerResult = await UserManager.CreateAsync(user, model.Password);

            if (!registerResult.Succeeded)
            {
                // GetErrorResult(registerResult);
                result.message = registerResult.Errors.FirstOrDefault();
                return result;
            }

            //  return Ok();
            result.isSuccess = true;
            result.message = "User registered successfully";
            return result;
        }