praetorian 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (87) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.rdoc +3 -0
  4. data/Rakefile +34 -0
  5. data/app/assets/javascripts/praetorian/application.js +13 -0
  6. data/app/assets/javascripts/praetorian/users.js +2 -0
  7. data/app/assets/stylesheets/praetorian/_colors.scss +24 -0
  8. data/app/assets/stylesheets/praetorian/application.css +15 -0
  9. data/app/assets/stylesheets/praetorian/users.css +4 -0
  10. data/app/controllers/praetorian/application_controller.rb +8 -0
  11. data/app/controllers/praetorian/users_controller.rb +60 -0
  12. data/app/helpers/praetorian/application_helper.rb +4 -0
  13. data/app/helpers/praetorian/users_helper.rb +4 -0
  14. data/app/models/praetorian/user.rb +41 -0
  15. data/app/views/layouts/praetorian/application.html.erb +14 -0
  16. data/app/views/praetorian/users/_form.html.erb +26 -0
  17. data/app/views/praetorian/users/edit.html.erb +4 -0
  18. data/app/views/praetorian/users/index.html.erb +12 -0
  19. data/app/views/praetorian/users/new.html.erb +4 -0
  20. data/app/views/praetorian/users/show.html.erb +14 -0
  21. data/app/views/shared/_errors.html.erb +17 -0
  22. data/config/routes.rb +7 -0
  23. data/db/migrate/20140604035508_create_praetorian_users.rb +13 -0
  24. data/lib/praetorian.rb +10 -0
  25. data/lib/praetorian/engine.rb +5 -0
  26. data/lib/praetorian/version.rb +3 -0
  27. data/lib/tasks/praetorian_tasks.rake +4 -0
  28. data/test/controllers/praetorian/users_controller_test.rb +9 -0
  29. data/test/dummy/README.rdoc +28 -0
  30. data/test/dummy/Rakefile +6 -0
  31. data/test/dummy/app/assets/javascripts/application.js +13 -0
  32. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  33. data/test/dummy/app/controllers/application_controller.rb +5 -0
  34. data/test/dummy/app/helpers/application_helper.rb +2 -0
  35. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  36. data/test/dummy/bin/bundle +3 -0
  37. data/test/dummy/bin/rails +4 -0
  38. data/test/dummy/bin/rake +4 -0
  39. data/test/dummy/config.ru +4 -0
  40. data/test/dummy/config/application.rb +23 -0
  41. data/test/dummy/config/boot.rb +5 -0
  42. data/test/dummy/config/database.yml +30 -0
  43. data/test/dummy/config/environment.rb +5 -0
  44. data/test/dummy/config/environments/development.rb +37 -0
  45. data/test/dummy/config/environments/production.rb +83 -0
  46. data/test/dummy/config/environments/test.rb +39 -0
  47. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  48. data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
  49. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  50. data/test/dummy/config/initializers/inflections.rb +16 -0
  51. data/test/dummy/config/initializers/mime_types.rb +5 -0
  52. data/test/dummy/config/initializers/session_store.rb +3 -0
  53. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  54. data/test/dummy/config/locales/en.yml +23 -0
  55. data/test/dummy/config/routes.rb +4 -0
  56. data/test/dummy/config/secrets.yml +22 -0
  57. data/test/dummy/db/development.sqlite3 +0 -0
  58. data/test/dummy/db/schema.rb +26 -0
  59. data/test/dummy/log/development.log +8976 -0
  60. data/test/dummy/public/404.html +67 -0
  61. data/test/dummy/public/422.html +67 -0
  62. data/test/dummy/public/500.html +66 -0
  63. data/test/dummy/public/favicon.ico +0 -0
  64. data/test/dummy/tmp/cache/assets/development/sass/59c313ae3378e14eaf89f9e64334805c0e43944a/_colors.scssc +0 -0
  65. data/test/dummy/tmp/cache/assets/development/sprockets/0b56b26cff3a25020ffefa40b332caf1 +0 -0
  66. data/test/dummy/tmp/cache/assets/development/sprockets/19a05fc599039d08921ed5d5e201072d +0 -0
  67. data/test/dummy/tmp/cache/assets/development/sprockets/4af769945107cdda7d5afe45dfa5caff +0 -0
  68. data/test/dummy/tmp/cache/assets/development/sprockets/54b60ec314006ae2c312204f5cd86607 +0 -0
  69. data/test/dummy/tmp/cache/assets/development/sprockets/637158b638367cb423e5150441b3a1a0 +0 -0
  70. data/test/dummy/tmp/cache/assets/development/sprockets/6659f44e33eee43b903cb9697a6ee0ed +0 -0
  71. data/test/dummy/tmp/cache/assets/development/sprockets/6a18ac85fee0e49b9ad1a4aff4e5282d +0 -0
  72. data/test/dummy/tmp/cache/assets/development/sprockets/93074a5be81756544ff72cc7c105f9d7 +0 -0
  73. data/test/dummy/tmp/cache/assets/development/sprockets/98db76255f36e18715ada491a39a3e46 +0 -0
  74. data/test/dummy/tmp/cache/assets/development/sprockets/9dfee174bedaaeb22510b602d1af26d9 +0 -0
  75. data/test/dummy/tmp/cache/assets/development/sprockets/a88914ee9bec1e0fcf4b415a9a427257 +0 -0
  76. data/test/dummy/tmp/cache/assets/development/sprockets/c86b235cda75dfaa6635e1bedf145200 +0 -0
  77. data/test/dummy/tmp/cache/assets/development/sprockets/d8f402dd49ff42e5f8df5066d25b722f +0 -0
  78. data/test/dummy/tmp/cache/assets/development/sprockets/eafc85273a3eec29007f8c47e5da0aa6 +0 -0
  79. data/test/dummy/tmp/cache/assets/development/sprockets/f3620d8e3c85de2ccf1aad33bea4f33b +0 -0
  80. data/test/dummy/tmp/pids/server.pid +1 -0
  81. data/test/fixtures/praetorian/users.yml +15 -0
  82. data/test/helpers/praetorian/users_helper_test.rb +6 -0
  83. data/test/integration/navigation_test.rb +10 -0
  84. data/test/models/praetorian/user_test.rb +9 -0
  85. data/test/praetorian_test.rb +7 -0
  86. data/test/test_helper.rb +15 -0
  87. metadata +247 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a06c2dad2c84f7e7ee23f959ba4d081591215dfd
