Permalink
Browse files

Claim code stuff is DONE (probably)

  • Loading branch information...
1 parent 09a6ed7 commit 8e7ab85cfd5348bbd39f7903bfbea960ba648766 @brianloveswords brianloveswords committed Nov 7, 2012
Showing with 16 additions and 6 deletions.
  1. +5 −1 public/js/claim-award.js
  2. +1 −0 routes/admin.js
  3. +8 −4 routes/badge.js
  4. +2 −1 tests/badge-model.test.js
View
@@ -23,7 +23,11 @@
var url;
getAssertion(email, function (err, data) {
if (err)
- return window.alert('there was an error trying to claim the badge :(');
+ return window.alert('There was an error trying to claim the badge');
+
+ if (data.status === 'already-claimed')
+ return window.alert('This badge has already been claimed by someone');
+
url = data.assertionUrl;
OpenBadges.issue([url]);
});
View
@@ -88,6 +88,7 @@ exports.confirmClaim = function confirmClaim(req, res) {
return res.render('public/confirm-claim.html', {
csrf: req.session._csrf,
code: req.body.code,
+ claim: req.claim,
badge: req.badge,
});
};
View
@@ -148,10 +148,12 @@ exports.releaseClaimCode = function releaseClaimCode(req, res, next) {
exports.awardToUser = function awardToUser(req, res, next) {
- var email = req.body.email;
- var code = req.body.code;
+ var form = req.body
+ var email = (form.email || '').trim();
+ var code = (form.code || '').trim();
var badge = req.badge;
- if (!badge.redeemClaimCode(code, email))
+ var couldClaim = badge.redeemClaimCode(code, email);
+ if (!couldClaim)
return res.send({ status: 'already-claimed' })
badge.awardOrFind(email, function (err, instance) {
if (err) return res.send({ status: 'error', error: err });
@@ -168,11 +170,13 @@ exports.awardToUser = function awardToUser(req, res, next) {
exports.findByClaimCode = function findByClaimCode(options) {
return function (req, res, next) {
var code = req.body.code;
- Badge.findByClaimCode(code, function (err, badge) {
+ var normalizedCode = code.trim().replace(/ /g, '-').toLowerCase();
+ Badge.findByClaimCode(normalizedCode, function (err, badge) {
if (err) return next(err);
if (!badge)
return res.redirect('/claim?code=' + code + '&missing=true');
req.badge = badge;
+ req.claim = badge.getClaimCode('normalizedCode');
return next();
});
}
@@ -281,10 +281,11 @@ test.applyFixtures(fixtures, function () {
});
});
- test('Badge#claimClaimCode', function (t) {
+ test('Badge#redeemClaimCode', function (t) {
const badge = fixtures['offline-badge'];
const code ='will-claim';
t.same(badge.redeemClaimCode(code, 'brian@example.org'), true);
+ t.same(badge.redeemClaimCode(code, 'brian@example.org'), true);
t.same(badge.redeemClaimCode(code, 'otherguy@example.org'), false);
t.end();
});

0 comments on commit 8e7ab85

Please sign in to comment.