コード例 #1
0
        public async Task <dynamic> Post([FromBody] PasswordRecoveryRequest requestBody)
        {
            this.EnsureModelValidation();

            var collection = MongoWrapper.Database.GetCollection <Models.User>(nameof(User));

            var projectionBuilder = new ProjectionDefinitionBuilder <Models.User>();
            var projection        = projectionBuilder
                                    .Include(u => u._id)
                                    .Include(u => u.Email)
                                    .Include(u => u.FullName)
                                    .Include("_t");

            var filterBuilder = new FilterDefinitionBuilder <Models.User>();
            var filter        = filterBuilder.And(
                filterBuilder.Eq(u => u.Email, requestBody.Email),
                GeneralUtils.NotDeactivated(filterBuilder)
                );

            var user = (await collection.FindAsync(filter, new FindOptions <Models.User>
            {
                Limit = 1,
                Projection = projection,
            })).SingleOrDefault();

            await EmailUtils.SendPasswordRecoveryEmail(MongoWrapper, SmtpConfiguration, user);

            return(new ResponseBody
            {
                Code = ResponseCode.GenericSuccess,
                Data = null,
                Message = "Um código foi enviado para o e-mail! Este código permite a redefinição para uma senha gerada automaticamente.",
                Success = true,
            });
        }