Skip to content

Commit 8743e51

Browse files
committed
debug
1 parent 909bd95 commit 8743e51

File tree

3 files changed

+23
-18
lines changed

3 files changed

+23
-18
lines changed

app.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,11 @@ app.get('/', (req, res, next) => {
2929

3030
app.get('/application', (req, res, next) => {
3131
if (req.session.userId) {
32-
res.render('index', { title: 'Hey', message: 'Hello there!' })
32+
return res.render('index', {
33+
username: req.session.username,
34+
ltiConsumer: req.session.ltiConsumer,
35+
userId: req.session.userId
36+
})
3337
} else {
3438
next(new Error('Session invalid. Please login via LTI to use this application.'));
3539
}

lti/index.js

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -41,22 +41,23 @@ exports.handleLaunch = (req, res, next) => {
4141
const provider = new lti.Provider(consumerKey, consumerSecret, nonceStore, lti.HMAC_SHA1);
4242

4343
provider.valid_request(req, function(err, isValid) {
44-
if (err || !isValid) {
45-
return next(err || new Error('invalid lti'));
46-
}
47-
48-
let body = {};
49-
[
50-
'roles', 'admin', 'alumni', 'content_developer', 'guest', 'instructor',
51-
'manager', 'member', 'mentor', 'none', 'observer', 'other', 'prospective_student',
52-
'student', 'ta', 'launch_request', 'username', 'userId', 'mentor_user_ids',
53-
'context_id', 'context_label', 'context_title', 'body'
54-
].forEach(function(key) {
55-
body[key] = provider[key];
56-
});
57-
58-
59-
return res.status(200).json(body);
44+
if (err) {
45+
return next(err);
46+
}
47+
if (isValid) {
48+
req.session.regenerate(err => {
49+
if (err) next(err);
50+
51+
req.session.contextId = provider.context_id;
52+
req.session.userId = provider.userId;
53+
req.session.username = provider.username;
54+
req.session.ltiConsumer = provider.body.tool_consumer_instance_guid;
55+
56+
return res.redirect(301, '/application');
57+
});
58+
} else {
59+
return next(err);
60+
}
6061
});
6162
});
6263
};

views/index.pug

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ html(lang='en')
5353
body
5454
.container-narrow
5555
.jumbotron
56-
h1 Welcome to the example application, you are connected as #{user.name}
56+
h1 Welcome to the example application, you are connected as #{username}. You have come from #{ltiConsumer} where you userId is #{userId}.
5757
p.lead
5858
| The Bootstrap 2.3.2 examples translated into Pug and instantly ready to view with Express
5959
a.btn.btn-large.btn-success(href='https://github.com/timReynolds/pug-bootstrap-examples') Source on Github

0 commit comments

Comments
 (0)