public async Task SetSecretAsync(ObjectId id, SecretDoc secret, CancellationToken cancellationToken) { var update = Builders <UserDoc> .Update .Set(doc => doc.Secret, secret) .Set(doc => doc.PasswordToken, null); await UpdateAsync(id, update, cancellationToken); }
public async Task <bool> TryAddSecretAsync(ObjectId id, SecretDoc secret, CancellationToken cancellationToken) { var update = Builders <UserDoc> .Update .Set(doc => doc.Secret, secret) .Set(doc => doc.PasswordToken, null); var result = await Collection.UpdateOneAsync( doc => doc.Id == id && doc.Secret == null, update, cancellationToken : cancellationToken); return(result.MatchedCount == 1); }
public static Secret ToModel(this SecretDoc doc) { if (doc is null) { throw new ArgumentNullException(nameof(doc)); } return(new Secret ( hash: doc.Hash, salt: doc.Salt )); }