This commit is contained in:
Andrew Hayward 2013-06-04 03:04:12 +01:00
Родитель 0086d01eee
Коммит afcb9b6145
2 изменённых файлов: 37 добавлений и 3 удалений

Просмотреть файл

@ -141,9 +141,24 @@ var aestimia = new Api(ENDPOINT, {
var state = satisfied ? 'accepted' : 'rejected';
if (state !== application.state) {
// TO DO - email applicant about change of application state
}
if (state !== application.state)
if (state === 'accepted')
application.getLearner()
.complete(function (err, learner) {
if (err || !learner) return;
openbadger.awardBadge({
email: learner.email,
badge: application.badgeId
}, function (err, assertionUrl) {
if (err)
return console.log(err); // Should probably log this
// TO DO - email applicant about change of application state
console.log('Badge awarded:', assetionUrl);
});
});
application.updateAttributes({
state: state,

Просмотреть файл

@ -306,6 +306,25 @@ var openbadger = new Api(ENDPOINT, {
});
},
awardBadge: function awardBadge (query, callback) {
var email = query.email || query.session.user.email;
var shortname = query.badge;
var params = {
auth: getJWTToken(email),
email: email
}
this.post('/user/badge/' + shortname, { form: params }, function(err, data) {
if (err)
return callback(err, data);
return callback(null, {
assetionUrl: data.url
});
});
},
getBadgeFromCode: function getBadgeFromCode (query, callback) {
var email = query.email;
var code = query.code;