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.
- Loading branch information
Showing
10 changed files
with
71 additions
and
23 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
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,5 +1,6 @@ | ||
require 'active_record' | ||
require_relative 'database_connection' | ||
require 'bcrypt' | ||
establish_database_connection | ||
|
||
class User < ActiveRecord::Base | ||
|
@@ -12,17 +13,14 @@ def self.all_records | |
@users | ||
end | ||
|
||
def self.create_user(username, email, password) | ||
user = User.new | ||
user.username = username | ||
user.email = email | ||
user.password = password | ||
def self.create_user(name, username, email, password) | ||
encrypted_password = BCrypt::Password.create(password) | ||
user = User.new(name: name, username: username, email: email, password: encrypted_password) | ||
user.save | ||
user | ||
end | ||
end | ||
|
||
# User.create({ :username => 'Jamie', :email => "[email protected]", :password => "passwordjamie" }) | ||
|
||
# p User.all | ||
# user.all_records | ||
def authenticate(password) | ||
BCrypt::Password.new(self.password) == password | ||
end | ||
end |
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 |
---|---|---|
|
@@ -3,15 +3,16 @@ DROP TABLE IF EXISTS users CASCADE; | |
-- Table Definition | ||
CREATE TABLE users ( | ||
id SERIAL PRIMARY KEY, | ||
name text, | ||
username text, | ||
email text, | ||
password text | ||
); | ||
|
||
TRUNCATE TABLE users RESTART IDENTITY; | ||
|
||
INSERT INTO users ("username", "email", "password") VALUES | ||
('joehannis', '[email protected]', 'passwordjoe'), | ||
('jakehannis', '[email protected]', 'passwordjake'), | ||
('laurenhannis', '[email protected]', 'passwordlauren'), | ||
('lunahannis', '[email protected]', 'passwordluna'); | ||
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'); |
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 |
---|---|---|
|
@@ -11,7 +11,7 @@ | |
expect(User.all_records[1][:email]).to eq('[email protected]') | ||
end | ||
it 'creates a new user and returns the table' do | ||
User.create_user('johnsmith', '[email protected]', 'password123') | ||
User.create_user('John Smith', 'johnsmith', '[email protected]', 'password123') | ||
expect(User.all_records[4][:email]).to eq('[email protected]') | ||
end | ||
|
||
|
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