samurai_core 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 (41) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.rdoc +3 -0
  4. data/Rakefile +24 -0
  5. data/app/assets/javascripts/samurai/application.js +16 -0
  6. data/app/assets/stylesheets/samurai/application.css.scss +6 -0
  7. data/app/controllers/samurai/admin/admin_controller.rb +9 -0
  8. data/app/controllers/samurai/admin/users_controller.rb +9 -0
  9. data/app/controllers/samurai/application_controller.rb +13 -0
  10. data/app/controllers/samurai/dashboard_controller.rb +9 -0
  11. data/app/helpers/samurai/application_helper.rb +22 -0
  12. data/app/models/samurai/ability.rb +67 -0
  13. data/app/models/samurai/user.rb +10 -0
  14. data/app/views/devise/confirmations/new.html.erb +16 -0
  15. data/app/views/devise/mailer/confirmation_instructions.html.erb +5 -0
  16. data/app/views/devise/mailer/reset_password_instructions.html.erb +8 -0
  17. data/app/views/devise/mailer/unlock_instructions.html.erb +7 -0
  18. data/app/views/devise/passwords/edit.html.erb +22 -0
  19. data/app/views/devise/passwords/new.html.erb +16 -0
  20. data/app/views/devise/registrations/edit.html.erb +50 -0
  21. data/app/views/devise/registrations/new.html.erb +34 -0
  22. data/app/views/devise/sessions/new.html.erb +36 -0
  23. data/app/views/devise/shared/_links.html.erb +25 -0
  24. data/app/views/devise/unlocks/new.html.erb +16 -0
  25. data/app/views/layouts/samurai/application.html.erb +49 -0
  26. data/app/views/samurai/admin/admin/index.html.erb +34 -0
  27. data/app/views/samurai/admin/shared/_nav.html.erb +12 -0
  28. data/app/views/samurai/admin/users/index.html.erb +29 -0
  29. data/app/views/samurai/dashboard/index.html.erb +7 -0
  30. data/app/views/samurai/static/403.html +1 -0
  31. data/config/initializers/devise.rb +261 -0
  32. data/config/locales/devise.en.yml +60 -0
  33. data/config/routes.rb +8 -0
  34. data/db/migrate/20150413191412_devise_create_samurai_users.rb +42 -0
  35. data/db/migrate/20150415165903_add_admin_to_samurai_users.rb +5 -0
  36. data/lib/samurai/core.rb +13 -0
  37. data/lib/samurai/core/engine.rb +17 -0
  38. data/lib/samurai/core/version.rb +5 -0
  39. data/lib/samurai_core.rb +2 -0
  40. data/lib/tasks/core_tasks.rake +4 -0
  41. metadata +239 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8b4690984ce28ab192171b33c6eefb261dce9ead
