public IActionResult ResetPasswordExists(string token)
        {
            this.logger.LogDebug(string.Format(CultureInfo.InvariantCulture, this.localizer["LogResetPasswordExistsTry"].Value));

            if (string.IsNullOrEmpty(token))
            {
                throw new ArgumentNullException(nameof(token));
            }

            UserPasswordResetToken userPasswordResetToken = this.userPasswordResetTokenService.GetByToken(token);
            User user;

            if (userPasswordResetToken == null)
            {
                this.logger.LogDebug(string.Format(CultureInfo.InvariantCulture, this.localizer["LogResetPasswordExistsNotFound"].Value, token));
                return(this.NotFound(new { message = string.Format(CultureInfo.InvariantCulture, this.localizer["LogResetPasswordExistsNotFound"].Value, token) }));
            }

            if (this.userPasswordResetTokenService.IsValid(userPasswordResetToken))
            {
                user = this.userService.Get(userPasswordResetToken.CreatedBy.Id);
                if (user != null)
                {
                    return(this.Ok(new UserPasswordLostResponseModel()
                    {
                        Username = user.Username, Email = user.Email
                    }));
                }
                else
                {
                    this.logger.LogError(string.Format(CultureInfo.InvariantCulture, this.localizer["LogResetPasswordExistsUserNotFound"].Value));
                    return(this.NotFound(new { message = string.Format(CultureInfo.InvariantCulture, this.localizer["LogResetPasswordExistsUserNotFound"].Value) }));
                }
            }
            else
            {
                return(this.StatusCode(498, new { message = string.Format(CultureInfo.InvariantCulture, this.localizer["LogResetPasswordExistsNotValid"].Value) }));
            }
        }
        public IActionResult ForgotPassword([FromBody] UserPasswordLostModel model)
        {
            this.logger.LogDebug(string.Format(CultureInfo.InvariantCulture, this.localizer["LogPasswordLostTokenTry"].Value));

            if (model == null)
            {
                throw new ArgumentNullException(nameof(model));
            }

            User user = null;

            if (!string.IsNullOrEmpty(model.Email))
            {
                user = this.userService.GetByEmail(model.Email);
            }
            else if (!string.IsNullOrEmpty(model.Username))
            {
                user = this.userService.GetByUsername(model.Username);
            }

            if (user == null)
            {
                this.logger.LogDebug(string.Format(CultureInfo.InvariantCulture, this.localizer["LogPasswordLostTokenUserNotFound"].Value, new { method = !string.IsNullOrEmpty(model.Email) ? "email" : "username", value = model.Email ?? model.Username }));
                return(this.NotFound(new { message = string.Format(CultureInfo.InvariantCulture, this.localizer["LogPasswordLostTokenUserNotFound"].Value) }));
            }

            UserPasswordResetToken userPasswordResetToken;
            string token;

            try
            {
                token = CryptographicHelper.GetUrlSafeToken(24);
                userPasswordResetToken = new UserPasswordResetToken()
                {
                    Token      = token,
                    ValidUntil = DateTime.UtcNow.AddMinutes(this.appSettings.Security.ResetPasswordTokenDurationInMinutes),
                    Created    = DateTime.UtcNow,
                    CreatedBy  = new UserReference()
                    {
                        Id = user.Id, Username = user.Username
                    },
                };
                userPasswordResetToken = this.userPasswordResetTokenService.Create(userPasswordResetToken);

                // Sending reset password email, with token in clear value.
                this.emailService.SendTemplate(new EmailAddress()
                {
                    Address = user.Email, Name = user.Username
                }, "PasswordLost", new
                {
                    username          = user.Username,
                    resetpasswordlink = $"{new Uri(this.appSettings.Environment.FrontUrl, $"#/user/resetpassword/{token}")}",
                    sitename          = this.appSettings.Environment.Name,
                    siteurl           = this.appSettings.Environment.FrontUrl.ToString(),
                    unsubscribeurl    = new Uri(this.appSettings.Environment.FrontUrl, "/user/unsubscribe").ToString(),
                });
            }
            catch (Exception ex)
            {
                // TODO: Gérer les exceptions, avec message localisé
                this.logger.LogError(string.Format(CultureInfo.InvariantCulture, this.localizer["LogPasswordLostTokenFailed"].Value));
                return(this.Problem(
                           statusCode: (int)HttpStatusCode.InternalServerError,
                           title: ex.ToString(),
                           detail: ex.StackTrace));
            }

            this.logger.LogDebug(string.Format(CultureInfo.InvariantCulture, this.localizer["LogPasswordLostTokenSuccess"].Value, new { value = model.Email ?? model.Username }));
            return(this.Ok());
        }