예제 #1
0
        public async Task <IHttpActionResult> ConfirmEmail(string userId = "", string code = "")
        {
            _logger.Debug(string.Format("Begin. UserId: [{0}], Code: [{1}]"));
            if (string.IsNullOrWhiteSpace(userId) || string.IsNullOrWhiteSpace(code))
            {
                ModelState.AddModelError("", "User Id and Code are required");
                _logger.Error(string.Format(
                                  "Model state is not valid. ModelState: [{0}]",
                                  string.Join(Environment.NewLine, ModelState.Select(x => string.Format("{0}: {1}", x.Key, x.Value)))));
                return(BadRequest(ModelState));
            }

            IdentityResult result = await NdUserManager.ConfirmEmailAsync(userId, code);

            if (result.Succeeded)
            {
                _logger.Debug(string.Format("Email confirmed successfully. Id: [{0}]", userId));
                return(Ok());
            }
            else
            {
                _logger.Error(string.Format(
                                  "Confirm email failed. Id: [{0}], Code: [{1}], Reason: [{2}]",
                                  userId, code,
                                  string.Join(Environment.NewLine, result.Errors)));
                return(GetErrorResult(result));
            }
        }