4
+ data.tar.gz: 600052235be812abaf1d09273c5ea9725775eab0
5
+ SHA512:
6
+ metadata.gz: 6b8dfbec07a7fa684a8ff393e721fef55037d618ff0505950874a360c347917ac3608ee003967fd77673080344bb121d73b58a0c9e3ab2e1a49f8cbac86b1d32
7
+ data.tar.gz: 9da53d0c3476b30f6a66e9c2c38e2db56f498fe7db3891c75a9e53be79f333785c9ad11e4dc6d8421e48cb123387a7b81e7b67e4ad90f7a3681c641fe8e0ee90
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2015 Lucas Mendelowski
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.
data/README.rdoc ADDED
@@ -0,0 +1,3 @@
1
+ = Core
2
+
3
+ This project rocks and uses MIT-LICENSE.
data/Rakefile ADDED
@@ -0,0 +1,24 @@
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 = 'Core'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+
18
+
19
+ load 'rails/tasks/statistics.rake'
20
+
21
+
22
+
23
+ Bundler::GemHelper.install_tasks
24
+
@@ -0,0 +1,16 @@
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.
9
+ //
10
+ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require_tree .
14
+ //= require jquery
15
+ //= require jquery_ujs
16
+ //= require bootstrap-sprockets
@@ -0,0 +1,6 @@
1
+ @import "bootstrap-sprockets";
2
+ @import "bootstrap";
3
+
4
+ body {
5
+ padding-top: 65px; // For the nav bar
6
+ }
@@ -0,0 +1,9 @@
1
+ module Samurai
2
+ module Admin
3
+ class AdminController < ApplicationController
4
+ def index
5
+
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module Samurai
2
+ module Admin
3
+ class UsersController < AdminController
4
+ def index
5
+ @users = Samurai::User.ordered.limit(3)
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,13 @@
1
+ module Samurai
2
+ class ApplicationController < ActionController::Base
3
+ before_filter :authenticate_user!
4
+
5
+ rescue_from CanCan::AccessDenied do |exception|
6
+ render file: 'static/403.html', status: 403, layout: false
7
+ end
8
+
9
+ def current_ability
10
+ @current_ability ||= Samurai::Ability.new(current_user)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,9 @@
1
+ module Samurai
2
+ class DashboardController < ApplicationController
3
+ authorize_resource class: false
4
+
5
+ def index
6
+
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,22 @@
1
+ module Samurai
2
+ module ApplicationHelper
3
+ FLASH_CLASSES = {
4
+ notice: "alert alert-info",
5
+ success: "alert alert-success",
6
+ alert: "alert alert-danger",
7
+ error: "alert alert-danger"
8
+ }
9
+
10
+ def active(path, comparator = :absolute)
11
+ if comparator == :inclusion
12
+ /^#{path}/ =~ request.path ? 'active' : ''
13
+ else
14
+ current_page?(path) ? 'active' : ''
15
+ end
16
+ end
17
+
18
+ def flash_class(level)
19
+ FLASH_CLASSES[level]
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,67 @@
1
+ module Samurai
2
+ class Ability
3
+ include CanCan::Ability
4
+
5
+ class_attribute :abilities
6
+ self.abilities = Set.new
7
+
8
+ # Allows us to go beyond the standard cancan initialize method which makes
9
+ # it difficult for engines to modify the default {Ability} of an
10
+ # application. The registered ability should behave properly as a
11
+ # stand-alone class
12
+ # and therefore should be easy to test in isolation.
13
+ # @param ability [Ability] a class that includes the CanCan::Ability module.
14
+ def self.register_ability(ability)
15
+ self.abilities.add(ability)
16
+ end
17
+
18
+ # Remove a registered ability.
19
+ # @param ability [Ability] a class that includes the CanCan::Ability module.
20
+ def self.remove_ability(ability)
21
+ self.abilities.delete(ability)
22
+ end
23
+
24
+ def initialize(user)
25
+ Rails.logger.info self.abilities.inspect
26
+
27
+ if user.admin?
28
+ can :manage, :all
29
+ else
30
+ can :read, :dashboard
31
+ end
32
+
33
+ # Include any abilities registered by extensions, etc.
34
+ Ability.abilities.each do |klass|
35
+ ability = klass.send(:new, user)
36
+ @rules = rules + ability.send(:rules)
37
+ end
38
+
39
+ # Define abilities for the passed in user here. For example:
40
+ #
41
+ # user ||= User.new # guest user (not logged in)
42
+ # if user.admin?
43
+ # can :manage, :all
44
+ # else
45
+ # can :read, :all
46
+ # end
47
+ #
48
+ # The first argument to `can` is the action you are giving the user
49
+ # permission to do.
50
+ # If you pass :manage it will apply to every action. Other common actions
51
+ # here are :read, :create, :update and :destroy.
52
+ #
53
+ # The second argument is the resource the user can perform the action on.
54
+ # If you pass :all it will apply to every resource. Otherwise pass a Ruby
55
+ # class of the resource.
56
+ #
57
+ # The third argument is an optional hash of conditions to further filter the
58
+ # objects.
59
+ # For example, here the user can only update published articles.
60
+ #
61
+ # can :update, Article, :published => true
62
+ #
63
+ # See the wiki for details:
64
+ # https://github.com/ryanb/cancan/wiki/Defining-Abilities
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,10 @@
1
+ module Samurai
2
+ class User < ActiveRecord::Base
3
+ # Include default devise modules. Others available are:
4
+ # :confirmable, :lockable, :timeoutable and :omniauthable
5
+ devise :database_authenticatable, :registerable,
6
+ :recoverable, :rememberable, :trackable, :validatable
7
+
8
+ scope :ordered, -> { order('created_at desc') }
9
+ end
10
+ end
@@ -0,0 +1,16 @@
1
+ <h2>Resend confirmation instructions</h2>
2
+
3
+ <%= form_for(resource, as: resource_name, url: confirmation_path(resource_name), html: { method: :post }) do |f| %>
4
+ <%= devise_error_messages! %>
5
+
6
+ <div class="field">
7
+ <%= f.label :email %><br />
8
+ <%= f.email_field :email, autofocus: true %>
9
+ </div>
10
+
11
+ <div class="actions">
12
+ <%= f.submit "Resend confirmation instructions" %>
13
+ </div>
14
+ <% end %>
15
+
16
+ <%= render "devise/shared/links" %>
@@ -0,0 +1,5 @@
1
+ <p>Welcome <%= @email %>!</p>
2
+
3
+ <p>You can confirm your account email through the link below:</p>
4
+
5
+ <p><%= link_to 'Confirm my account', confirmation_url(@resource, confirmation_token: @token) %></p>
@@ -0,0 +1,8 @@
1
+ <p>Hello <%= @resource.email %>!</p>
2
+
3
+ <p>Someone has requested a link to change your password. You can do this through the link below.</p>
4
+
5
+ <p><%= link_to 'Change my password', edit_password_url(@resource, reset_password_token: @token) %></p>
6
+
7
+ <p>If you didn't request this, please ignore this email.</p>
8
+ <p>Your password won't change until you access the link above and create a new one.</p>
@@ -0,0 +1,7 @@
1
+ <p>Hello <%= @resource.email %>!</p>
2
+
3
+ <p>Your account has been locked due to an excessive number of unsuccessful sign in attempts.</p>
4
+
5
+ <p>Click the link below to unlock your account:</p>
6
+
7
+ <p><%= link_to 'Unlock my account', unlock_url(@resource, unlock_token: @token) %></p>
@@ -0,0 +1,22 @@
1
+ <h2>Change your password</h2>
2
+
3
+ <%= form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :put }) do |f| %>
4
+ <%= devise_error_messages! %>
5
+ <%= f.hidden_field :reset_password_token %>
6
+
7
+ <div class="field">
8
+ <%= f.label :password, "New password" %><br />
9
+ <%= f.password_field :password, autofocus: true, autocomplete: "off" %>
10
+ </div>
11
+
12
+ <div class="field">
13
+ <%= f.label :password_confirmation, "Confirm new password" %><br />
14
+ <%= f.password_field :password_confirmation, autocomplete: "off" %>
15
+ </div>
16
+
17
+ <div class="actions">
18
+ <%= f.submit "Change my password" %>
19
+ </div>
20
+ <% end %>
21
+
22
+ <%= render "devise/shared/links" %>
@@ -0,0 +1,16 @@
1
+ <h2>Forgot your password?</h2>
2
+
3
+ <%= form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :post }) do |f| %>
4
+ <%= devise_error_messages! %>
5
+
6
+ <div class="field">
7
+ <%= f.label :email %><br />
8
+ <%= f.email_field :email, autofocus: true %>
9
+ </div>
10
+
11
+ <div class="actions">
12
+ <%= f.submit "Send me reset password instructions" %>
13
+ </div>
14
+ <% end %>
15
+
16
+ <%= render "devise/shared/links" %>
@@ -0,0 +1,50 @@
1
+ <h2>Edit <%= resource_name.to_s.humanize %></h2>
2
+
3
+ <hr>
4
+
5
+ <%= form_for(resource, as: resource_name, url: registration_path(resource_name),
6
+ html: { method: :put, class: 'form-horizontal' }) do |f| %>
7
+ <%= devise_error_messages! %>
8
+ <div class="form-group">
9
+ <%= f.label :email, class: 'col-sm-2 control-label' %> <div class="col-sm-6">
10
+ <%= f.email_field :email, class: 'form-control' %> </div>
11
+ </div>
12
+ <div class="form-group">
13
+ <%= f.label :password, class: 'col-sm-2 control-label' %>
14
+ <i>(leave blank if you don't want to change it)</i>
15
+ <div class="col-sm-6">
16
+ <%= f.password_field :password, autocomplete: "off", class: 'form-control' %>
17
+ </div>
18
+ </div>
19
+ <div class="form-group">
20
+ <%= f.label :password_confirmation, class: 'col-sm-2 control-label' %>
21
+ <div class="col-sm-6">
22
+ <%= f.password_field :password_confirmation, autocomplete: "off", class: 'form-control' %>
23
+ </div>
24
+ </div>
25
+ <div class="form-group">
26
+ <%= f.label :current_password, class: 'col-sm-2 control-label' %>
27
+ <i>(we need your current password to confirm your changes)</i>
28
+ <div class="col-sm-6">
29
+ <%= f.password_field :current_password, autocomplete: "off", class: 'form-control' %>
30
+ </div>
31
+ </div>
32
+ <div class="form-group">
33
+ <div class="col-sm-offset-2 col-sm-6">
34
+ <%= f.submit "Update", class: "btn btn-primary" %>
35
+ </div>
36
+ </div>
37
+ <% end %>
38
+
39
+ <h2>Cancel my account</h2>
40
+
41
+ <hr>
42
+
43
+ <p>Unhappy?
44
+ <%= button_to "Cancel my account", registration_path(resource_name), data: { confirm: "Are you sure?" },
45
+ method: :delete, class: 'btn btn-danger' %>
46
+ </p>
47
+
48
+ <hr>
49
+
50
+ <%= link_to "Back", :back, class: 'btn btn-default' %>
@@ -0,0 +1,34 @@
1
+ <h2>Sign up</h2>
2
+ <hr>
3
+
4
+ <%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { class: 'form-horizontal' }) do |f| %>
5
+ <%= devise_error_messages! %>
6
+ <div class="form-group">
7
+ <%= f.label :email, class: "col-sm-2 control-label" %>
8
+ <div class="col-sm-6">
9
+ <%= f.email_field :email, class: "form-control" %>
10
+ </div>
11
+ </div>
12
+ <div class="form-group">
13
+ <%= f.label :password, class: "col-sm-2 control-label" %>
14
+ <div class="col-sm-6">
15
+ <%= f.password_field :password, autocomplete: "off", class: "form-control" %>
16
+ </div>
17
+ </div>
18
+ <div class="form-group">
19
+ <%= f.label :password_confirmation, class: "col-sm-2 control-label" %>
20
+ <div class="col-sm-6">
21
+ <%= f.password_field :password_confirmation, autocomplete: "off", class: "form-control" %>
22
+ </div>
23
+ </div>
24
+ <div class="form-group">
25
+ <div class="col-sm-offset-2 col-sm-6">
26
+ <%= f.submit "Sign up", class: "btn btn-primary" %>
27
+ </div>
28
+ </div>
29
+ <div class="form-group">
30
+ <div class="col-sm-offset-2 col-sm-6">
31
+ <%= render "devise/shared/links" %>
32
+ </div>
33
+ </div>
34
+ <% end %>
@@ -0,0 +1,36 @@
1
+ <h2>Sign in</h2>
2
+
3
+ <hr>
4
+
5
+ <%= form_for(resource, as: resource_name, url: session_path(resource_name), html: { class: 'form-horizontal' }) do |f| %>
6
+ <div class="form-group">
7
+ <%= f.label :email, class: "col-sm-2 control-label" %>
8
+ <div class="col-sm-6">
9
+ <%= f.email_field :email, autofocus: true, class: "form-control" %>
10
+ </div>
11
+ </div>
12
+ <div class="form-group">
13
+ <%= f.label :password, class: "col-sm-2 control-label" %>
14
+ <div class="col-sm-6">
15
+ <%= f.password_field :password, autocomplete: "off", class: "form-control" %>
16
+ </div>
17
+ </div>
18
+
19
+ <% if devise_mapping.rememberable? -%>
20
+ <div class="form-group">
21
+ <div class="col-sm-6 col-sm-offset-2">
22
+ <%= f.check_box :remember_me %> <%= f.label :remember_me %>
23
+ </div>
24
+ </div>
25
+ <% end -%>
26
+ <div class="form-group">
27
+ <div class="col-sm-6 col-sm-offset-2">
28
+ <%= f.submit "Sign in", class: 'btn btn-primary' %>
29
+ </div>
30
+ </div>
31
+ <div class="form-group">
32
+ <div class="col-sm-6 col-sm-offset-2">
33
+ <%= render "devise/shared/links" %>
34
+ </div>
35
+ </div>
36
+ <% end %>