forked from fossasia/yaydoc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes fossasia#342: adding support for sending notification if access…
… token revoked
- Loading branch information
Showing
8 changed files
with
158 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,3 +77,24 @@ exports.sendMailOnBuild = function (buildStatus, email, repository) { | |
} | ||
}); | ||
}; | ||
|
||
exports.sendMailOnTokenFailure = function (email) { | ||
var client = nodemailer.createTransport(sgTransport(options)); | ||
|
||
var textContent = 'Access token for Yaydoc is expired. Sign in once again to continue the service'; | ||
var htmlContent = 'Access token for Yaydoc is expired. Sign in once again to continue the service'; | ||
|
||
client.sendMail({ | ||
from: '[email protected]', | ||
to: email, | ||
subject: 'Token expired - Yaydoc', | ||
text: textContent, | ||
html: htmlContent | ||
}, function (error, info) { | ||
if (error) { | ||
console.log(error); | ||
} else { | ||
console.log('Message sent: ' + info.response); | ||
} | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
const github = require("./github.js"); | ||
const mailer = require("./mailer"); | ||
const async = require("async"); | ||
User = require("../model/user"); | ||
var tokenRevokedQueue = async.queue(function (user, done) { | ||
github.retriveUser(user.token, function (error, userData) { | ||
if (error) { | ||
if (user.expired === false) { | ||
mailer.sendMailOnTokenFailure(user.email); | ||
User.updateUserById(user.id, { | ||
expired: true | ||
}, function(error, data) { | ||
if (error) { | ||
console.log(error); | ||
} | ||
}); | ||
} | ||
done(); | ||
} else { | ||
done(); | ||
} | ||
}) | ||
}, 2); | ||
|
||
exports.addTokenRevokedJob = function(user) { | ||
tokenRevokedQueue.push(user); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
const github = require("./github") | ||
const queue = require("./queue") | ||
|
||
User = require("../model/user"); | ||
|
||
exports.checkExpiredToken = function () { | ||
User.count(function (error, count) { | ||
if (error) { | ||
console.log(error); | ||
} else { | ||
var page = 0; | ||
if (count < 10) { | ||
page = 1; | ||
} else { | ||
page = count / 10; | ||
if (page * 10 < count) { | ||
page = (count + 10) /10; | ||
} | ||
} | ||
for (var i = 0; i <= page; i++) { | ||
User.paginateUsers(i, 10, | ||
function (error, users) { | ||
if (error) { | ||
console.log(error); | ||
} else { | ||
users.forEach(function(user) { | ||
queue.addTokenRevokedJob(user); | ||
}) | ||
} | ||
}) | ||
} | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters