Skip to content
This repository was archived by the owner on Feb 12, 2026. It is now read-only.

Commit 226b82b

Browse files
authored
Merge pull request #3 from SpringRole/DM-1
added new function and update read me
2 parents a9693bd + 94d5fa1 commit 226b82b

2 files changed

Lines changed: 96 additions & 19 deletions

File tree

README.md

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,21 @@
11
# domain-verification
2-
Verify domain ownsership, currently supports 3 methods:
2+
This module help you to verify domain ownership.
33

4-
## 1. htmlVerification:
4+
## Install
5+
6+
$ npm install domain-verification
7+
8+
## Usage
9+
10+
consta domainVerification = require('domain-verification');
11+
domainVerification.html(domain_url,domain_html_name,hash_value);
12+
domainVerification.txt(domain_url,domain_key,domain_value);
13+
domainVerification.metatag(domain_url,domain_key,domain_value);
14+
domainVerification.all(domain_url,domain_key,domain_value,domain_html_name,hash_value);
15+
16+
We are supporting Promise.
17+
18+
## 1. html:
519

620
Verify by uploading a specific HTML to a given domain.
721

@@ -14,18 +28,22 @@ Verify domain ownsership, currently supports 3 methods:
1428
* The domain to be verified has the HTML file specified in the url specified by 'domain_url'.
1529
* The filename is of the form: 'domain_html_name'.html, eg. 'domainVerified-1233ask.html'
1630

17-
## 2. txtVerification:
31+
## 2. txt:
1832
Verify by Txt in the DNS of the domain:
1933

20-
### Parameters:
34+
### Parameters:
2135
* domain_url: The URL of the domain that has the Txt file added
2236
* domain_key: The Txt key
2337
* domain_value: The Txt value
2438

25-
## 3. metaTagVerification:
39+
## 3. metatag:
2640
Verify by metatag information of a domain:
2741

2842
### Parameters:
2943
* domain_url: The URL of the domain containing the metatag
3044
* domain_key: The meta tag key/name
31-
* domain_value: The value of the meta tag key/name
45+
* domain_value: The value of the meta tag key/name
46+
47+
## 3. all:
48+
This methods call all the above 3 function and give you the result:
49+

index.js

Lines changed: 72 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ var DomainVerification = (function() {
1111
var htmlVerification = function(domain_url,domain_html_name,hash_value) {
1212
var original_args = arguments;
1313
return new Promise(function(resolve,reject){
14-
if(original_args.length == 4)
14+
if(original_args.length == 3)
1515
{
16+
var obj = {};
17+
obj.verified = "Html Verification";
1618
var url = domain_url+'/'+domain_html_name+'.html';
1719
var options = {
1820
method: 'GET',
@@ -21,13 +23,16 @@ var DomainVerification = (function() {
2123
request(options,function(error,response,body){
2224
if(error)
2325
{
24-
resolve(false);
26+
obj.status = false;
27+
resolve(obj);
2528
} else {
2629
if(hash_value == body)
2730
{
28-
resolve(true);
31+
obj.status = true;
32+
resolve(obj);
2933
} else {
30-
resolve(false);
34+
obj.status = false;
35+
resolve(obj);
3136
}
3237
}
3338
});
@@ -41,19 +46,24 @@ var DomainVerification = (function() {
4146
var original_args = arguments;
4247
return new Promise(function (resolve,reject){
4348
if(original_args.length == 3){
49+
var obj = {};
50+
obj.verified = "Txt Verification";
4451
dns.resolveTxt(domain_url, function(error,records){
4552
if(records == undefined)
4653
{
47-
resolve(false);
54+
obj.status = false;
55+
resolve(obj);
4856
} else {
4957
records.forEach(function(record){
5058
var expected = domain_key+'='+domain_value;
5159
if(expected == record[0])
5260
{
53-
resolve(true);
61+
obj.status = true;
62+
resolve(obj);
5463
}
5564
else {
56-
resolve(false);
65+
obj.status = false;
66+
resolve(obj);
5767
}
5868
});
5969
}
@@ -68,37 +78,86 @@ var DomainVerification = (function() {
6878
var metaTagVerification = function(domain_url,domain_key,domain_value) {
6979
var original_args = arguments;
7080
return new Promise(function(resolve,reject){
81+
var obj = {};
82+
obj.verified = "Meta tag Verification";
83+
7184
if(original_args.length == 3)
7285
{
7386
metafetch.fetch(domain_url,function(err,result){
7487
if(err)
7588
{
76-
resolve(false);
89+
obj.status = false;
90+
resolve(obj);
7791
} else {
7892
var check_key = result.meta[domain_key];
7993
if( check_key != undefined)
8094
{
8195
if(check_key === domain_value)
8296
{
83-
resolve(true);
97+
obj.status = true;
98+
resolve(obj);
8499
} else {
85-
resolve(false);
100+
obj.status = false;
101+
resolve(obj);
86102
}
87103
} else {
88-
resolve(false);
104+
obj.status = false;
105+
resolve(obj);
89106
}
90107
}
91108
});
92109
} else {
93110
reject('Mismatch arguments');
94111
}
95112
});
96-
}
113+
};
114+
115+
var verifyAll = function(domain_url,domain_key,domain_value,domain_html_name,hash_value)
116+
{
117+
var original_args = arguments;
118+
return new Promise(function(resolve,reject){
119+
var obj = {};
120+
var success = [];
121+
var failure = [];
122+
if(original_args.length == 5)
123+
{
124+
Promise.all([
125+
htmlVerification(domain_url,domain_html_name,hash_value),
126+
txtVerification(domain_url,domain_key,domain_value),
127+
metaTagVerification(domain_url,domain_key,domain_value)
128+
]).then(results_data =>{
129+
results_data.forEach( data=>{
130+
if(data.status)
131+
{
132+
success.push(data.name);
133+
} else {
134+
failure.push(data.name);
135+
}
136+
});
137+
if(success.length > 0)
138+
{
139+
obj.status = true;
140+
obj.verified = success;
141+
} else {
142+
obj.status = false;
143+
obj.verified = [];
144+
}
145+
resolve(obj);
146+
}).catch( error =>{
147+
reject(error);
148+
});
149+
} else {
150+
reject('Mismatch arguments');
151+
}
152+
});
153+
};
154+
97155

98156
return {
99157
html: htmlVerification,
100158
txt: txtVerification,
101-
metatag: metaTagVerification
159+
metatag: metaTagVerification,
160+
all:verifyAll
102161
};
103162

104163
})();

0 commit comments

Comments
 (0)