Пример #1
0
        public async Task <string> GenerateNewCode(string appId)
        {
            int       expressSeconds = 5 * 60;
            CodeModel model          = new CodeModel
            {
                Code      = ObjectId.GenerateNewId().ToString(),
                ExpiresIn = expressSeconds,
                Appid     = appId,
                Id        = Guid.NewGuid()
            };
            await codeCol.Indexes.CreateOneAsync(new BsonDocumentIndexKeysDefinition <CodeModel>(model.ToBsonDocument()),
                                                 new CreateIndexOptions { ExpireAfter = TimeSpan.FromSeconds(expressSeconds) });

            return(model.Code);
        }