monban-generators 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (26) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +41 -0
  6. data/Rakefile +1 -0
  7. data/lib/generators/monban/password_reset/password_reset_generator.rb +50 -0
  8. data/lib/generators/monban/scaffold/scaffold_generator.rb +41 -0
  9. data/lib/generators/monban/templates/app/controllers/password_resets_controller.rb +34 -0
  10. data/lib/generators/monban/templates/app/controllers/sessions_controller.rb +26 -0
  11. data/lib/generators/monban/templates/app/controllers/users_controller.rb +23 -0
  12. data/lib/generators/monban/templates/app/mailers/password_reset_mailer.rb +13 -0
  13. data/lib/generators/monban/templates/app/models/password_reset.rb +22 -0
  14. data/lib/generators/monban/templates/app/views/password_reset_mailer/change_password.html.erb +5 -0
  15. data/lib/generators/monban/templates/app/views/password_resets/create.html.erb +3 -0
  16. data/lib/generators/monban/templates/app/views/password_resets/edit.html.erb +16 -0
  17. data/lib/generators/monban/templates/app/views/password_resets/new.html.erb +16 -0
  18. data/lib/generators/monban/templates/app/views/sessions/new.html.erb +13 -0
  19. data/lib/generators/monban/templates/app/views/users/new.html.erb +13 -0
  20. data/lib/generators/monban/templates/db/migrate/create_password_resets.rb +10 -0
  21. data/lib/generators/monban/templates/password_reset_readme +10 -0
  22. data/lib/generators/monban/templates/scaffold_readme +4 -0
  23. data/lib/monban/generators/version.rb +5 -0
  24. data/lib/monban/generators.rb +7 -0
  25. data/monban-generators.gemspec +24 -0
  26. metadata +111 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3970205c79382c4d6d81b7819090a6eb1dd53eef
