diff --git a/Pearlception/.gitignore b/Pearlception/.gitignore index 48fb168..e7eac14 100644 --- a/Pearlception/.gitignore +++ b/Pearlception/.gitignore @@ -15,3 +15,4 @@ # Ignore Byebug command history file. .byebug_history +/config/database.yml diff --git a/Pearlception/Gemfile b/Pearlception/Gemfile index 649a89f..9a447a8 100644 --- a/Pearlception/Gemfile +++ b/Pearlception/Gemfile @@ -30,10 +30,12 @@ gem 'jbuilder', '~> 2.5' # Use Redis adapter to run Action Cable in production # gem 'redis', '~> 3.0' # Use ActiveModel has_secure_password -# gem 'bcrypt', '~> 3.1.7' - +gem 'bcrypt', '~> 3.1.7' +# gem 'bcrypt-ruby', :require => 'bcrypt' # Use Capistrano for deployment # gem 'capistrano-rails', group: :development +# for sign in sign up +gem 'devise' group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console diff --git a/Pearlception/Gemfile.lock b/Pearlception/Gemfile.lock index 1324266..7b37024 100644 --- a/Pearlception/Gemfile.lock +++ b/Pearlception/Gemfile.lock @@ -39,6 +39,7 @@ GEM minitest (~> 5.1) tzinfo (~> 1.1) arel (7.1.4) + bcrypt (3.1.11) builder (3.2.2) byebug (9.0.6) coffee-rails (4.2.1) @@ -50,6 +51,12 @@ GEM coffee-script-source (1.12.2) concurrent-ruby (1.0.4) debug_inspector (0.0.2) + devise (4.2.0) + bcrypt (~> 3.0) + orm_adapter (~> 0.1) + railties (>= 4.1.0, < 5.1) + responders + warden (~> 1.2.3) erubis (2.7.0) execjs (2.7.0) ffi (1.9.14) @@ -81,6 +88,7 @@ GEM nio4r (1.2.1) nokogiri (1.7.0) mini_portile2 (~> 2.1.0) + orm_adapter (0.5.0) puma (3.6.2) rack (2.0.1) rack-test (0.6.3) @@ -112,6 +120,8 @@ GEM rb-fsevent (0.9.8) rb-inotify (0.9.7) ffi (>= 0.5.0) + responders (2.3.0) + railties (>= 4.2.0, < 5.1) sass (3.4.23) sass-rails (5.0.6) railties (>= 4.0.0, < 6) @@ -141,6 +151,8 @@ GEM thread_safe (~> 0.1) uglifier (3.0.4) execjs (>= 0.3.0, < 3) + warden (1.2.6) + rack (>= 1.0) web-console (3.4.0) actionview (>= 5.0) activemodel (>= 5.0) @@ -154,8 +166,10 @@ PLATFORMS ruby DEPENDENCIES + bcrypt (~> 3.1.7) byebug coffee-rails (~> 4.2) + devise jbuilder (~> 2.5) jquery-rails listen (~> 3.0.5) diff --git a/Pearlception/app/assets/javascripts/registrations.coffee b/Pearlception/app/assets/javascripts/registrations.coffee new file mode 100644 index 0000000..24f83d1 --- /dev/null +++ b/Pearlception/app/assets/javascripts/registrations.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://coffeescript.org/ diff --git a/Pearlception/app/assets/stylesheets/registrations.scss b/Pearlception/app/assets/stylesheets/registrations.scss new file mode 100644 index 0000000..f6e17a2 --- /dev/null +++ b/Pearlception/app/assets/stylesheets/registrations.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the registrations controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/Pearlception/app/controllers/application_controller.rb b/Pearlception/app/controllers/application_controller.rb index 1c07694..d620036 100644 --- a/Pearlception/app/controllers/application_controller.rb +++ b/Pearlception/app/controllers/application_controller.rb @@ -1,3 +1,22 @@ class ApplicationController < ActionController::Base protect_from_forgery with: :exception + protected + def authenticate_user + if session[:user_id] + # set current user object to @current_user object variable + @current_user = User.find session[:user_id] + return true + else + redirect_to(:controller => 'sessions', :action => 'login') + return false + end + end + def save_login_state + if session[:user_id] + redirect_to(:controller => 'sessions', :action => 'home') + return false + else + return true + end + end end diff --git a/Pearlception/app/controllers/registrations_controller.rb b/Pearlception/app/controllers/registrations_controller.rb new file mode 100644 index 0000000..b97cbdf --- /dev/null +++ b/Pearlception/app/controllers/registrations_controller.rb @@ -0,0 +1,7 @@ +class RegistrationsController < Devise::RegistrationsController + private + + def sign_up_params + params.require(:user).permit(:company_id, :email, :password, :password_confirmation) + end +end diff --git a/Pearlception/app/helpers/registrations_helper.rb b/Pearlception/app/helpers/registrations_helper.rb new file mode 100644 index 0000000..b100376 --- /dev/null +++ b/Pearlception/app/helpers/registrations_helper.rb @@ -0,0 +1,2 @@ +module RegistrationsHelper +end diff --git a/Pearlception/app/helpers/sessions_helper.rb b/Pearlception/app/helpers/sessions_helper.rb new file mode 100644 index 0000000..309f8b2 --- /dev/null +++ b/Pearlception/app/helpers/sessions_helper.rb @@ -0,0 +1,2 @@ +module SessionsHelper +end diff --git a/Pearlception/app/models/company.rb b/Pearlception/app/models/company.rb new file mode 100644 index 0000000..c2737b5 --- /dev/null +++ b/Pearlception/app/models/company.rb @@ -0,0 +1,3 @@ +class Company < ApplicationRecord + belongs_to :user +end diff --git a/Pearlception/app/models/user.rb b/Pearlception/app/models/user.rb new file mode 100644 index 0000000..b2091f9 --- /dev/null +++ b/Pearlception/app/models/user.rb @@ -0,0 +1,6 @@ +class User < ApplicationRecord + # Include default devise modules. Others available are: + # :confirmable, :lockable, :timeoutable and :omniauthable + devise :database_authenticatable, :registerable, + :recoverable, :rememberable, :trackable, :validatable +end diff --git a/Pearlception/app/views/layouts/application.html.erb b/Pearlception/app/views/layouts/application.html.erb index 685c9c6..d10301f 100644 --- a/Pearlception/app/views/layouts/application.html.erb +++ b/Pearlception/app/views/layouts/application.html.erb @@ -9,6 +9,13 @@
+ <% if notice %> +<%= notice %>
+ <% end %> + <% if alert %> +<%= alert %>
+ <% end %> <%= yield %> +