Skip to content

Commit a9c79e7

Browse files
committed
store user
1 parent f1cba6e commit a9c79e7

File tree

4 files changed

+44
-7
lines changed

4 files changed

+44
-7
lines changed

app.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ passport.deserializeUser(function(id, done) {
6262
passport.use(new LocalStrategy(
6363
function(username, password, done) {
6464
// Find the user from your DB (MongoDB, CouchDB, other...)
65-
console.log('login with ', username, password);
6665
done(null, username);
6766
}
6867
));
@@ -92,7 +91,7 @@ app.get('/topic_hint', routes.topic_hint);
9291
app.get('/auth',
9392
passport.authenticate('local', {failureRedirect: '/login'}),
9493
function(req, res) {
95-
res.redirect('/');
94+
res.redirect('/profile/'+req.user);
9695
}
9796
);
9897

routes/index.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,19 @@ exports.login = function(req, res){
7575

7676
exports.postLogin = function(req, res){
7777
console.log(req.body);
78-
79-
res.redirect('/auth?username='+req.body.username+'&password='+req.body.password);
78+
modelProvider.findUserByName(req.body.name, function (err,result){
79+
if(err == null && result == null)
80+
{
81+
var user ={
82+
name:req.body.username,
83+
email:"admin@test.com"
84+
}
85+
modelProvider.createUser(user,function(err,result){
86+
res.redirect('/auth?username='+req.body.username+'&password='+req.body.password);
87+
});
88+
}
89+
})
90+
8091
};
8192

8293

routes/tutorial.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,11 @@ exports.postNewTutorial = function(req, res){
8282
};
8383

8484
exports.postTutorialComment = function(req, res){
85-
85+
console.log("user name " +req.user);
86+
if(req.user != undefined)
87+
{
88+
89+
}
8690
var comment = req.body.comment;
8791
var tutorialId = req.params.tid;
8892
console.log("comment " + comment + " tutorial id " +tutorialId);

routes/user.js

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,29 @@
44
*/
55

66
exports.profile = function(req, res){
7-
console.log(req.params);
8-
res.send("respond with a resource");
7+
var uid = req.params.uid;
8+
var user = {
9+
id : uid,
10+
name : uid,
11+
about: "I am a programmer",
12+
stat: {
13+
friends: 19,
14+
paths : 3,
15+
tutorials : 45
16+
},
17+
skills : ["javascript","javascript-basic","nodejs","nodejs-intermediate","expressjs-basic","openVC-basic","objectiveC-basic"],
18+
completedPaths : [
19+
{ name :"basic javascript" , url : "http://google.com"},
20+
{ name :"basic javascript" , url : "http://google.com"},
21+
{ name :"basic javascript" , url : "http://google.com"}
22+
],
23+
completedTutorials: [
24+
{ name :"basic javascript" , url : "http://google.com"},
25+
{ name :"basic javascript" , url : "http://google.com"},
26+
{ name :"basic javascript" , url : "http://google.com"},
27+
{ name :"basic javascript" , url : "http://google.com"},
28+
{ name :"basic javascript" , url : "http://google.com"}
29+
]
30+
}
31+
res.render('profile', {user: user});
932
};

0 commit comments

Comments
 (0)