whodat 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (123) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +10 -0
  3. data/.rspec +4 -0
  4. data/.travis.yml +3 -0
  5. data/CODE-OF-CONDUCT.md +60 -0
  6. data/Gemfile +19 -0
  7. data/Gemfile.lock +173 -0
  8. data/HOW-TO-CONTRIBUTE.md +19 -0
  9. data/MIT-LICENSE +20 -0
  10. data/README.md +99 -0
  11. data/Rakefile +24 -0
  12. data/Users +0 -0
  13. data/Whodat +0 -0
  14. data/app/assets/config/whodat_manifest.js +2 -0
  15. data/app/assets/images/whodat/.keep +0 -0
  16. data/app/assets/images/whodat/example-app-screencap.png +0 -0
  17. data/app/assets/images/whodat/navbar-pic-readme.png +0 -0
  18. data/app/assets/images/whodat/whodat-logo-tiny.png +0 -0
  19. data/app/assets/images/whodat/whodat-logo-wide.png +0 -0
  20. data/app/assets/images/whodat/whodat-logo.png +0 -0
  21. data/app/assets/javascripts/whodat/application.js +15 -0
  22. data/app/assets/javascripts/whodat/dashboard.js +2 -0
  23. data/app/assets/javascripts/whodat/sessions.js +2 -0
  24. data/app/assets/javascripts/whodat/users.js +2 -0
  25. data/app/assets/stylesheets/whodat/application.css +15 -0
  26. data/app/assets/stylesheets/whodat/dashboard.css +41 -0
  27. data/app/assets/stylesheets/whodat/navbar.css +45 -0
  28. data/app/assets/stylesheets/whodat/sessions.css +4 -0
  29. data/app/assets/stylesheets/whodat/users.css +4 -0
  30. data/app/controllers/whodat/application_controller.rb +30 -0
  31. data/app/controllers/whodat/dashboard_controller.rb +19 -0
  32. data/app/controllers/whodat/sessions_controller.rb +34 -0
  33. data/app/controllers/whodat/users_controller.rb +29 -0
  34. data/app/helpers/whodat/application_helper.rb +12 -0
  35. data/app/helpers/whodat/sessions_helper.rb +19 -0
  36. data/app/jobs/whodat/application_job.rb +4 -0
  37. data/app/mailers/whodat/application_mailer.rb +6 -0
  38. data/app/models/whodat/application_record.rb +5 -0
  39. data/app/models/whodat/user.rb +15 -0
  40. data/app/views/layouts/whodat/application.html.erb +23 -0
  41. data/app/views/whodat/application/_navbar.html.erb +26 -0
  42. data/app/views/whodat/dashboard/_navbar.html.erb +16 -0
  43. data/app/views/whodat/dashboard/index.html.erb +14 -0
  44. data/app/views/whodat/sessions/new.html.erb +29 -0
  45. data/app/views/whodat/users/create.html.erb +2 -0
  46. data/app/views/whodat/users/index.html.erb +2 -0
  47. data/app/views/whodat/users/new.html.erb +34 -0
  48. data/bin/rails +14 -0
  49. data/bin/rspec +29 -0
  50. data/config/routes.rb +15 -0
  51. data/db/migrate/20180717210347_create_whodat_users.rb +12 -0
  52. data/lib/tasks/boolean_as_integer.rake +20 -0
  53. data/lib/tasks/whodat_tasks.rake +4 -0
  54. data/lib/whodat.rb +23 -0
  55. data/lib/whodat/engine.rb +5 -0
  56. data/lib/whodat/version.rb +3 -0
  57. data/spec/controllers/sessions_controller_spec.rb +71 -0
  58. data/spec/controllers/users_controller_spec.rb +104 -0
  59. data/spec/dummy/Rakefile +6 -0
  60. data/spec/dummy/app/assets/config/manifest.js +4 -0
  61. data/spec/dummy/app/assets/javascripts/application.js +14 -0
  62. data/spec/dummy/app/assets/javascripts/cable.js +13 -0
  63. data/spec/dummy/app/assets/javascripts/welcome.js +2 -0
  64. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  65. data/spec/dummy/app/assets/stylesheets/welcome.css +100 -0
  66. data/spec/dummy/app/channels/application_cable/channel.rb +4 -0
  67. data/spec/dummy/app/channels/application_cable/connection.rb +4 -0
  68. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  69. data/spec/dummy/app/controllers/welcome_controller.rb +4 -0
  70. data/spec/dummy/app/jobs/application_job.rb +2 -0
  71. data/spec/dummy/app/mailers/application_mailer.rb +4 -0
  72. data/spec/dummy/app/models/application_record.rb +3 -0
  73. data/spec/dummy/app/views/layouts/application.html.erb +17 -0
  74. data/spec/dummy/app/views/layouts/mailer.html.erb +13 -0
  75. data/spec/dummy/app/views/layouts/mailer.text.erb +1 -0
  76. data/spec/dummy/app/views/welcome/index.html.erb +18 -0
  77. data/spec/dummy/bin/bundle +3 -0
  78. data/spec/dummy/bin/rails +4 -0
  79. data/spec/dummy/bin/rake +4 -0
  80. data/spec/dummy/bin/setup +36 -0
  81. data/spec/dummy/bin/update +31 -0
  82. data/spec/dummy/bin/yarn +11 -0
  83. data/spec/dummy/config.ru +5 -0
  84. data/spec/dummy/config/application.rb +35 -0
  85. data/spec/dummy/config/boot.rb +5 -0
  86. data/spec/dummy/config/cable.yml +10 -0
  87. data/spec/dummy/config/database.yml +25 -0
  88. data/spec/dummy/config/environment.rb +5 -0
  89. data/spec/dummy/config/environments/development.rb +61 -0
  90. data/spec/dummy/config/environments/production.rb +98 -0
  91. data/spec/dummy/config/environments/test.rb +53 -0
  92. data/spec/dummy/config/initializers/application_controller_renderer.rb +8 -0
  93. data/spec/dummy/config/initializers/assets.rb +14 -0
  94. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  95. data/spec/dummy/config/initializers/content_security_policy.rb +25 -0
  96. data/spec/dummy/config/initializers/cookies_serializer.rb +5 -0
  97. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  98. data/spec/dummy/config/initializers/inflections.rb +16 -0
  99. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  100. data/spec/dummy/config/initializers/routes.rb +23 -0
  101. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  102. data/spec/dummy/config/locales/en.yml +33 -0
  103. data/spec/dummy/config/puma.rb +34 -0
  104. data/spec/dummy/config/routes.rb +9 -0
  105. data/spec/dummy/config/spring.rb +6 -0
  106. data/spec/dummy/config/storage.yml +34 -0
  107. data/spec/dummy/db/schema.rb +24 -0
  108. data/spec/dummy/db/seeds.rb +21 -0
  109. data/spec/dummy/package.json +5 -0
  110. data/spec/dummy/public/404.html +67 -0
  111. data/spec/dummy/public/422.html +67 -0
  112. data/spec/dummy/public/500.html +66 -0
  113. data/spec/dummy/public/apple-touch-icon-precomposed.png +0 -0
  114. data/spec/dummy/public/apple-touch-icon.png +0 -0
  115. data/spec/dummy/public/favicon.ico +0 -0
  116. data/spec/dummy/spec/controllers/welcome_controller_spec.rb +12 -0
  117. data/spec/factories.rb +8 -0
  118. data/spec/rails_helper.rb +70 -0
  119. data/spec/spec_helper.rb +108 -0
  120. data/spec/support/factory_bot.rb +7 -0
  121. data/whodat-logo-wide.png +0 -0
  122. data/whodat.gemspec +36 -0
  123. metadata +3065 -0
