Permalink
Browse files

Merge remote branch 'upstream/master'

  • Loading branch information...
2 parents 799ba8a + b8cac16 commit 6b1ac815ada32dfd825406389155ce6c232e66b3 @ekryski ekryski committed Mar 31, 2011
@@ -19,6 +19,7 @@ FollowIssue.followIssue = function(req, res)
{
dbAccess.create('follows', { values:['user_id=' + user_id, 'issue_id=' + issue_id]}, function(){});
}
+ redirectTo(res, '/viewIssue?id='+issue_id);
});
}
});
@@ -34,7 +35,9 @@ FollowIssue.unfollowIssue = function(req, res)
var issue_id = parsedURL.query.id;
var user_id = user.id;
console.log(user_id + " " + issue_id);
- dbAccess.remove('follows', { conditions:['user_id=' + user_id, 'issue_id=' + issue_id]}, function(){});
+ dbAccess.remove('follows', { conditions:['user_id=' + user_id, 'issue_id=' + issue_id]}, function(){
+ redirectTo(res, '/viewIssue?id='+issue_id);
+ });
}
});
}
@@ -45,6 +45,8 @@ exports.signin = function(req, res) {
res.setHeader('Set-Cookie', 'session=' + sessionString + '; Expires=' + date);
redirectTo(res, '/'); // redirect to index.
});
+ /* Note: there is a code duplicate of session generation in the signup module.
+ * Changes to this section should be reflected there, or a new issue created. */
} else {
res.render(view, {error: 'Sign In Failed. Please try again.'});
@@ -1,23 +1,4 @@
/*
- * Module for new user signup
- *
- * Created By: Jonathan Moore, Corliss Fung, Nasrullah Taha
- */
-
-var dbAccess = require('dbAccess'),
- qs = require('querystring'),
- crypto = require('crypto'),
- reputation = require('reputation'),
- util = require('util'),
- user = require('user');
-
-var SignupModule = exports.SignupModule = function() {
- this.username;
- this.email;
- this.password;
-};
-
-/*
* Module for new user signup
*
* Created By: Jonathan Moore, Corliss Fung, Nasrullah Taha
@@ -92,18 +73,41 @@ SignupModule.handleSignup = function(req, res)
// On success, redirect user to Welcome page.
reputation.updateOnSignUp(username, email);
// Find id of newly created user - note: without UNIQUE constraint, this may return multiple users but will lock on to first, security hole.
- dbAccess.find('users', { conditions:['name="' + username + '"']}, function(error, records){
+ user.authenticate(username, password, function (error, user){
if (error) throw error;
- if (records) {
- console.log("User '" + username + "' was successfully created, id = " + records[0].id);
- res.setHeader('set-cookie', 'session=' + records[0].id);
- redirectTo(res, '/signupSuccess.html');
- }
- }); // end dbAccess.find()
+ if (user) {
+ console.log("User '" + username + "' was successfully created, id = " + user.id);
+
+ //cookie session expiration date
+ var date = new Date();
+ date.setDate(date.getDate() + 7);
+
+ // This generates a unique session and then assigns it to
+ // the user cookie and inserts it in the sessions table.
+ var sessionString = generateHash(user.id);
+ var query = "INSERT INTO sessions (user_id, session_hash) VALUES ('" + user.id + "','" + sessionString + "');";
+
+ dbAccess.runQuery(query, function(error){
+ //res.render('public/signupSuccess.html', {uname: username} );
+ res.setHeader('Set-Cookie', 'session=' + sessionString + '; Expires=' + date);
+ redirectTo(res, '/signupSuccess.html'); // redirect to index.
+ });
+
+ } else {
+ res.render(view, {error: 'Signup Failed. Please try again.'});
+ }
+ }); // end dbAccess.find()
}
}); // end dbAccess.runQuery()
}
}); // end dbAccess.find()
}); // end req.on()
};
+
+function generateHash(id) {
+ var timestamp = new Date().getTime();
+ var toHash = (timestamp+id).toString();
+ return user.md5hash(toHash);
+}
+
@@ -79,6 +79,7 @@ function displayPage(response, issue) {
}
}
getStats(thisIssueId, function(issueStats){
+ getFollow(g_UserId, thisIssueId, function(follows){
variables = {
found: true,
quickTaskButtons_partial: 'views/layouts/partials/quickTaskButtons_partial.html',
@@ -102,10 +103,11 @@ function displayPage(response, issue) {
lastModified: issue.lastModified,
numComments: issueStats[0],
numFollowers: issueStats[1],
- numViews: issueStats[2]
-
+ numViews: issueStats[2],
+ following: follows
}
response.render('views/viewIssue.html', variables);
+ });
}); // end of queries of issue stats
});
});
@@ -147,6 +149,15 @@ function getStats(thisIssueId, callback) {
}
+function getFollow(g_UserId, thisIssueID, callback){
+ var isfollowing;
+ var findFollowing = "SELECT * FROM (SELECT * FROM follows WHERE issue_id=" + thisIssueID + ") WHERE user_id=" + g_UserId;
+ //console.log(findFollowing);
+ dbAccess.runQuery(findFollowing, function(error, follows){
+ if(error) throw error;
+ if(callback instanceof Function) { callback(follows); }
+ });
+}
ViewIssue.addcomments = function (req,res) {
var requestString = "";
@@ -9,8 +9,8 @@
<body>
<div id="page">
<div id="header">
- <a href="signup">join</a> |
- <a href="signin">login</a>
+ Welcome, please <a href="/viewProfile"> edit your profile</a> |
+ <a href="/signout">logout</a>
</div>
<div id="menu">
View
@@ -33,9 +33,22 @@
{{/file_link}}
<p>More information: <a href="{{link}}"> here </a></p>
{{^user}}
- <p><em><a href='/signin'>Sign in</a> to vote on issues.</em></p>
+ <p><em><a href='/signin'>Sign in</a> to follow or vote on this issues.</em></p>
{{/user}}
{{#user}}
+ {{#following}}
+ <p>
+ You are following this issue.
+ </p>
+ <p>
+ Click <a href="/unfollowIssue?id={{issue_id}}">here</a> to stop following this issue.
+ </p>
+ {{/following}}
+ {{^following}}
+ <p>
+ <a href="/followIssue?id={{issue_id}}">Follow</a> this issue
+ </p>
+ {{/following}}
{{^userHasVoted}}
<p>
<table style="width: 100%">

0 comments on commit 6b1ac81

Please sign in to comment.