4
+ data.tar.gz: ad301e575250f8675f2033db8f608dff0dcd0e11
5
+ SHA512:
6
+ metadata.gz: d8a33e23cadef1c352d712d9343925bcdd71b3d27820ed6ae8e2a493016216f33bd547040cdc5cef92b958a5a9b9290aad1cc3b08865ef71819a242e5d0e5521
7
+ data.tar.gz: 42252bbf45578781d2eda4a56eaff043859ac8c820e809674f5c85589d4578188a7773718f4d58e1ed6687fba86cbab7c4ee5ba690bd402d9a0d82ed397fc97a
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in monban-generators.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 halogenandtoast
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # Monban::Generators
2
+
3
+ Rails generators for adding in authentication components.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'monban-generators'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ ## Generators
16
+
17
+ Currently there are two generators available, but over time more will be added:
18
+
19
+ ### Scaffold
20
+
21
+ You can generate a basic starting point for any monban app by running the following:
22
+
23
+ rails g monban:scaffold
24
+
25
+ ### Password Reset
26
+
27
+ If you'd like to generate basic password reset for your app, you can run:
28
+
29
+ rails g monban:password_reset
30
+
31
+ This will generate the necessary files for an implementation of resetting
32
+ a user's password. It will ask you for host names for development, test
33
+ and production environments in order to make the mailer work.
34
+
35
+ ## Contributing
36
+
37
+ 1. Fork it ( http://github.com/<my-github-username>/monban-generators/fork )
38
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
39
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
40
+ 4. Push to the branch (`git push origin my-new-feature`)
41
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,50 @@
1
+ require 'rails/generators/active_record'
2
+
3
+ module Monban
4
+ module Generators
5
+ class PasswordResetGenerator < Rails::Generators::Base
6
+ include Rails::Generators::Migration
7
+ source_root File.expand_path("../../templates", __FILE__)
8
+
9
+ def add_config_options
10
+ %w(development test production).each do |env|
11
+ host = ask("What is the host to use for #{env}?")
12
+ application(%{config.action_mailer.default_url_options = { :host => "#{host}" }}, env: env)
13
+ end
14
+ end
15
+
16
+ def add_routes
17
+ route("resources :password_resets, only: [:new, :create]")
18
+ route("resources :users, only: [:none] do\n resources :password_resets, only: [:edit, :update]\n end")
19
+ end
20
+
21
+ def add_views
22
+ copy_file 'app/views/password_resets/create.html.erb'
23
+ copy_file 'app/views/password_resets/edit.html.erb'
24
+ copy_file 'app/views/password_resets/new.html.erb'
25
+ copy_file 'app/views/password_reset_mailer/change_password.html.erb'
26
+ end
27
+
28
+ def add_mailers
29
+ template 'app/mailers/password_reset_mailer.rb', 'app/mailers/password_reset_mailer.rb'
30
+ end
31
+
32
+ def add_controllers
33
+ template 'app/controllers/password_resets_controller.rb', 'app/controllers/password_resets_controller.rb'
34
+ end
35
+
36
+ def self.next_migration_number(dir)
37
+ ActiveRecord::Generators::Base.next_migration_number(dir)
38
+ end
39
+
40
+ def add_model
41
+ template 'app/models/password_reset.rb', 'app/models/password_reset.rb'
42
+ migration_template "db/migrate/create_password_resets.rb", "db/migrate/create_password_resets.rb"
43
+ end
44
+
45
+ def display_readme
46
+ readme 'password_reset_readme'
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,41 @@
1
+ require 'rails/generators/active_record'
2
+
3
+ module Monban
4
+ module Generators
5
+ class ScaffoldGenerator < Rails::Generators::Base
6
+ include Rails::Generators::Migration
7
+ source_root File.expand_path("../../templates", __FILE__)
8
+
9
+ def add_routes
10
+ route("resources :users, only: [:new, :create]")
11
+ route("resource :session, only: [:new, :create, :destroy]")
12
+ end
13
+
14
+ def add_views
15
+ copy_file 'app/views/users/new.html.erb'
16
+ copy_file 'app/views/sessions/new.html.erb'
17
+ end
18
+
19
+ def add_controllers
20
+ template 'app/controllers/sessions_controller.rb', 'app/controllers/sessions_controller.rb'
21
+ template 'app/controllers/users_controller.rb', 'app/controllers/users_controller.rb'
22
+ end
23
+
24
+ def add_helper_module_to_application_controller
25
+ inject_into_class "app/controllers/application_controller.rb", ApplicationController, " include Monban::ControllerHelpers\n"
26
+ end
27
+
28
+ def self.next_migration_number(dir)
29
+ ActiveRecord::Generators::Base.next_migration_number(dir)
30
+ end
31
+
32
+ def add_model
33
+ generate 'model', 'user email password_digest'
34
+ end
35
+
36
+ def display_readme
37
+ readme 'scaffold_readme'
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,34 @@
1
+ class PasswordResetsController < ApplicationController
2
+ skip_before_filter :require_login
3
+
4
+ def new
5
+ @password_reset = PasswordReset.new
6
+ end
7
+
8
+ def create
9
+ user = User.find_by(email: params[:password_reset][:email])
10
+ if user
11
+ password_reset = PasswordReset.create(user: user)
12
+ PasswordResetMailer.change_password(password_reset).deliver # NOTE: You'll want to delay this
13
+ end
14
+ end
15
+
16
+ def edit
17
+ @password_reset = PasswordReset.find_by!(token: params[:id], user_id: params[:user_id])
18
+ @user = @password_reset.user
19
+ end
20
+
21
+ def update
22
+ @password_reset = PasswordReset.find_by!(token: params[:id], user_id: params[:user_id])
23
+ @user = @password_reset.user
24
+
25
+ reset_password(@user, params[:password_reset][:password])
26
+
27
+ if @user.save
28
+ sign_in @user
29
+ redirect_to root_path
30
+ else
31
+ render :edit
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,26 @@
1
+ class SessionsController < ApplicationController
2
+ def new
3
+ end
4
+
5
+ def create
6
+ user = authenticate_session(session_params)
7
+
8
+ if sign_in(user)
9
+ redirect_to root_path
10
+ else
11
+ render :new
12
+ end
13
+ end
14
+
15
+ def destroy
16
+ sign_out
17
+ redirect_to root_path
18
+ end
19
+
20
+ private
21
+
22
+ def session_params
23
+ params.require(:session).permit(:email, :password)
24
+ end
25
+ end
26
+
@@ -0,0 +1,23 @@
1
+ class UsersController < ApplicationController
2
+ def new
3
+ @user = User.new
4
+ end
5
+
6
+ def create
7
+ @user = sign_up(user_params)
8
+
9
+ if @user.valid?
10
+ sign_in(@user)
11
+ redirect_to root_path
12
+ else
13
+ render :new
14
+ end
15
+ end
16
+
17
+ private
18
+
19
+ def user_params
20
+ params.require(:user).permit(:email, :password)
21
+ end
22
+ end
23
+
@@ -0,0 +1,13 @@
1
+ class PasswordResetMailer < ActionMailer::Base
2
+ default from: "noreply@example.com" # NOTE: You'll want to change this
3
+
4
+ def change_password(password_reset)
5
+ @password_reset = password_reset
6
+ @user = password_reset.user
7
+
8
+ mail(
9
+ to: @user.email,
10
+ subject: 'Change your password'
11
+ )
12
+ end
13
+ end
@@ -0,0 +1,22 @@
1
+ class PasswordReset < ActiveRecord::Base
2
+ belongs_to :user
3
+ before_create :generate_unique_token
4
+ delegate :email, to: :user, allow_nil: true
5
+
6
+ def to_param
7
+ token
8
+ end
9
+
10
+ private
11
+
12
+ def generate_unique_token
13
+ self.token = generate_token
14
+ while PasswordReset.exists?(token: self.token)
15
+ self.token = generate_token
16
+ end
17
+ end
18
+
19
+ def generate_token
20
+ SecureRandom.hex(20).encode('UTF-8')
21
+ end
22
+ end
@@ -0,0 +1,5 @@
1
+ Someone, hopefully you, requested we send you a link to change your password:
2
+
3
+ <%= edit_user_password_reset_url(@user, @password_reset) %>
4
+
5
+ If you didn't request this, ignore this email. Your password has not been changed.
@@ -0,0 +1,3 @@
1
+ <div class="password-reset">
2
+ <p>You will receive an email within the next few minutes. It contains instructions for changing your password.</p>
3
+ </div>
@@ -0,0 +1,16 @@
1
+ <div class="password-reset">
2
+ <h2>Change your password</h2>
3
+
4
+ <p>Your password has been reset. Choose a new password below.</p>
5
+
6
+ <%= form_for [@user, @password_reset] do |form| %>
7
+ <div class="password-field">
8
+ <%= form.label :password %>
9
+ <%= form.password_field :password %>
10
+ </div>
11
+
12
+ <div class="submit-field">
13
+ <%= form.submit 'Update Password' %>
14
+ </div>
15
+ <% end %>
16
+ </div>
@@ -0,0 +1,16 @@
1
+ <div class="password-reset">
2
+ <h2>Reset your password</h2>
3
+
4
+ <p>To be emailed a link to reset your password, please enter your email address.</p>
5
+
6
+ <%= form_for @password_reset do |form| %>
7
+ <div class="text-field">
8
+ <%= form.label :email %>
9
+ <%= form.email_field :email %>
10
+ </div>
11
+
12
+ <div class="submit-field">
13
+ <%= form.submit 'Reset Password' %>
14
+ </div>
15
+ <% end %>
16
+ </div>
@@ -0,0 +1,13 @@
1
+ <%= form_for :session, url: session_path do |form| %>
2
+ <div>
3
+ <%= form.label :email %>
4
+ <%= form.email_field :email %>
5
+ </div>
6
+ <div>
7
+ <%= form.label :password %>
8
+ <%= form.password_field :password %>
9
+ </div>
10
+ <div>
11
+ <%= form.submit "Sign in" %>
12
+ </div>
13
+ <% end %>
@@ -0,0 +1,13 @@
1
+ <%= form_for @user do |form| %>
2
+ <div>
3
+ <%= form.label :email %>
4
+ <%= form.email_field :email %>
5
+ </div>
6
+ <div>
7
+ <%= form.label :password %>
8
+ <%= form.password_field :password %>
9
+ </div>
10
+ <div>
11
+ <%= form.submit "Sign up" %>
12
+ </div>
13
+ <% end %>
@@ -0,0 +1,10 @@
1
+ class CreatePasswordResets < ActiveRecord::Migration
2
+ def change
3
+ create_table :password_resets do |t|
4
+ t.belongs_to :user, index: true
5
+ t.string :token
6
+
7
+ t.timestamps
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+
2
+
3
+ Final Steps
4
+ run:
5
+ rake db:migrate
6
+
7
+
8
+ You'll want to make the changes noted in:
9
+ - app/controllers/password_resets_controller.rb
10
+ - app/mailers/password_reset_mailer.rb
@@ -0,0 +1,4 @@
1
+
2
+ Final Steps
3
+ run:
4
+ rake db:migrate
@@ -0,0 +1,5 @@
1
+ module Monban
2
+ module Generators
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,7 @@
1
+ require "monban/generators/version"
2
+
3
+ module Monban
4
+ module Generators
5
+ # Your code goes here...
6
+ end
7
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'monban/generators/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "monban-generators"
8
+ spec.version = Monban::Generators::VERSION
9
+ spec.authors = ["halogenandtoast"]
10
+ spec.email = ["halogenandtoast@gmail.com"]
11
+ spec.summary = %q{Rails generators for the monban authentication library}
12
+ spec.description = %q{Generators to add in different forms of user authentication to a rails application.}
13
+ spec.homepage = "http://github.com/halogenandtoast/monban-generators"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.5"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_dependency "monban", "~> 0.0.12"
24
+ end
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: monban-generators
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - halogenandtoast
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: monban
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.0.12
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.0.12
55
+ description: Generators to add in different forms of user authentication to a rails
56
+ application.
57
+ email:
58
+ - halogenandtoast@gmail.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - lib/generators/monban/password_reset/password_reset_generator.rb
69
+ - lib/generators/monban/scaffold/scaffold_generator.rb
70
+ - lib/generators/monban/templates/app/controllers/password_resets_controller.rb
71
+ - lib/generators/monban/templates/app/controllers/sessions_controller.rb
72
+ - lib/generators/monban/templates/app/controllers/users_controller.rb
73
+ - lib/generators/monban/templates/app/mailers/password_reset_mailer.rb
74
+ - lib/generators/monban/templates/app/models/password_reset.rb
75
+ - lib/generators/monban/templates/app/views/password_reset_mailer/change_password.html.erb
76
+ - lib/generators/monban/templates/app/views/password_resets/create.html.erb
77
+ - lib/generators/monban/templates/app/views/password_resets/edit.html.erb
78
+ - lib/generators/monban/templates/app/views/password_resets/new.html.erb
79
+ - lib/generators/monban/templates/app/views/sessions/new.html.erb
80
+ - lib/generators/monban/templates/app/views/users/new.html.erb
81
+ - lib/generators/monban/templates/db/migrate/create_password_resets.rb
82
+ - lib/generators/monban/templates/password_reset_readme
83
+ - lib/generators/monban/templates/scaffold_readme
84
+ - lib/monban/generators.rb
85
+ - lib/monban/generators/version.rb
86
+ - monban-generators.gemspec
87
+ homepage: http://github.com/halogenandtoast/monban-generators
88
+ licenses:
89
+ - MIT
90
+ metadata: {}
91
+ post_install_message:
92
+ rdoc_options: []
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ requirements: []
106
+ rubyforge_project:
107
+ rubygems_version: 2.2.2
108
+ signing_key:
109
+ specification_version: 4
110
+ summary: Rails generators for the monban authentication library
111
+ test_files: []