{"action":"created","comment":{"url":"https://api.github.com/repos/andela-skieha/document-management-system/pulls/comments/79771272","id":79771272,"diff_hunk":"@@ -0,0 +1,89 @@\n+/* eslint-disable no-underscore-dangle */\n+/* eslint-disable no-param-reassign */\n+\n+const jwt = require('jsonwebtoken');\n+const bcrypt = require('bcrypt-nodejs');\n+const User = require('../models/user');\n+const users = require('./users');\n+const documents = require('./documents');\n+const roles = require('./roles');\n+const config = require('../config');\n+\n+module.exports = (apiRouter) => {\n+  apiRouter.post('/users/signup', (req, res) => {\n+    const user = new User();\n+    user.username = req.body.username;\n+    user.name = { firstname: req.body.firstname, lastname: req.body.lastname };\n+    user.email = req.body.email;\n+    user.password = req.body.password;\n+\n+    user.save((err) => {\n+      if (err) {\n+        if (err.code === 11000) {\n+          res.status(409).send({ message: 'Duplicate user entry.' });\n+        } else {\n+          res.status(400).send({ message: 'Error creating user.' });\n+        }\n+      } else {\n+        res.status(201).send({\n+          message: 'User created successfully.',\n+          user,\n+        });\n+      }\n+    });\n+  });\n+\n+  apiRouter.post('/users/login', (req, res) => {\n+    User.findOne({\n+      username: req.body.username,\n+    })\n+   .select('username password')\n+   .exec((err, user) => {\n+     if (err) throw err;\n+\n+     if (!user) {\n+       res.status(404).send({ error: 'User not found.' });\n+     } else if (user) {\n+       bcrypt.compare(req.body.password, user.password, (error, result) => {\n+         if (result !== true) {\n+           res.status(403).send({ error: 'Wrong password supplied' });\n+         } else {\n+           const userData = {\n+             _id: user._id,\n+             email: user.email,\n+           };\n+           const dmsToken = jwt.sign(userData, config.secret, { expiresIn: 86400 });\n+\n+           res.status(200).send({\n+             message: 'User logged in',\n+             token: dmsToken,\n+             user_id: user._id,\n+           });\n+         }\n+       });\n+     }\n+   });\n+  });\n+\n+  apiRouter.use((req, res, next) => {\n+    const dmsToken = req.body.dmsToken || req.query.dmsToken || req.headers['x-access-token'];\n+    if (dmsToken) {\n+      jwt.verify(dmsToken, config.secret, (err, decoded) => {","path":"server/routes/index.js","position":71,"original_position":71,"commit_id":"957da2c9e376e1ac42bd74e9ab9691e12cd6f871","original_commit_id":"957da2c9e376e1ac42bd74e9ab9691e12cd6f871","user":{"login":"houndci-bot","id":6697940,"avatar_url":"https://avatars.githubusercontent.com/u/6697940?v=3","gravatar_id":"","url":"https://api.github.com/users/houndci-bot","html_url":"https://github.com/houndci-bot","followers_url":"https://api.github.com/users/houndci-bot/followers","following_url":"https://api.github.com/users/houndci-bot/following{/other_user}","gists_url":"https://api.github.com/users/houndci-bot/gists{/gist_id}","starred_url":"https://api.github.com/users/houndci-bot/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/houndci-bot/subscriptions","organizations_url":"https://api.github.com/users/houndci-bot/orgs","repos_url":"https://api.github.com/users/houndci-bot/repos","events_url":"https://api.github.com/users/houndci-bot/events{/privacy}","received_events_url":"https://api.github.com/users/houndci-bot/received_events","type":"User","site_admin":false},"body":"'arrow function syntax (=>)' is only available in ES6 (use 'esversion: 6').","created_at":"2016-09-21T07:09:23Z","updated_at":"2016-09-21T07:09:23Z","html_url":"https://github.com/andela-skieha/document-management-system/pull/1#discussion_r79771272","pull_request_url":"https://api.github.com/repos/andela-skieha/document-management-system/pulls/1","_links":{"self":{"href":"https://api.github.com/repos/andela-skieha/document-management-system/pulls/comments/79771272"},"html":{"href":"https://github.com/andela-skieha/document-management-system/pull/1#discussion_r79771272"},"pull_request":{"href":"https://api.github.com/repos/andela-skieha/document-management-system/pulls/1"}}},"pull_request":{"url":"https://api.github.com/repos/andela-skieha/document-management-system/pulls/1","id":86062587,"html_url":"https://github.com/andela-skieha/document-management-system/pull/1","diff_url":"https://github.com/andela-skieha/document-management-system/pull/1.diff","patch_url":"https://github.com/andela-skieha/document-management-system/pull/1.patch","issue_url":"https://api.github.com/repos/andela-skieha/document-management-system/issues/1","number":1,"state":"open","locked":false,"title":"Develop","user":{"login":"andela-skieha","id":19430095,"avatar_url":"https://avatars.githubusercontent.com/u/19430095?v=3","gravatar_id":"","url":"https://api.github.com/users/andela-skieha","html_url":"https://github.com/andela-skieha","followers_url":"https://api.github.com/users/andela-skieha/followers","following_url":"https://api.github.com/users/andela-skieha/following{/other_user}","gists_url":"https://api.github.com/users/andela-skieha/gists{/gist_id}","starred_url":"https://api.github.com/users/andela-skieha/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andela-skieha/subscriptions","organizations_url":"https://api.github.com/users/andela-skieha/orgs","repos_url":"https://api.github.com/users/andela-skieha/repos","events_url":"https://api.github.com/users/andela-skieha/events{/privacy}","received_events_url":"https://api.github.com/users/andela-skieha/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-09-20T21:47:29Z","updated_at":"2016-09-21T07:09:23Z","closed_at":null,"merged_at":null,"merge_commit_sha":null,"assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/andela-skieha/document-management-system/pulls/1/commits","review_comments_url":"https://api.github.com/repos/andela-skieha/document-management-system/pulls/1/comments","review_comment_url":"https://api.github.com/repos/andela-skieha/document-management-system/pulls/comments{/number}","comments_url":"https://api.github.com/repos/andela-skieha/document-management-system/issues/1/comments","statuses_url":"https://api.github.com/repos/andela-skieha/document-management-system/statuses/957da2c9e376e1ac42bd74e9ab9691e12cd6f871","head":{"label":"andela-skieha:develop","ref":"develop","sha":"957da2c9e376e1ac42bd74e9ab9691e12cd6f871","user":{"login":"andela-skieha","id":19430095,"avatar_url":"https://avatars.githubusercontent.com/u/19430095?v=3","gravatar_id":"","url":"https://api.github.com/users/andela-skieha","html_url":"https://github.com/andela-skieha","followers_url":"https://api.github.com/users/andela-skieha/followers","following_url":"https://api.github.com/users/andela-skieha/following{/other_user}","gists_url":"https://api.github.com/users/andela-skieha/gists{/gist_id}","starred_url":"https://api.github.com/users/andela-skieha/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andela-skieha/subscriptions","organizations_url":"https://api.github.com/users/andela-skieha/orgs","repos_url":"https://api.github.com/users/andela-skieha/repos","events_url":"https://api.github.com/users/andela-skieha/events{/privacy}","received_events_url":"https://api.github.com/users/andela-skieha/received_events","type":"User","site_admin":false},"repo":{"id":65121949,"name":"document-management-system","full_name":"andela-skieha/document-management-system","owner":{"login":"andela-skieha","id":19430095,"avatar_url":"https://avatars.githubusercontent.com/u/19430095?v=3","gravatar_id":"","url":"https://api.github.com/users/andela-skieha","html_url":"https://github.com/andela-skieha","followers_url":"https://api.github.com/users/andela-skieha/followers","following_url":"https://api.github.com/users/andela-skieha/following{/other_user}","gists_url":"https://api.github.com/users/andela-skieha/gists{/gist_id}","starred_url":"https://api.github.com/users/andela-skieha/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andela-skieha/subscriptions","organizations_url":"https://api.github.com/users/andela-skieha/orgs","repos_url":"https://api.github.com/users/andela-skieha/repos","events_url":"https://api.github.com/users/andela-skieha/events{/privacy}","received_events_url":"https://api.github.com/users/andela-skieha/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/andela-skieha/document-management-system","description":null,"fork":false,"url":"https://api.github.com/repos/andela-skieha/document-management-system","forks_url":"https://api.github.com/repos/andela-skieha/document-management-system/forks","keys_url":"https://api.github.com/repos/andela-skieha/document-management-system/keys{/key_id}","collaborators_url":"https://api.github.com/repos/andela-skieha/document-management-system/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/andela-skieha/document-management-system/teams","hooks_url":"https://api.github.com/repos/andela-skieha/document-management-system/hooks","issue_events_url":"https://api.github.com/repos/andela-skieha/document-management-system/issues/events{/number}","events_url":"https://api.github.com/repos/andela-skieha/document-management-system/events","assignees_url":"https://api.github.com/repos/andela-skieha/document-management-system/assignees{/user}","branches_url":"https://api.github.com/repos/andela-skieha/document-management-system/branches{/branch}","tags_url":"https://api.github.com/repos/andela-skieha/document-management-system/tags","blobs_url":"https://api.github.com/repos/andela-skieha/document-management-system/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/andela-skieha/document-management-system/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/andela-skieha/document-management-system/git/refs{/sha}","trees_url":"https://api.github.com/repos/andela-skieha/document-management-system/git/trees{/sha}","statuses_url":"https://api.github.com/repos/andela-skieha/document-management-system/statuses/{sha}","languages_url":"https://api.github.com/repos/andela-skieha/document-management-system/languages","stargazers_url":"https://api.github.com/repos/andela-skieha/document-management-system/stargazers","contributors_url":"https://api.github.com/repos/andela-skieha/document-management-system/contributors","subscribers_url":"https://api.github.com/repos/andela-skieha/document-management-system/subscribers","subscription_url":"https://api.github.com/repos/andela-skieha/document-management-system/subscription","commits_url":"https://api.github.com/repos/andela-skieha/document-management-system/commits{/sha}","git_commits_url":"https://api.github.com/repos/andela-skieha/document-management-system/git/commits{/sha}","comments_url":"https://api.github.com/repos/andela-skieha/document-management-system/comments{/number}","issue_comment_url":"https://api.github.com/repos/andela-skieha/document-management-system/issues/comments{/number}","contents_url":"https://api.github.com/repos/andela-skieha/document-management-system/contents/{+path}","compare_url":"https://api.github.com/repos/andela-skieha/document-management-system/compare/{base}...{head}","merges_url":"https://api.github.com/repos/andela-skieha/document-management-system/merges","archive_url":"https://api.github.com/repos/andela-skieha/document-management-system/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/andela-skieha/document-management-system/downloads","issues_url":"https://api.github.com/repos/andela-skieha/document-management-system/issues{/number}","pulls_url":"https://api.github.com/repos/andela-skieha/document-management-system/pulls{/number}","milestones_url":"https://api.github.com/repos/andela-skieha/document-management-system/milestones{/number}","notifications_url":"https://api.github.com/repos/andela-skieha/document-management-system/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/andela-skieha/document-management-system/labels{/name}","releases_url":"https://api.github.com/repos/andela-skieha/document-management-system/releases{/id}","deployments_url":"https://api.github.com/repos/andela-skieha/document-management-system/deployments","created_at":"2016-08-07T07:46:06Z","updated_at":"2016-08-18T08:59:55Z","pushed_at":"2016-09-21T07:09:11Z","git_url":"git://github.com/andela-skieha/document-management-system.git","ssh_url":"git@github.com:andela-skieha/document-management-system.git","clone_url":"https://github.com/andela-skieha/document-management-system.git","svn_url":"https://github.com/andela-skieha/document-management-system","homepage":null,"size":73,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"andela-skieha:master","ref":"master","sha":"e863b8c3b64f705ac40f5b105ab893a23d848eca","user":{"login":"andela-skieha","id":19430095,"avatar_url":"https://avatars.githubusercontent.com/u/19430095?v=3","gravatar_id":"","url":"https://api.github.com/users/andela-skieha","html_url":"https://github.com/andela-skieha","followers_url":"https://api.github.com/users/andela-skieha/followers","following_url":"https://api.github.com/users/andela-skieha/following{/other_user}","gists_url":"https://api.github.com/users/andela-skieha/gists{/gist_id}","starred_url":"https://api.github.com/users/andela-skieha/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andela-skieha/subscriptions","organizations_url":"https://api.github.com/users/andela-skieha/orgs","repos_url":"https://api.github.com/users/andela-skieha/repos","events_url":"https://api.github.com/users/andela-skieha/events{/privacy}","received_events_url":"https://api.github.com/users/andela-skieha/received_events","type":"User","site_admin":false},"repo":{"id":65121949,"name":"document-management-system","full_name":"andela-skieha/document-management-system","owner":{"login":"andela-skieha","id":19430095,"avatar_url":"https://avatars.githubusercontent.com/u/19430095?v=3","gravatar_id":"","url":"https://api.github.com/users/andela-skieha","html_url":"https://github.com/andela-skieha","followers_url":"https://api.github.com/users/andela-skieha/followers","following_url":"https://api.github.com/users/andela-skieha/following{/other_user}","gists_url":"https://api.github.com/users/andela-skieha/gists{/gist_id}","starred_url":"https://api.github.com/users/andela-skieha/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/andela-skieha/subscriptions","organizations_url":"https://api.github.com/users/andela-skieha/orgs","repos_url":"https://api.github.com/users/andela-skieha/repos","events_url":"https://api.github.com/users/andela-skieha/events{/privacy}","received_events_url":"https://api.github.com/users/andela-skieha/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/andela-skieha/document-management-system","description":null,"fork":false,"url":"https://api.github.com/repos/andela-skieha/document-management-system","forks_url":"https://api.github.com/repos/andela-skieha/document-management-system/forks","keys_url":"https://api.github.com/repos/andela-skieha/document-management-system/keys{/key_id}","collaborators_url":"https://api.github.com/repos/andela-skieha/document-management-system/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/andela-skieha/document-management-system/teams","hooks_url":"https://api.github.com/repos/andela-skieha/document-management-system/hooks","issue_events_url":"https://api.github.com/repos/andela-skieha/document-management-system/issues/events{/number}","events_url":"https://api.github.com/repos/andela-skieha/document-management-system/events","assignees_url":"https://api.github.com/repos/andela-skieha/document-management-system/assignees{/user}","branches_url":"https://api.github.com/repos/andela-skieha/document-management-system/branches{/branch}","tags_url":"https://api.github.com/repos/andela-skieha/document-management-system/tags","blobs_url":"https://api.github.com/repos/andela-skieha/document-management-system/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/andela-skieha/document-management-system/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/andela-skieha/document-management-system/git/refs{/sha}","trees_url":"https://api.github.com/repos/andela-skieha/document-management-system/git/trees{/sha}","statuses_url":"https://api.github.com/repos/andela-skieha/document-management-system/statuses/{sha}","languages_url":"https://api.github.com/repos/andela-skieha/document-management-system/languages","stargazers_url":"https://api.github.com/repos/andela-skieha/document-management-system/stargazers","contributors_url":"https://api.github.com/repos/andela-skieha/document-management-system/contributors","subscribers_url":"https://api.github.com/repos/andela-skieha/document-management-system/subscribers","subscription_url":"https://api.github.com/repos/andela-skieha/document-management-system/subscription","commits_url":"https://api.github.com/repos/andela-skieha/document-management-system/commits{/sha}","git_commits_url":"https://api.github.com/repos/andela-skieha/document-management-system/git/commits{/sha}","comments_url":"https://api.github.com/repos/andela-skieha/document-management-system/comments{/number}","issue_comment_url":"https://api.github.com/repos/andela-skieha/document-management-system/issues/comments{/number}","contents_url":"https://api.github.com/repos/andela-skieha/document-management-system/contents/{+path}","compare_url":"https://api.github.com/repos/andela-skieha/document-management-system/compare/{base}...{head}","merges_url":"https://api.github.com/repos/andela-skieha/document-management-system/merges","archive_url":"https://api.github.com/repos/andela-skieha/document-management-system/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/andela-skieha/document-management-system/downloads","issues_url":"https://api.github.com/repos/andela-skieha/document-management-system/issues{/number}","pulls_url":"https://api.github.com/repos/andela-skieha/document-management-system/pulls{/number}","milestones_url":"https://api.github.com/repos/andela-skieha/document-management-system/milestones{/number}","notifications_url":"https://api.github.com/repos/andela-skieha/document-management-system/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/andela-skieha/document-management-system/labels{/name}","releases_url":"https://api.github.com/repos/andela-skieha/document-management-system/releases{/id}","deployments_url":"https://api.github.com/repos/andela-skieha/document-management-system/deployments","created_at":"2016-08-07T07:46:06Z","updated_at":"2016-08-18T08:59:55Z","pushed_at":"2016-09-21T07:09:11Z","git_url":"git://github.com/andela-skieha/document-management-system.git","ssh_url":"git@github.com:andela-skieha/document-management-system.git","clone_url":"https://github.com/andela-skieha/document-management-system.git","svn_url":"https://github.com/andela-skieha/document-management-system","homepage":null,"size":73,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/andela-skieha/document-management-system/pulls/1"},"html":{"href":"https://github.com/andela-skieha/document-management-system/pull/1"},"issue":{"href":"https://api.github.com/repos/andela-skieha/document-management-system/issues/1"},"comments":{"href":"https://api.github.com/repos/andela-skieha/document-management-system/issues/1/comments"},"review_comments":{"href":"https://api.github.com/repos/andela-skieha/document-management-system/pulls/1/comments"},"review_comment":{"href":"https://api.github.com/repos/andela-skieha/document-management-system/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/andela-skieha/document-management-system/pulls/1/commits"},"statuses":{"href":"https://api.github.com/repos/andela-skieha/document-management-system/statuses/957da2c9e376e1ac42bd74e9ab9691e12cd6f871"}}}}
{"actor":{"display_login":"houndci-bot"}}