4
+ data.tar.gz: 4af66c725286ca9cc627f8e1c1a16e4f9c3076c0
5
+ SHA512:
6
+ metadata.gz: b010d6082fbd2e080e8c42e115aa8d6c76a71a2349e5bb3709597b2ef326dc16272e21bd8ad9119971c18c2a5506be840fd9473e6a40de2d7de7fb00fb8f47a2
7
+ data.tar.gz: 3edda3cc5183d313d699b492a86f1ac2d37a5c38485daeaa745bc28752371b372285f5c520cebaadea904f411f39d8c2c1982b5d83b20b3e14ed6ec56d0bac26
@@ -0,0 +1,20 @@
1
+ Copyright 2014 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,3 @@
1
+ = Praetorian
2
+
3
+ This project rocks and uses MIT-LICENSE.
@@ -0,0 +1,34 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'Praetorian'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+
21
+
22
+ Bundler::GemHelper.install_tasks
23
+
24
+ require 'rake/testtask'
25
+
26
+ Rake::TestTask.new(:test) do |t|
27
+ t.libs << 'lib'
28
+ t.libs << 'test'
29
+ t.pattern = 'test/**/*_test.rb'
30
+ t.verbose = false
31
+ end
32
+
33
+
34
+ task default: :test
@@ -0,0 +1,13 @@
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 vendor/assets/javascripts of plugins, if any, 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.
9
+ //
10
+ // Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require_tree .
@@ -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,24 @@
1
+ $header-text-color: #FFFFFF;
2
+ $header-link-color: #FFFFFF;
3
+ $header-background-color: #000000;
4
+
5
+ $footer-text-color: #FFFFFF;
6
+ $footer-link-color: #FFFFFF;
7
+ $footer-background-color: #000000;
8
+
9
+ $primary-color: #F5F5F5;
10
+ $secondary-color: #237CBE;
11
+ $primary-background-color: #C0C0C0;
12
+ $secondary-background-color: #708890;
13
+ $primary-text-color: #444;
14
+ $secondary-text-color: #777;
15
+ $tertiary-text-color: #3366FF;
16
+ $primary-link-color: #2E6AA0;
17
+ $secondary-link-color: #FFF;
18
+ $errors-background-color: #FFC;
19
+ $errors-text-color: #DC3D3D;
20
+ $subdued-color: darken($primary-background-color, 20%);
21
+ $flash-notice-color: #FFC;
22
+ $flash-alert-color: #FFE1DE;
23
+ $accent-color: #FAFBFF;
24
+ $fieldset-color: lighten($secondary-background-color, 50%);
@@ -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 vendor/assets/stylesheets of plugins, if any, 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 styles
10
+ * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11
+ * file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -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,8 @@
1
+ module Praetorian
2
+ class ApplicationController < ActionController::Base
3
+
4
+ # Prevent CSRF attacks by raising an exception. For APIs, you may want to use :null_session instead.
5
+ protect_from_forgery with: :exception
6
+
7
+ end
8
+ end
@@ -0,0 +1,60 @@
1
+ require_dependency "praetorian/application_controller"
2
+
3
+ # modules are good for creating buckets of related methods, mixins (a module that has methods that get mixed into other classes to follow DRY principle) and namespaces.
4
+
5
+ module Praetorian
6
+ class UsersController < ApplicationController
7
+
8
+ def index
9
+ @users = Praetorian::User.all
10
+ end
11
+
12
+ def show
13
+ @user = Praetorian::User.find(params[:id])
14
+ # @user = User.find(cookies[:auth_token])
15
+ end
16
+
17
+ def new
18
+ @user = Praetorian::User.new
19
+ end
20
+
21
+ def create
22
+ @user = Praetorian::User.new(user_params)
23
+ if @user.save
24
+ # session[:user_id] = @user.id
25
+ cookies[:auth_token] = @user.auth_token
26
+ redirect_to root_url, notice: "Thank you for signing up!"
27
+ else
28
+ render "new"
29
+ end
30
+ end
31
+
32
+ def edit
33
+ @user = Praetorian::User.find(params[:id])
34
+ end
35
+
36
+ def update
37
+ @user = Praetorian::User.find(params[:id])
38
+ if @user.update(user_params)
39
+ redirect_to @user, notice: "Account successfully updated!"
40
+ else
41
+ render :edit
42
+ end
43
+ end
44
+
45
+ def destroy
46
+ @user = Praetorian::User.find(params[:id])
47
+ @user.destroy
48
+ session[:user_id] = nil
49
+ redirect_to root_url, alert: "Account successfully deleted!"
50
+ cookies[:auth_token] = nil
51
+ end
52
+
53
+ private
54
+
55
+ def user_params
56
+ params.require(:user).permit(:email, :password, :password_confirmation)
57
+ end
58
+
59
+ end
60
+ end
@@ -0,0 +1,4 @@
1
+ module Praetorian
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Praetorian
2
+ module UsersHelper
3
+ end
4
+ end
@@ -0,0 +1,41 @@
1
+ # modules are good for creating buckets of related methods, mixins (a module that has methods that get mixed into other classes to follow DRY principle) and namespaces.
2
+
3
+ module Praetorian
4
+ class User < ActiveRecord::Base
5
+ has_secure_password
6
+ validates :email, presence: true,
7
+ format: /\A\S+a\S+\z/,
8
+ uniqueness: { case_sensitive: false }
9
+ validates_presence_of :password, :on => :create
10
+ before_create { generate_token(:auth_token) }
11
+
12
+ # Refactored to have 2 levels of authentication.
13
+ # Level 1. The user class level authenticate method to make sure e-mail exists for a user account.
14
+ # Level 2. The instance level that is called on the user object that has_secure password provides to compare passwords. User.authenticate is a convenience method that comes with has_secure_password. It takes the plain text password passed in from the session form, encrypts it and compares to encrypted password_digest field in database. If these two passwords match, authenticate returns the user object indicating the submitted password is correct. If the passwords don't match, authenticate returns false indicating the password is incorrect. Because the User.find_by above can return nil if there is no match, we must check if user and user.authenticate.
15
+ # Note: params are at the controller level. We can assign params values at the controller level and pass as arguments to other classes such as the User model.
16
+
17
+ def self.authenticate(email, password)
18
+ # user = User.find_by(email: params[:email]) - if performed in users_controller
19
+ user = User.find_by(email: email)
20
+ # if user && user.authenticate(params[:password]) - if performed in users_controller
21
+ user && user.authenticate(password)
22
+ end
23
+
24
+ def admin?
25
+ #
26
+ end
27
+
28
+ def send_password_reset
29
+ generate_token(:password_reset_token)
30
+ self.password_reset_sent_at = Time.zone.now
31
+ save!
32
+ UserMailer.password_reset(self).deliver
33
+ end
34
+
35
+ def generate_token(column)
36
+ begin
37
+ self[column] = SecureRandom.urlsafe_base64
38
+ end while User.exists?(column => self[column])
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Praetorian</title>
5
+ <%= stylesheet_link_tag "praetorian/application", media: "all" %>
6
+ <%= javascript_include_tag "praetorian/application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
@@ -0,0 +1,26 @@
1
+ <%= form_for(@user) do |f| %>
2
+ <%= render "shared/errors", object: @user %>
3
+ <fieldset>
4
+ <ol>
5
+ <li class="required">
6
+ <%= f.label :email %>
7
+ <%= f.email_field :email, size: 40 %>
8
+ </li>
9
+ <li class="required">
10
+ <%= f.label :password %>
11
+ <%= f.password_field :password, size: 40 %>
12
+ </li>
13
+ <li class="required">
14
+ <%= f.label :password_confirmation, "Confirm Password" %>
15
+ <%= f.password_field :password_confirmation, size: 40 %>
16
+ </li>
17
+ </ol>
18
+ <p>
19
+ <% if @user.new_record? %>
20
+ <%= f.submit "Create Account" %>
21
+ <% else %>
22
+ <%= f.submit "Update Account" %>
23
+ <% end %>
24
+ </p>
25
+ </fieldset>
26
+ <% end %>
@@ -0,0 +1,4 @@
1
+ <div class="comments_area_1">
2
+ <h2>Edit Profile for <%= link_to "praetorian", root_path %> user account.</h2>
3
+
4
+ <%= render 'form' %>
@@ -0,0 +1,12 @@
1
+ <header id="content-header">
2
+ <h1>User Management Index</h1>
3
+ <h1><%= pluralize(@users.size, 'User') %></h1>
4
+ </header>
5
+
6
+ <ul id="users">
7
+ <% @users.each do |user| %>
8
+ <li>
9
+ <%= link_to user.email, praetorian.user_path(user) %>
10
+ </li>
11
+ <% end %>
12
+ </ul>
@@ -0,0 +1,4 @@
1
+ <div class="comments_area_1">
2
+ <h2>Sign Up to <%= link_to "Home Page", root_path %></h2>
3
+
4
+ <%= render 'form' %>
@@ -0,0 +1,14 @@
1
+ <article id="user">
2
+ <header>
3
+ <h1><%= @user.email %></h1>
4
+ </header>
5
+ <footer>
6
+ <nav>
7
+ <%= link_to 'Edit Account', praetorian.edit_user_path(@user), class: 'button' %>
8
+ <%= link_to 'Delete Account', @user,
9
+ method: :delete,
10
+ data: { confirm: 'Are you sure you want to permanently delete your account?' },
11
+ class: 'button' %>
12
+ </nav>
13
+ </footer>
14
+ </article>
@@ -0,0 +1,17 @@
1
+ <% if object.errors.any? %>
2
+ <section id="errors">
3
+ <header>
4
+ <h2>
5
+ Oops! The <%= object.class.name.titleize.downcase %> could not be saved.
6
+ </h2>
7
+ <h3>
8
+ Please correct the following <%= pluralize(object.errors.count, "error") %>:
9
+ </h3>
10
+ </header>
11
+ <ul>
12
+ <% object.errors.full_messages.each do |message| %>
13
+ <li><%= message %></li>
14
+ <% end %>
15
+ </ul>
16
+ </section>
17
+ <% end %>
@@ -0,0 +1,7 @@
1
+ Praetorian::Engine.routes.draw do
2
+
3
+ resources :users
4
+
5
+ root :to => 'users#index'
6
+
7
+ end
@@ -0,0 +1,13 @@
1
+ class CreatePraetorianUsers < ActiveRecord::Migration
2
+ def change
3
+ create_table :praetorian_users do |t|
4
+ t.string :email
5
+ t.string :password_digest
6
+ t.string :auth_token
7
+ t.string :passsword_reset_token
8
+ t.datetime :password_reset_sent_at
9
+
10
+ t.timestamps
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,10 @@
1
+ # require any gems that are used in the rails engine here.
2
+
3
+ # require bcrypt-ruby', '~> 3.0.0' fails for some reason
4
+ # I changed my gem to gem 'bcrypt-ruby', '~> 3.1.0' which installed bcrypt 3.1.7. Saw a warning message about the gem being renamed and changed it to gem 'bcrypt', '~> 3.1.0'
5
+ require "bcrypt"
6
+ require "sass-rails"
7
+ require "praetorian/engine"
8
+
9
+ module Praetorian
10
+ end
@@ -0,0 +1,5 @@
1
+ module Praetorian
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace Praetorian
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ module Praetorian
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :praetorian do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,9 @@
1
+ require 'test_helper'
2
+
3
+ module Praetorian
4
+ class UsersControllerTest < ActionController::TestCase
5
+ # test "the truth" do
6
+ # assert true
7
+ # end
8
+ end
9
+ end
@@ -0,0 +1,28 @@
1
+ == README
2
+
3
+ This README would normally document whatever steps are necessary to get the
4
+ application up and running.
5
+
6
+ Things you may want to cover:
7
+
8
+ * Ruby version
9
+
10
+ * System dependencies
11
+
12
+ * Configuration
13
+
14
+ * Database creation
15
+
16
+ * Database initialization
17
+
18
+ * How to run the test suite
19
+
20
+ * Services (job queues, cache servers, search engines, etc.)
21
+
22
+ * Deployment instructions
23
+
24
+ * ...
25
+
26
+
27
+ Please feel free to use a different markup language if you do not plan to run
28
+ <tt>rake doc:app</tt>.