data/Users ADDED
File without changes
data/Whodat ADDED
File without changes
@@ -0,0 +1,2 @@
1
+ //= link_directory ../javascripts/whodat .js
2
+ //= link_directory ../stylesheets/whodat .css
File without changes
@@ -0,0 +1,15 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file. JavaScript code in this file should be added after the last require_* statement.
9
+ //
10
+ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require rails-ujs
14
+ //= require_tree .
15
+ //
@@ -0,0 +1,2 @@
1
+ // Place all the behaviors and hooks related to the matching controller here.
2
+ // All this logic will automatically be available in application.js.
@@ -0,0 +1,2 @@
1
+ // Place all the behaviors and hooks related to the matching controller here.
2
+ // All this logic will automatically be available in application.js.
@@ -0,0 +1,2 @@
1
+ // Place all the behaviors and hooks related to the matching controller here.
2
+ // All this logic will automatically be available in application.js.
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
10
+ * files in this directory. Styles in this file should be added after the last require_* statement.
11
+ * It is generally better to create a new file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,41 @@
1
+
2
+ /* Add a black background color to the top navigation */
3
+ .topnav {
4
+ background-color: rgb(25, 42, 99);
5
+ overflow: hidden;
6
+ }
7
+
8
+ /* Style the links inside the navigation bar */
9
+ .topnav a {
10
+ float: left ;
11
+ display: block;
12
+ color: #f2f2f2;
13
+ text-align: center;
14
+ padding: 12px 12px;
15
+ text-decoration: none;
16
+ font-size: 17px;
17
+ }
18
+
19
+
20
+ #username {
21
+ float: right;
22
+ display: block;
23
+ color: #afc9e6;
24
+ text-align: center;
25
+ padding: 12px 16px;
26
+ text-decoration: none;
27
+ font-size: 17px;
28
+ }
29
+
30
+ /* Change the color of links on hover */
31
+ .topnav a:hover {
32
+ background-color: #ddd;
33
+ color: rgb(14, 64, 109);
34
+ }
35
+
36
+ /* Add an active class to highlight the current page */
37
+ .active {
38
+ background-color: rgb(144, 157, 177);
39
+ color: white;
40
+ }
41
+
@@ -0,0 +1,45 @@
1
+ /* Nav Bar */
2
+
3
+ /* Add a dark background and fix position at top */
4
+ .topnav {
5
+ background-color: rgb(25, 42, 99);
6
+ overflow: hidden;
7
+ position: fixed;
8
+ top: 0;
9
+ width: 100%;
10
+ }
11
+
12
+ /* Style the links inside the navigation bar */
13
+ .topnav a {
14
+ float: left ;
15
+ display: block;
16
+ color: #f2f2f2;
17
+ text-align: center;
18
+ padding: 12px 12px;
19
+ text-decoration: none;
20
+ font-size: 17px;
21
+ }
22
+
23
+
24
+ #username {
25
+ float: right;
26
+ display: block;
27
+ color: #afc9e6;
28
+ text-align: center;
29
+ padding: 12px 16px;
30
+ text-decoration: none;
31
+ font-size: 17px;
32
+ }
33
+
34
+ /* Change the color of links on hover */
35
+ .topnav a:hover {
36
+ background-color: #ddd;
37
+ color: rgb(14, 64, 109);
38
+ }
39
+
40
+ /* Add an active class to highlight the current page */
41
+ .active {
42
+ background-color: rgb(144, 157, 177);
43
+ color: white;
44
+ }
45
+
@@ -0,0 +1,4 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
@@ -0,0 +1,4 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
@@ -0,0 +1,30 @@
1
+ module Whodat
2
+ class ApplicationController < ActionController::Base
3
+ protect_from_forgery with: :exception
4
+ include SessionsHelper
5
+ include ApplicationHelper
6
+
7
+ def authenticate_user!
8
+ redirect_to new_session_path unless current_user
9
+ end
10
+
11
+ def sign_in(user)
12
+ session[:user_id] = user.id
13
+ end
14
+
15
+ def sign_out
16
+ session[:user_id] = nil
17
+ end
18
+
19
+ private
20
+
21
+ def session_cleared?
22
+ user_signed_in? || session[:user_id].nil?
23
+ end
24
+
25
+ def cleanup_dead_session
26
+ return unless Whodat::User.find_by( id: session[:user_id] ).nil?
27
+ end
28
+ end
29
+ end
30
+
@@ -0,0 +1,19 @@
1
+ require_dependency "whodat/application_controller"
2
+
3
+ module Whodat
4
+ class DashboardController < ApplicationController
5
+ # before_action :authenticate_user!
6
+
7
+ helper_method :current_user, :user_signed_in?
8
+
9
+ def index
10
+ def current_user
11
+ @current_user ||= Whodat::User.find_by( id: session[:user_id] )
12
+ end
13
+
14
+ def user_signed_in?
15
+ current_user
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,34 @@
1
+ require_dependency "whodat/application_controller"
2
+
3
+ module Whodat
4
+ class SessionsController < ApplicationController
5
+
6
+ def new
7
+ end
8
+
9
+ def create
10
+ user = Whodat::User.find_by( email: session_params[:email])
11
+ if user && user.authenticate(session_params[:password])
12
+ create_session(user)
13
+ flash[:notice] = "Welcome, #{user.name}!"
14
+ redirect_to main_app.root_path
15
+ else
16
+ flash[:notice] = "Invalid email or password. Please try again."
17
+ render :new
18
+ end
19
+ end
20
+
21
+ def destroy
22
+ destroy_session(current_user)
23
+ flash[:notice] = "You've been signed out, come back soon."
24
+ redirect_to main_app.root_path
25
+ end
26
+
27
+ private
28
+
29
+ def session_params
30
+ params.require(:session).permit(:name, :email, :password )
31
+ end
32
+ end
33
+ end
34
+
@@ -0,0 +1,29 @@
1
+ require_dependency "whodat/application_controller"
2
+
3
+ module Whodat
4
+ class UsersController < ApplicationController
5
+ def new
6
+ @user = User.new
7
+ end
8
+
9
+ def create
10
+
11
+ @user = User.new(user_params)
12
+
13
+ if @user.save
14
+ flash[:notice] = "Welcome, #{@user.name}!"
15
+ create_session(@user)
16
+ redirect_to main_app.root_path
17
+ else
18
+ flash[:notice] = "An error occurred. Please try again."
19
+ render :new
20
+ end
21
+ end
22
+
23
+ private
24
+
25
+ def user_params
26
+ params.require(:user).permit(:name, :email, :password, :password_confirmation)
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,12 @@
1
+ module Whodat
2
+ module ApplicationHelper
3
+
4
+ def current_user
5
+ @current_user ||= Whodat::User.find_by( id: session[:user_id] )
6
+ end
7
+
8
+ def user_signed_in?
9
+ current_user
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,19 @@
1
+ module Whodat
2
+ module SessionsHelper
3
+
4
+ def create_session(user)
5
+ session[:user_id] = user.id
6
+ end
7
+
8
+ def destroy_session(user)
9
+ session[:user_id] = nil
10
+ end
11
+
12
+ def current_user
13
+ Whodat::User.find_by(id: session[:user_id])
14
+ end
15
+ end
16
+ end
17
+
18
+
19
+
@@ -0,0 +1,4 @@
1
+ module Whodat
2
+ class ApplicationJob < ActiveJob::Base
3
+ end
4
+ end
@@ -0,0 +1,6 @@
1
+ module Whodat
2
+ class ApplicationMailer < ActionMailer::Base
3
+ default from: 'from@example.com'
4
+ layout 'mailer'
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ module Whodat
2
+ class ApplicationRecord < ActiveRecord::Base
3
+ self.abstract_class = true
4
+ end
5
+ end
@@ -0,0 +1,15 @@
1
+ class EmailValidator < ActiveModel::EachValidator
2
+ def validate_each(record, attribute, value)
3
+ record.errors.add attribute, (options[:message] || "is not a valid email") unless
4
+ value =~ /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i
5
+ end
6
+ end
7
+
8
+ module Whodat
9
+ class User < ApplicationRecord
10
+ has_secure_password
11
+ validates :email, presence: true, uniqueness: true, email: true
12
+ validates :name, :password_digest, presence: true
13
+ validates :password, length: { minimum: 8 }, on: :create
14
+ end
15
+ end
@@ -0,0 +1,23 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Whodat</title>
5
+ <%= csrf_meta_tags %>
6
+ <%= csp_meta_tag %>
7
+
8
+ <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
9
+ <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
10
+
11
+ <%= stylesheet_link_tag "whodat/application", media: "all", 'data-turbolinks-track': 'reload' %>
12
+ <%= javascript_include_tag "whodat/application", 'data-turbolinks-track': 'reload' %>
13
+
14
+ </head>
15
+ <body>
16
+
17
+ <%= yield %>
18
+ <% if flash[:notice] %>
19
+ <div class="notice"><%= flash[:notice] %></div>
20
+ <% end %>
21
+
22
+ </body>
23
+ </html>
@@ -0,0 +1,26 @@
1
+
2
+ <title>Whodat Navbar</title>
3
+ <%= csrf_meta_tags %>
4
+ <%= csp_meta_tag %>
5
+
6
+ <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
7
+ <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
8
+
9
+ <%= stylesheet_link_tag "whodat/application", media: "all" %>
10
+ <%= javascript_include_tag "whodat/application" %>
11
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
12
+
13
+ <div class="topnav" id="myTopnav">
14
+
15
+ <a> <%= link_to 'Main app', main_app.root_path %> </a>
16
+ <a> <%= link_to 'Signup', new_user_path %> </a>
17
+ <a> <%= link_to 'Login', new_session_path %> </a>
18
+ <% if user_signed_in? %>
19
+ <a> <%= link_to 'Logout', session_path(current_user), data: {confirm: "Are you sure?" }, method: :delete %> </a>
20
+ <div id="username"> You're logged in as <%=current_user.name %> </div>
21
+ <% end %>
22
+
23
+ </div>
24
+
25
+
26
+
@@ -0,0 +1,16 @@
1
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
2
+ <%= stylesheet_link_tag "whodat/navbar" %>
3
+
4
+ <div class="topnav" id="myTopnav">
5
+
6
+ <a> <%= link_to 'Main app', main_app.root_path %> </a>
7
+ <a> <%= link_to 'Signup', whodat.new_user_path %> </a>
8
+ <a> <%= link_to 'Login', whodat.new_session_path %> </a>
9
+
10
+
11
+ <% if user_signed_in? %>
12
+ <a> <%= link_to 'Logout', whodat.session_path(current_user), data: {confirm: "Are you sure?" }, method: :delete %> </a>
13
+ <div id="username"> You're logged in as <%=current_user.name %> </div>
14
+ <% end %>
15
+
16
+ </div>
@@ -0,0 +1,14 @@
1
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
2
+
3
+ <div class="topnav" id="myTopnav">
4
+
5
+ <a> <%= link_to 'Main app', main_app.root_path %> </a>
6
+ <a> <%= link_to 'Signup', new_user_path %> </a>
7
+ <a> <%= link_to 'Login', new_session_path %> </a>
8
+ <% if user_signed_in? %>
9
+ <a> <%= link_to 'Logout', session_path(current_user), data: {confirm: "Are you sure?" }, method: :delete %> </a>
10
+ <div id="username"> You're logged in as <%=current_user.name %> </div>
11
+ <% end %>
12
+
13
+ </div>
14
+