forked from makersacademy/chitter-challenge
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added login and logout method, along with rspec tests
- Loading branch information
Showing
8 changed files
with
143 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,31 @@ | ||
DROP TABLE IF EXISTS users CASCADE; | ||
|
||
-- Table Definition | ||
CREATE TABLE users ( | ||
SET client_min_messages = WARNING; | ||
CREATE EXTENSION IF NOT EXISTS pgcrypto; | ||
-- Define the table structure | ||
CREATE TABLE IF NOT EXISTS users ( | ||
id SERIAL PRIMARY KEY, | ||
name text, | ||
username text, | ||
email text, | ||
password text | ||
); | ||
|
||
-- Clear existing data and reset the auto-incrementing ID | ||
TRUNCATE TABLE users RESTART IDENTITY; | ||
|
||
-- Helper function to encrypt passwords using BCrypt | ||
CREATE OR REPLACE FUNCTION encrypt_password(password text) | ||
RETURNS text AS $$ | ||
DECLARE | ||
hashed_password text; | ||
BEGIN | ||
hashed_password := crypt(password, gen_salt('bf')); | ||
RETURN hashed_password; | ||
END; | ||
$$ LANGUAGE plpgsql; | ||
|
||
-- Insert user records with encrypted passwords | ||
INSERT INTO users ("name", "username", "email", "password") VALUES | ||
('Joe Hannis', 'joehannis', '[email protected]', 'passwordjoe'), | ||
('Jake Hannis', 'jakehannis', '[email protected]', 'passwordjake'), | ||
('Lauren Hannis', 'laurenhannis', '[email protected]', 'passwordlauren'), | ||
('Luna Hannis', 'lunahannis', '[email protected]', 'passwordluna'); | ||
('Joe Hannis', 'joehannis', '[email protected]', encrypt_password('passwordjoe')), | ||
('Jake Hannis', 'jakehannis', '[email protected]', encrypt_password('passwordjake')), | ||
('Lauren Hannis', 'laurenhannis', '[email protected]', encrypt_password('passwordlauren')), | ||
('Luna Hannis', 'lunahannis', '[email protected]', encrypt_password('passwordluna')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<html> | ||
<head></head> | ||
<body> | ||
<h1>Chitter</h1> | ||
<div>What would you like to say?</div> | ||
<div><form action="/account_page" method="POST"> | ||
<input type="text" name="message"> | ||
<input type="submit" value="Post a message!"> | ||
</form></div> | ||
<% @@posts.each do |post| %> | ||
<%= post %><br /> | ||
<% end %> | ||
<a href="http://localhost:9292/logout">Logout</a> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<html> | ||
<head></head> | ||
<body> | ||
<h1>Welcome to Chitter!</h1> | ||
<div>Please log in below</div> | ||
<div><form action="/login" method="POST"> | ||
<div>Username</div> | ||
<input type="text" name="username"> | ||
<div>Password</div> | ||
<input type="password" name="password"> | ||
<input type="submit" value="Login"> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<html> | ||
<head></head> | ||
<body> | ||
<h1>Login failure</h1> | ||
<div><a href="http://localhost:9292/login">click here to try again</a></div> | ||
</body> | ||
</html> |