зеркало из https://github.com/mozilla/CSOL-site.git
Badge awarding
This commit is contained in:
Родитель
0086d01eee
Коммит
afcb9b6145
21
aestimia.js
21
aestimia.js
|
@ -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;
|
||||
|
|
Загрузка…
Ссылка в новой задаче