simple_token_authentication 1.0.0.beta.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +674 -0
- data/README.md +134 -0
- data/Rakefile +32 -0
- data/lib/simple_token_authentication.rb +5 -0
- data/lib/simple_token_authentication/acts_as_token_authenticatable.rb +33 -0
- data/lib/simple_token_authentication/acts_as_token_authentication_handler.rb +68 -0
- data/lib/simple_token_authentication/version.rb +3 -0
- data/lib/tasks/simple_token_authentication_tasks.rake +4 -0
- data/test/dummy/README.rdoc +28 -0
- data/test/dummy/Rakefile +6 -0
- data/test/dummy/app/assets/javascripts/application.js +13 -0
- data/test/dummy/app/assets/javascripts/posts.js +2 -0
- data/test/dummy/app/assets/javascripts/private_posts.js +2 -0
- data/test/dummy/app/assets/stylesheets/application.css +13 -0
- data/test/dummy/app/assets/stylesheets/posts.css +4 -0
- data/test/dummy/app/assets/stylesheets/private_posts.css +4 -0
- data/test/dummy/app/assets/stylesheets/scaffold.css +56 -0
- data/test/dummy/app/controllers/application_controller.rb +21 -0
- data/test/dummy/app/controllers/posts_controller.rb +62 -0
- data/test/dummy/app/controllers/private_posts_controller.rb +63 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/helpers/posts_helper.rb +2 -0
- data/test/dummy/app/helpers/private_posts_helper.rb +2 -0
- data/test/dummy/app/models/post.rb +3 -0
- data/test/dummy/app/models/private_post.rb +3 -0
- data/test/dummy/app/models/user.rb +2 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/app/views/posts/_form.html.erb +29 -0
- data/test/dummy/app/views/posts/edit.html.erb +6 -0
- data/test/dummy/app/views/posts/index.html.erb +31 -0
- data/test/dummy/app/views/posts/new.html.erb +5 -0
- data/test/dummy/app/views/posts/show.html.erb +19 -0
- data/test/dummy/app/views/private_posts/_form.html.erb +29 -0
- data/test/dummy/app/views/private_posts/edit.html.erb +6 -0
- data/test/dummy/app/views/private_posts/index.html.erb +31 -0
- data/test/dummy/app/views/private_posts/new.html.erb +5 -0
- data/test/dummy/app/views/private_posts/show.html.erb +19 -0
- data/test/dummy/bin/bundle +3 -0
- data/test/dummy/bin/rails +4 -0
- data/test/dummy/bin/rake +4 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +23 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +29 -0
- data/test/dummy/config/environments/production.rb +80 -0
- data/test/dummy/config/environments/test.rb +36 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/indefinite_articlerize.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/secret_token.rb +12 -0
- data/test/dummy/config/initializers/session_store.rb +3 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +23 -0
- data/test/dummy/config/routes.rb +60 -0
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/db/migrate/20140107041016_create_posts.rb +11 -0
- data/test/dummy/db/migrate/20140107053025_create_users.rb +6 -0
- data/test/dummy/db/migrate/20140107064508_create_private_posts.rb +11 -0
- data/test/dummy/db/schema.rb +35 -0
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/lib/generators/rspec/controller/controller_generator.rb +33 -0
- data/test/dummy/lib/generators/rspec/helper/helper_generator.rb +15 -0
- data/test/dummy/lib/generators/rspec/model/model_generator.rb +22 -0
- data/test/dummy/lib/generators/rspec/scaffold/scaffold_generator.rb +192 -0
- data/test/dummy/lib/templates/rspec/controller/controller_spec.rb +16 -0
- data/test/dummy/lib/templates/rspec/controller/view_spec.rb +5 -0
- data/test/dummy/lib/templates/rspec/helper/helper_spec.rb +0 -0
- data/test/dummy/lib/templates/rspec/model/model_spec.rb +65 -0
- data/test/dummy/lib/templates/rspec/model/model_spec_backup.rb +19 -0
- data/test/dummy/lib/templates/rspec/scaffold/controller_spec.rb +168 -0
- data/test/dummy/lib/templates/rspec/scaffold/edit_spec.rb +31 -0
- data/test/dummy/lib/templates/rspec/scaffold/index_spec.rb +32 -0
- data/test/dummy/lib/templates/rspec/scaffold/new_spec.rb +30 -0
- data/test/dummy/lib/templates/rspec/scaffold/routing_spec.rb +39 -0
- data/test/dummy/lib/templates/rspec/scaffold/show_spec.rb +28 -0
- data/test/dummy/log/development.log +3437 -0
- data/test/dummy/log/test.log +22013 -0
- data/test/dummy/public/404.html +58 -0
- data/test/dummy/public/422.html +58 -0
- data/test/dummy/public/500.html +57 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/spec/controllers/posts_controller_spec.rb +161 -0
- data/test/dummy/spec/controllers/private_posts_controller_spec.rb +41 -0
- data/test/dummy/spec/factories/posts.rb +11 -0
- data/test/dummy/spec/factories/private_posts.rb +11 -0
- data/test/dummy/spec/helpers/posts_helper_spec.rb +0 -0
- data/test/dummy/spec/helpers/private_posts_helper_spec.rb +0 -0
- data/test/dummy/spec/models/post_spec.rb +65 -0
- data/test/dummy/spec/models/private_post_spec.rb +65 -0
- data/test/dummy/spec/models/user_spec.rb +61 -0
- data/test/dummy/spec/requests/posts_spec.rb +16 -0
- data/test/dummy/spec/requests/private_posts_spec.rb +17 -0
- data/test/dummy/spec/routing/posts_routing_spec.rb +35 -0
- data/test/dummy/spec/routing/private_posts_routing_spec.rb +35 -0
- data/test/dummy/spec/spec_helper.rb +42 -0
- data/test/dummy/spec/support/factory_girl.rb +6 -0
- data/test/dummy/spec/views/posts/edit.html.erb_spec.rb +22 -0
- data/test/dummy/spec/views/posts/index.html.erb_spec.rb +26 -0
- data/test/dummy/spec/views/posts/new.html.erb_spec.rb +22 -0
- data/test/dummy/spec/views/posts/show.html.erb_spec.rb +19 -0
- data/test/dummy/spec/views/private_posts/edit.html.erb_spec.rb +22 -0
- data/test/dummy/spec/views/private_posts/index.html.erb_spec.rb +26 -0
- data/test/dummy/spec/views/private_posts/new.html.erb_spec.rb +22 -0
- data/test/dummy/spec/views/private_posts/show.html.erb_spec.rb +19 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/371bf96e99717688ed7313a0c53f4212 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/4050a4e5062ab95c9f32e9b6940821ea +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/416150dc3ac35079c94273cc46e90aa6 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/5384ad85f52d3272dbc64d46ef3876a4 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/5f1a0d05e77ca8b9a1fc2a47e17a8174 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/6fc757c2c8329244ca95d6909865bbc2 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/87b209c0c9da28094a8d5581a21262c6 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/c85016e7bbd4f3adbb7635d01f85d39b +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/d066c004d1fd26ae76a61303a7a18145 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/f56253b5f374fff1a33fbbc9881c9124 +0 -0
- data/test/dummy/tmp/cache/assets/test/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
- data/test/simple_token_authentication_test.rb +7 -0
- data/test/test_helper.rb +15 -0
- metadata +384 -0
@@ -0,0 +1,62 @@
|
|
1
|
+
class PostsController < ApplicationController
|
2
|
+
|
3
|
+
# Please do notice that this controller does NOT call `acts_as_authentication_handler`.
|
4
|
+
# See test/dummy/spec/requests/posts_specs.rb
|
5
|
+
|
6
|
+
before_action :set_post, only: [:show, :edit, :update, :destroy]
|
7
|
+
|
8
|
+
# GET /posts
|
9
|
+
def index
|
10
|
+
@posts = Post.all
|
11
|
+
end
|
12
|
+
|
13
|
+
# GET /posts/1
|
14
|
+
def show
|
15
|
+
end
|
16
|
+
|
17
|
+
# GET /posts/new
|
18
|
+
def new
|
19
|
+
@post = Post.new
|
20
|
+
end
|
21
|
+
|
22
|
+
# GET /posts/1/edit
|
23
|
+
def edit
|
24
|
+
end
|
25
|
+
|
26
|
+
# POST /posts
|
27
|
+
def create
|
28
|
+
@post = Post.new(post_params)
|
29
|
+
|
30
|
+
if @post.save
|
31
|
+
redirect_to @post, notice: 'Post was successfully created.'
|
32
|
+
else
|
33
|
+
render action: 'new'
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# PATCH/PUT /posts/1
|
38
|
+
def update
|
39
|
+
if @post.update(post_params)
|
40
|
+
redirect_to @post, notice: 'Post was successfully updated.'
|
41
|
+
else
|
42
|
+
render action: 'edit'
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
# DELETE /posts/1
|
47
|
+
def destroy
|
48
|
+
@post.destroy
|
49
|
+
redirect_to posts_url, notice: 'Post was successfully destroyed.'
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
# Use callbacks to share common setup or constraints between actions.
|
54
|
+
def set_post
|
55
|
+
@post = Post.find(params[:id])
|
56
|
+
end
|
57
|
+
|
58
|
+
# Only allow a trusted parameter "white list" through.
|
59
|
+
def post_params
|
60
|
+
params.require(:post).permit(:title, :body, :published)
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
class PrivatePostsController < ApplicationController
|
2
|
+
|
3
|
+
# Please do notice that this controller DOES call `acts_as_authentication_handler`.
|
4
|
+
# See test/dummy/spec/requests/posts_specs.rb
|
5
|
+
acts_as_token_authentication_handler
|
6
|
+
|
7
|
+
before_action :set_private_post, only: [:show, :edit, :update, :destroy]
|
8
|
+
|
9
|
+
# GET /private_posts
|
10
|
+
def index
|
11
|
+
@private_posts = PrivatePost.all
|
12
|
+
end
|
13
|
+
|
14
|
+
# GET /private_posts/1
|
15
|
+
def show
|
16
|
+
end
|
17
|
+
|
18
|
+
# GET /private_posts/new
|
19
|
+
def new
|
20
|
+
@private_post = PrivatePost.new
|
21
|
+
end
|
22
|
+
|
23
|
+
# GET /private_posts/1/edit
|
24
|
+
def edit
|
25
|
+
end
|
26
|
+
|
27
|
+
# POST /private_posts
|
28
|
+
def create
|
29
|
+
@private_post = PrivatePost.new(private_post_params)
|
30
|
+
|
31
|
+
if @private_post.save
|
32
|
+
redirect_to @private_post, notice: 'Private post was successfully created.'
|
33
|
+
else
|
34
|
+
render action: 'new'
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
# PATCH/PUT /private_posts/1
|
39
|
+
def update
|
40
|
+
if @private_post.update(private_post_params)
|
41
|
+
redirect_to @private_post, notice: 'Private post was successfully updated.'
|
42
|
+
else
|
43
|
+
render action: 'edit'
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# DELETE /private_posts/1
|
48
|
+
def destroy
|
49
|
+
@private_post.destroy
|
50
|
+
redirect_to private_posts_url, notice: 'Private post was successfully destroyed.'
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
# Use callbacks to share common setup or constraints between actions.
|
55
|
+
def set_private_post
|
56
|
+
@private_post = PrivatePost.find(params[:id])
|
57
|
+
end
|
58
|
+
|
59
|
+
# Only allow a trusted parameter "white list" through.
|
60
|
+
def private_post_params
|
61
|
+
params.require(:private_post).permit(:title, :body, :published)
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>Dummy</title>
|
5
|
+
<%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %>
|
6
|
+
<%= javascript_include_tag "application", "data-turbolinks-track" => true %>
|
7
|
+
<%= csrf_meta_tags %>
|
8
|
+
</head>
|
9
|
+
<body>
|
10
|
+
|
11
|
+
<%= yield %>
|
12
|
+
|
13
|
+
</body>
|
14
|
+
</html>
|
@@ -0,0 +1,29 @@
|
|
1
|
+
<%= form_for(@post) do |f| %>
|
2
|
+
<% if @post.errors.any? %>
|
3
|
+
<div id="error_explanation">
|
4
|
+
<h2><%= pluralize(@post.errors.count, "error") %> prohibited this post from being saved:</h2>
|
5
|
+
|
6
|
+
<ul>
|
7
|
+
<% @post.errors.full_messages.each do |msg| %>
|
8
|
+
<li><%= msg %></li>
|
9
|
+
<% end %>
|
10
|
+
</ul>
|
11
|
+
</div>
|
12
|
+
<% end %>
|
13
|
+
|
14
|
+
<div class="field">
|
15
|
+
<%= f.label :title %><br>
|
16
|
+
<%= f.text_field :title %>
|
17
|
+
</div>
|
18
|
+
<div class="field">
|
19
|
+
<%= f.label :body %><br>
|
20
|
+
<%= f.text_area :body %>
|
21
|
+
</div>
|
22
|
+
<div class="field">
|
23
|
+
<%= f.label :published %><br>
|
24
|
+
<%= f.check_box :published %>
|
25
|
+
</div>
|
26
|
+
<div class="actions">
|
27
|
+
<%= f.submit %>
|
28
|
+
</div>
|
29
|
+
<% end %>
|
@@ -0,0 +1,31 @@
|
|
1
|
+
<h1>Listing posts</h1>
|
2
|
+
|
3
|
+
<table>
|
4
|
+
<thead>
|
5
|
+
<tr>
|
6
|
+
<th>Title</th>
|
7
|
+
<th>Body</th>
|
8
|
+
<th>Published</th>
|
9
|
+
<th></th>
|
10
|
+
<th></th>
|
11
|
+
<th></th>
|
12
|
+
</tr>
|
13
|
+
</thead>
|
14
|
+
|
15
|
+
<tbody>
|
16
|
+
<% @posts.each do |post| %>
|
17
|
+
<tr>
|
18
|
+
<td><%= post.title %></td>
|
19
|
+
<td><%= post.body %></td>
|
20
|
+
<td><%= post.published %></td>
|
21
|
+
<td><%= link_to 'Show', post %></td>
|
22
|
+
<td><%= link_to 'Edit', edit_post_path(post) %></td>
|
23
|
+
<td><%= link_to 'Destroy', post, method: :delete, data: { confirm: 'Are you sure?' } %></td>
|
24
|
+
</tr>
|
25
|
+
<% end %>
|
26
|
+
</tbody>
|
27
|
+
</table>
|
28
|
+
|
29
|
+
<br>
|
30
|
+
|
31
|
+
<%= link_to 'New Post', new_post_path %>
|
@@ -0,0 +1,19 @@
|
|
1
|
+
<p id="notice"><%= notice %></p>
|
2
|
+
|
3
|
+
<p>
|
4
|
+
<strong>Title:</strong>
|
5
|
+
<%= @post.title %>
|
6
|
+
</p>
|
7
|
+
|
8
|
+
<p>
|
9
|
+
<strong>Body:</strong>
|
10
|
+
<%= @post.body %>
|
11
|
+
</p>
|
12
|
+
|
13
|
+
<p>
|
14
|
+
<strong>Published:</strong>
|
15
|
+
<%= @post.published %>
|
16
|
+
</p>
|
17
|
+
|
18
|
+
<%= link_to 'Edit', edit_post_path(@post) %> |
|
19
|
+
<%= link_to 'Back', posts_path %>
|
@@ -0,0 +1,29 @@
|
|
1
|
+
<%= form_for(@private_post) do |f| %>
|
2
|
+
<% if @private_post.errors.any? %>
|
3
|
+
<div id="error_explanation">
|
4
|
+
<h2><%= pluralize(@private_post.errors.count, "error") %> prohibited this private_post from being saved:</h2>
|
5
|
+
|
6
|
+
<ul>
|
7
|
+
<% @private_post.errors.full_messages.each do |msg| %>
|
8
|
+
<li><%= msg %></li>
|
9
|
+
<% end %>
|
10
|
+
</ul>
|
11
|
+
</div>
|
12
|
+
<% end %>
|
13
|
+
|
14
|
+
<div class="field">
|
15
|
+
<%= f.label :title %><br>
|
16
|
+
<%= f.text_field :title %>
|
17
|
+
</div>
|
18
|
+
<div class="field">
|
19
|
+
<%= f.label :body %><br>
|
20
|
+
<%= f.text_area :body %>
|
21
|
+
</div>
|
22
|
+
<div class="field">
|
23
|
+
<%= f.label :published %><br>
|
24
|
+
<%= f.check_box :published %>
|
25
|
+
</div>
|
26
|
+
<div class="actions">
|
27
|
+
<%= f.submit %>
|
28
|
+
</div>
|
29
|
+
<% end %>
|
@@ -0,0 +1,31 @@
|
|
1
|
+
<h1>Listing private_posts</h1>
|
2
|
+
|
3
|
+
<table>
|
4
|
+
<thead>
|
5
|
+
<tr>
|
6
|
+
<th>Title</th>
|
7
|
+
<th>Body</th>
|
8
|
+
<th>Published</th>
|
9
|
+
<th></th>
|
10
|
+
<th></th>
|
11
|
+
<th></th>
|
12
|
+
</tr>
|
13
|
+
</thead>
|
14
|
+
|
15
|
+
<tbody>
|
16
|
+
<% @private_posts.each do |private_post| %>
|
17
|
+
<tr>
|
18
|
+
<td><%= private_post.title %></td>
|
19
|
+
<td><%= private_post.body %></td>
|
20
|
+
<td><%= private_post.published %></td>
|
21
|
+
<td><%= link_to 'Show', private_post %></td>
|
22
|
+
<td><%= link_to 'Edit', edit_private_post_path(private_post) %></td>
|
23
|
+
<td><%= link_to 'Destroy', private_post, method: :delete, data: { confirm: 'Are you sure?' } %></td>
|
24
|
+
</tr>
|
25
|
+
<% end %>
|
26
|
+
</tbody>
|
27
|
+
</table>
|
28
|
+
|
29
|
+
<br>
|
30
|
+
|
31
|
+
<%= link_to 'New Private post', new_private_post_path %>
|
@@ -0,0 +1,19 @@
|
|
1
|
+
<p id="notice"><%= notice %></p>
|
2
|
+
|
3
|
+
<p>
|
4
|
+
<strong>Title:</strong>
|
5
|
+
<%= @private_post.title %>
|
6
|
+
</p>
|
7
|
+
|
8
|
+
<p>
|
9
|
+
<strong>Body:</strong>
|
10
|
+
<%= @private_post.body %>
|
11
|
+
</p>
|
12
|
+
|
13
|
+
<p>
|
14
|
+
<strong>Published:</strong>
|
15
|
+
<%= @private_post.published %>
|
16
|
+
</p>
|
17
|
+
|
18
|
+
<%= link_to 'Edit', edit_private_post_path(@private_post) %> |
|
19
|
+
<%= link_to 'Back', private_posts_path %>
|
data/test/dummy/bin/rake
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require File.expand_path('../boot', __FILE__)
|
2
|
+
|
3
|
+
require 'rails/all'
|
4
|
+
|
5
|
+
Bundler.require(*Rails.groups)
|
6
|
+
require "simple_token_authentication"
|
7
|
+
|
8
|
+
module Dummy
|
9
|
+
class Application < Rails::Application
|
10
|
+
# Settings in config/environments/* take precedence over those specified here.
|
11
|
+
# Application configuration should go into files in config/initializers
|
12
|
+
# -- all .rb files in that directory are automatically loaded.
|
13
|
+
|
14
|
+
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
|
15
|
+
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
|
16
|
+
# config.time_zone = 'Central Time (US & Canada)'
|
17
|
+
|
18
|
+
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
|
19
|
+
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
|
20
|
+
# config.i18n.default_locale = :de
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# SQLite version 3.x
|
2
|
+
# gem install sqlite3
|
3
|
+
#
|
4
|
+
# Ensure the SQLite 3 gem is defined in your Gemfile
|
5
|
+
# gem 'sqlite3'
|
6
|
+
development:
|
7
|
+
adapter: sqlite3
|
8
|
+
database: db/development.sqlite3
|
9
|
+
pool: 5
|
10
|
+
timeout: 5000
|
11
|
+
|
12
|
+
# Warning: The database defined as "test" will be erased and
|
13
|
+
# re-generated from your development database when you run "rake".
|
14
|
+
# Do not set this db to the same as development or production.
|
15
|
+
test:
|
16
|
+
adapter: sqlite3
|
17
|
+
database: db/test.sqlite3
|
18
|
+
pool: 5
|
19
|
+
timeout: 5000
|
20
|
+
|
21
|
+
production:
|
22
|
+
adapter: sqlite3
|
23
|
+
database: db/production.sqlite3
|
24
|
+
pool: 5
|
25
|
+
timeout: 5000
|