{"action":"created","comment":{"url":"https://api.github.com/repos/atmiguel/cerealnotes/pulls/comments/173815762","pull_request_review_id":103064534,"id":173815762,"diff_hunk":"@@ -4,18 +4,67 @@ import (\n \t\"database/sql\"\n \t// Notice that we’re loading the driver anonymously, The driver registers itself as being available to the database/sql package.\n \t_ \"github.com/lib/pq\"\n+\t\"golang.org/x/crypto/bcrypt\"\n+\t\"log\"\n+\t\"time\"\n )\n \n-func Connect(dbUrl string) (*sql.DB, error) {\n-\tdb, err := sql.Open(\"postgres\", dbUrl)\n+var db *sql.DB\n+\n+func Connect(dbUrl string) error {\n+\tvar err error\n+\n+\tdb, err = sql.Open(\"postgres\", dbUrl)\n \tif err != nil {\n-\t\treturn nil, err\n+\t\treturn err\n \t}\n \n \t// Quickly test if the connection to the database worked.\n \tif err := db.Ping(); err != nil {\n-\t\treturn nil, err\n+\t\treturn err\n+\t}\n+\n+\treturn nil\n+}\n+\n+func CreateUser(displayName string, emailAddress string, password string) (int64, error) {\n+\n+\thashedPassword, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)\n+\tif err != nil {\n+\t\treturn -1, err\n+\t}\n+\n+\tsqlStatement := `\n+\t\tINSERT INTO users (display_name, email_address, password, creation_time) \n+\t\tVALUES ($1, $2, $3, $4) RETURNING id`\n+\n+\tvar id int64\n+\terr = db.QueryRow(sqlStatement, displayName, emailAddress, hashedPassword, time.Now().UTC()).Scan(&id)\n+\tif err != nil {\n+\t\treturn -1, err\n+\t}\n+\n+\tlog.Printf(\"created new user with id '%d'\", id)\n+\treturn id, nil\n+}\n+\n+func AuthenticateUser(emailAddress string, password string) (bool, error) {\n+\n+\tsqlStatement := `\n+\tSELECT password FROM users WHERE email_address = $1\n+\t`\n+\n+\t// TODO handle the scenario where there is nobody in the db\n+\tvar hashFromDatabase []byte\n+\terr := db.QueryRow(sqlStatement, emailAddress).Scan(&hashFromDatabase)\n+\tif err != nil {\n+\t\treturn false, err\n+\t}\n+\n+\t// Comparing the password with the hash","path":"databaseutil/databaseutil.go","position":65,"original_position":65,"commit_id":"fd5c5b74ad08f57fd2f01f3f6a84f5ce4df16f96","original_commit_id":"fd5c5b74ad08f57fd2f01f3f6a84f5ce4df16f96","user":{"login":"atmiguel","id":549631,"avatar_url":"https://avatars0.githubusercontent.com/u/549631?v=4","gravatar_id":"","url":"https://api.github.com/users/atmiguel","html_url":"https://github.com/atmiguel","followers_url":"https://api.github.com/users/atmiguel/followers","following_url":"https://api.github.com/users/atmiguel/following{/other_user}","gists_url":"https://api.github.com/users/atmiguel/gists{/gist_id}","starred_url":"https://api.github.com/users/atmiguel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/atmiguel/subscriptions","organizations_url":"https://api.github.com/users/atmiguel/orgs","repos_url":"https://api.github.com/users/atmiguel/repos","events_url":"https://api.github.com/users/atmiguel/events{/privacy}","received_events_url":"https://api.github.com/users/atmiguel/received_events","type":"User","site_admin":false},"body":"this comment seems unnecessary","created_at":"2018-03-12T14:29:50Z","updated_at":"2018-03-12T14:32:51Z","html_url":"https://github.com/atmiguel/cerealnotes/pull/7#discussion_r173815762","pull_request_url":"https://api.github.com/repos/atmiguel/cerealnotes/pulls/7","author_association":"OWNER","_links":{"self":{"href":"https://api.github.com/repos/atmiguel/cerealnotes/pulls/comments/173815762"},"html":{"href":"https://github.com/atmiguel/cerealnotes/pull/7#discussion_r173815762"},"pull_request":{"href":"https://api.github.com/repos/atmiguel/cerealnotes/pulls/7"}}},"pull_request":{"url":"https://api.github.com/repos/atmiguel/cerealnotes/pulls/7","id":174157742,"html_url":"https://github.com/atmiguel/cerealnotes/pull/7","diff_url":"https://github.com/atmiguel/cerealnotes/pull/7.diff","patch_url":"https://github.com/atmiguel/cerealnotes/pull/7.patch","issue_url":"https://api.github.com/repos/atmiguel/cerealnotes/issues/7","number":7,"state":"open","locked":false,"title":"Form interaction with DB","user":{"login":"zingales","id":796540,"avatar_url":"https://avatars3.githubusercontent.com/u/796540?v=4","gravatar_id":"","url":"https://api.github.com/users/zingales","html_url":"https://github.com/zingales","followers_url":"https://api.github.com/users/zingales/followers","following_url":"https://api.github.com/users/zingales/following{/other_user}","gists_url":"https://api.github.com/users/zingales/gists{/gist_id}","starred_url":"https://api.github.com/users/zingales/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zingales/subscriptions","organizations_url":"https://api.github.com/users/zingales/orgs","repos_url":"https://api.github.com/users/zingales/repos","events_url":"https://api.github.com/users/zingales/events{/privacy}","received_events_url":"https://api.github.com/users/zingales/received_events","type":"User","site_admin":false},"body":"have signup save data to db\r\nhave login read and validate password against db","created_at":"2018-03-10T07:03:42Z","updated_at":"2018-03-12T14:32:52Z","closed_at":null,"merged_at":null,"merge_commit_sha":"58dd6b14cc27078fcde3792b04d65655bd8e5734","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/atmiguel/cerealnotes/pulls/7/commits","review_comments_url":"https://api.github.com/repos/atmiguel/cerealnotes/pulls/7/comments","review_comment_url":"https://api.github.com/repos/atmiguel/cerealnotes/pulls/comments{/number}","comments_url":"https://api.github.com/repos/atmiguel/cerealnotes/issues/7/comments","statuses_url":"https://api.github.com/repos/atmiguel/cerealnotes/statuses/fd5c5b74ad08f57fd2f01f3f6a84f5ce4df16f96","head":{"label":"atmiguel:usersave","ref":"usersave","sha":"fd5c5b74ad08f57fd2f01f3f6a84f5ce4df16f96","user":{"login":"atmiguel","id":549631,"avatar_url":"https://avatars0.githubusercontent.com/u/549631?v=4","gravatar_id":"","url":"https://api.github.com/users/atmiguel","html_url":"https://github.com/atmiguel","followers_url":"https://api.github.com/users/atmiguel/followers","following_url":"https://api.github.com/users/atmiguel/following{/other_user}","gists_url":"https://api.github.com/users/atmiguel/gists{/gist_id}","starred_url":"https://api.github.com/users/atmiguel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/atmiguel/subscriptions","organizations_url":"https://api.github.com/users/atmiguel/orgs","repos_url":"https://api.github.com/users/atmiguel/repos","events_url":"https://api.github.com/users/atmiguel/events{/privacy}","received_events_url":"https://api.github.com/users/atmiguel/received_events","type":"User","site_admin":false},"repo":{"id":124090269,"name":"cerealnotes","full_name":"atmiguel/cerealnotes","owner":{"login":"atmiguel","id":549631,"avatar_url":"https://avatars0.githubusercontent.com/u/549631?v=4","gravatar_id":"","url":"https://api.github.com/users/atmiguel","html_url":"https://github.com/atmiguel","followers_url":"https://api.github.com/users/atmiguel/followers","following_url":"https://api.github.com/users/atmiguel/following{/other_user}","gists_url":"https://api.github.com/users/atmiguel/gists{/gist_id}","starred_url":"https://api.github.com/users/atmiguel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/atmiguel/subscriptions","organizations_url":"https://api.github.com/users/atmiguel/orgs","repos_url":"https://api.github.com/users/atmiguel/repos","events_url":"https://api.github.com/users/atmiguel/events{/privacy}","received_events_url":"https://api.github.com/users/atmiguel/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/atmiguel/cerealnotes","description":null,"fork":false,"url":"https://api.github.com/repos/atmiguel/cerealnotes","forks_url":"https://api.github.com/repos/atmiguel/cerealnotes/forks","keys_url":"https://api.github.com/repos/atmiguel/cerealnotes/keys{/key_id}","collaborators_url":"https://api.github.com/repos/atmiguel/cerealnotes/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/atmiguel/cerealnotes/teams","hooks_url":"https://api.github.com/repos/atmiguel/cerealnotes/hooks","issue_events_url":"https://api.github.com/repos/atmiguel/cerealnotes/issues/events{/number}","events_url":"https://api.github.com/repos/atmiguel/cerealnotes/events","assignees_url":"https://api.github.com/repos/atmiguel/cerealnotes/assignees{/user}","branches_url":"https://api.github.com/repos/atmiguel/cerealnotes/branches{/branch}","tags_url":"https://api.github.com/repos/atmiguel/cerealnotes/tags","blobs_url":"https://api.github.com/repos/atmiguel/cerealnotes/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/atmiguel/cerealnotes/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/atmiguel/cerealnotes/git/refs{/sha}","trees_url":"https://api.github.com/repos/atmiguel/cerealnotes/git/trees{/sha}","statuses_url":"https://api.github.com/repos/atmiguel/cerealnotes/statuses/{sha}","languages_url":"https://api.github.com/repos/atmiguel/cerealnotes/languages","stargazers_url":"https://api.github.com/repos/atmiguel/cerealnotes/stargazers","contributors_url":"https://api.github.com/repos/atmiguel/cerealnotes/contributors","subscribers_url":"https://api.github.com/repos/atmiguel/cerealnotes/subscribers","subscription_url":"https://api.github.com/repos/atmiguel/cerealnotes/subscription","commits_url":"https://api.github.com/repos/atmiguel/cerealnotes/commits{/sha}","git_commits_url":"https://api.github.com/repos/atmiguel/cerealnotes/git/commits{/sha}","comments_url":"https://api.github.com/repos/atmiguel/cerealnotes/comments{/number}","issue_comment_url":"https://api.github.com/repos/atmiguel/cerealnotes/issues/comments{/number}","contents_url":"https://api.github.com/repos/atmiguel/cerealnotes/contents/{+path}","compare_url":"https://api.github.com/repos/atmiguel/cerealnotes/compare/{base}...{head}","merges_url":"https://api.github.com/repos/atmiguel/cerealnotes/merges","archive_url":"https://api.github.com/repos/atmiguel/cerealnotes/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/atmiguel/cerealnotes/downloads","issues_url":"https://api.github.com/repos/atmiguel/cerealnotes/issues{/number}","pulls_url":"https://api.github.com/repos/atmiguel/cerealnotes/pulls{/number}","milestones_url":"https://api.github.com/repos/atmiguel/cerealnotes/milestones{/number}","notifications_url":"https://api.github.com/repos/atmiguel/cerealnotes/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/atmiguel/cerealnotes/labels{/name}","releases_url":"https://api.github.com/repos/atmiguel/cerealnotes/releases{/id}","deployments_url":"https://api.github.com/repos/atmiguel/cerealnotes/deployments","created_at":"2018-03-06T14:28:42Z","updated_at":"2018-03-12T14:18:27Z","pushed_at":"2018-03-12T06:46:06Z","git_url":"git://github.com/atmiguel/cerealnotes.git","ssh_url":"git@github.com:atmiguel/cerealnotes.git","clone_url":"https://github.com/atmiguel/cerealnotes.git","svn_url":"https://github.com/atmiguel/cerealnotes","homepage":null,"size":104,"stargazers_count":3,"watchers_count":3,"language":"JavaScript","has_issues":false,"has_projects":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":2,"license":null,"forks":0,"open_issues":2,"watchers":3,"default_branch":"master"}},"base":{"label":"atmiguel:master","ref":"master","sha":"99c6d7b18d47a891a783540207fa902ab57d40ed","user":{"login":"atmiguel","id":549631,"avatar_url":"https://avatars0.githubusercontent.com/u/549631?v=4","gravatar_id":"","url":"https://api.github.com/users/atmiguel","html_url":"https://github.com/atmiguel","followers_url":"https://api.github.com/users/atmiguel/followers","following_url":"https://api.github.com/users/atmiguel/following{/other_user}","gists_url":"https://api.github.com/users/atmiguel/gists{/gist_id}","starred_url":"https://api.github.com/users/atmiguel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/atmiguel/subscriptions","organizations_url":"https://api.github.com/users/atmiguel/orgs","repos_url":"https://api.github.com/users/atmiguel/repos","events_url":"https://api.github.com/users/atmiguel/events{/privacy}","received_events_url":"https://api.github.com/users/atmiguel/received_events","type":"User","site_admin":false},"repo":{"id":124090269,"name":"cerealnotes","full_name":"atmiguel/cerealnotes","owner":{"login":"atmiguel","id":549631,"avatar_url":"https://avatars0.githubusercontent.com/u/549631?v=4","gravatar_id":"","url":"https://api.github.com/users/atmiguel","html_url":"https://github.com/atmiguel","followers_url":"https://api.github.com/users/atmiguel/followers","following_url":"https://api.github.com/users/atmiguel/following{/other_user}","gists_url":"https://api.github.com/users/atmiguel/gists{/gist_id}","starred_url":"https://api.github.com/users/atmiguel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/atmiguel/subscriptions","organizations_url":"https://api.github.com/users/atmiguel/orgs","repos_url":"https://api.github.com/users/atmiguel/repos","events_url":"https://api.github.com/users/atmiguel/events{/privacy}","received_events_url":"https://api.github.com/users/atmiguel/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/atmiguel/cerealnotes","description":null,"fork":false,"url":"https://api.github.com/repos/atmiguel/cerealnotes","forks_url":"https://api.github.com/repos/atmiguel/cerealnotes/forks","keys_url":"https://api.github.com/repos/atmiguel/cerealnotes/keys{/key_id}","collaborators_url":"https://api.github.com/repos/atmiguel/cerealnotes/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/atmiguel/cerealnotes/teams","hooks_url":"https://api.github.com/repos/atmiguel/cerealnotes/hooks","issue_events_url":"https://api.github.com/repos/atmiguel/cerealnotes/issues/events{/number}","events_url":"https://api.github.com/repos/atmiguel/cerealnotes/events","assignees_url":"https://api.github.com/repos/atmiguel/cerealnotes/assignees{/user}","branches_url":"https://api.github.com/repos/atmiguel/cerealnotes/branches{/branch}","tags_url":"https://api.github.com/repos/atmiguel/cerealnotes/tags","blobs_url":"https://api.github.com/repos/atmiguel/cerealnotes/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/atmiguel/cerealnotes/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/atmiguel/cerealnotes/git/refs{/sha}","trees_url":"https://api.github.com/repos/atmiguel/cerealnotes/git/trees{/sha}","statuses_url":"https://api.github.com/repos/atmiguel/cerealnotes/statuses/{sha}","languages_url":"https://api.github.com/repos/atmiguel/cerealnotes/languages","stargazers_url":"https://api.github.com/repos/atmiguel/cerealnotes/stargazers","contributors_url":"https://api.github.com/repos/atmiguel/cerealnotes/contributors","subscribers_url":"https://api.github.com/repos/atmiguel/cerealnotes/subscribers","subscription_url":"https://api.github.com/repos/atmiguel/cerealnotes/subscription","commits_url":"https://api.github.com/repos/atmiguel/cerealnotes/commits{/sha}","git_commits_url":"https://api.github.com/repos/atmiguel/cerealnotes/git/commits{/sha}","comments_url":"https://api.github.com/repos/atmiguel/cerealnotes/comments{/number}","issue_comment_url":"https://api.github.com/repos/atmiguel/cerealnotes/issues/comments{/number}","contents_url":"https://api.github.com/repos/atmiguel/cerealnotes/contents/{+path}","compare_url":"https://api.github.com/repos/atmiguel/cerealnotes/compare/{base}...{head}","merges_url":"https://api.github.com/repos/atmiguel/cerealnotes/merges","archive_url":"https://api.github.com/repos/atmiguel/cerealnotes/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/atmiguel/cerealnotes/downloads","issues_url":"https://api.github.com/repos/atmiguel/cerealnotes/issues{/number}","pulls_url":"https://api.github.com/repos/atmiguel/cerealnotes/pulls{/number}","milestones_url":"https://api.github.com/repos/atmiguel/cerealnotes/milestones{/number}","notifications_url":"https://api.github.com/repos/atmiguel/cerealnotes/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/atmiguel/cerealnotes/labels{/name}","releases_url":"https://api.github.com/repos/atmiguel/cerealnotes/releases{/id}","deployments_url":"https://api.github.com/repos/atmiguel/cerealnotes/deployments","created_at":"2018-03-06T14:28:42Z","updated_at":"2018-03-12T14:18:27Z","pushed_at":"2018-03-12T06:46:06Z","git_url":"git://github.com/atmiguel/cerealnotes.git","ssh_url":"git@github.com:atmiguel/cerealnotes.git","clone_url":"https://github.com/atmiguel/cerealnotes.git","svn_url":"https://github.com/atmiguel/cerealnotes","homepage":null,"size":104,"stargazers_count":3,"watchers_count":3,"language":"JavaScript","has_issues":false,"has_projects":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":2,"license":null,"forks":0,"open_issues":2,"watchers":3,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/atmiguel/cerealnotes/pulls/7"},"html":{"href":"https://github.com/atmiguel/cerealnotes/pull/7"},"issue":{"href":"https://api.github.com/repos/atmiguel/cerealnotes/issues/7"},"comments":{"href":"https://api.github.com/repos/atmiguel/cerealnotes/issues/7/comments"},"review_comments":{"href":"https://api.github.com/repos/atmiguel/cerealnotes/pulls/7/comments"},"review_comment":{"href":"https://api.github.com/repos/atmiguel/cerealnotes/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/atmiguel/cerealnotes/pulls/7/commits"},"statuses":{"href":"https://api.github.com/repos/atmiguel/cerealnotes/statuses/fd5c5b74ad08f57fd2f01f3f6a84f5ce4df16f96"}},"author_association":"COLLABORATOR"}}
{"actor":{"display_login":"atmiguel"}}