signup 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.md +69 -0
  4. data/Rakefile +37 -0
  5. data/app/assets/config/signup_manifest.js +2 -0
  6. data/app/assets/javascripts/application.js +13 -0
  7. data/app/assets/stylesheets/application.css +16 -0
  8. data/app/controllers/signup/application_controller.rb +6 -0
  9. data/app/controllers/signup/sessions_controller.rb +33 -0
  10. data/app/controllers/signup/users_controller.rb +96 -0
  11. data/app/helpers/signup/application_helper.rb +12 -0
  12. data/app/helpers/signup/sessions_helper.rb +4 -0
  13. data/app/helpers/signup/users_helper.rb +67 -0
  14. data/app/jobs/signup/application_job.rb +4 -0
  15. data/app/mailers/signup/application_mailer.rb +6 -0
  16. data/app/models/signup/application_record.rb +5 -0
  17. data/app/models/signup/user.rb +43 -0
  18. data/app/views/layouts/signup/_header.html.erb +10 -0
  19. data/app/views/layouts/signup/_inline_css.html.erb +232 -0
  20. data/app/views/layouts/signup/_shim.html.erb +4 -0
  21. data/app/views/layouts/signup/application.html.erb +18 -0
  22. data/app/views/signup/sessions/new.html.erb +31 -0
  23. data/app/views/signup/shared/_flash_notice.html.erb +3 -0
  24. data/app/views/signup/users/_form.html.erb +62 -0
  25. data/app/views/signup/users/edit.html.erb +20 -0
  26. data/app/views/signup/users/index.html.erb +35 -0
  27. data/app/views/signup/users/new.html.erb +18 -0
  28. data/app/views/signup/users/show.html.erb +38 -0
  29. data/app/views/signup/users/signup.html.erb +59 -0
  30. data/config/routes.rb +9 -0
  31. data/db/migrate/20160930163056_create_signup_users.rb +15 -0
  32. data/db/seeds.rb +9 -0
  33. data/lib/signup.rb +3 -0
  34. data/lib/signup/engine.rb +18 -0
  35. data/lib/signup/version.rb +3 -0
  36. data/lib/tasks/signup_tasks.rake +12 -0
  37. metadata +147 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d1fd94565cf0b3f2386304e69d517afafd44b616
4
+ data.tar.gz: 2e4bc7ec5f00e092e33450524605a79bc9b3d23e
5
+ SHA512:
6
+ metadata.gz: bf0f70fe94abb83c6989430eebb63b6b1f204320a78af807980870642313990e1683d3c9f737797dbf76a944cdbf5849acd15bbd495784e22dbac44f55dcd053
7
+ data.tar.gz: 0ee6c8e25828a802d5d1328b0a5641a0bfd34e818e6e278def7cecb9749a7c62b9fcc1f3ce52968f10c021ea11d94ac3d2f53bb8ecc271e20a42436cbab2275f
@@ -0,0 +1,20 @@
1
+ Copyright 2016 hmtanbir
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,69 @@
1
+ # Signup
2
+ It is a simple but very powerful authentication and authorization plug-ins for rails.
3
+
4
+ ## Installation
5
+ **Step 1:** Add this line to your application's Gemfile:
6
+
7
+ ```ruby
8
+ gem 'signup'
9
+ ```
10
+
11
+ And then execute:
12
+ ```bash
13
+ $ bundle
14
+ ```
15
+
16
+ Or install it yourself as:
17
+ ```bash
18
+ $ gem install signup
19
+ ```
20
+
21
+ Follow the step to install this plugins:
22
+
23
+ **Step 2:**
24
+ For installing signup migration:
25
+
26
+ ```
27
+ $ bundle exec rake signup:install
28
+ ```
29
+
30
+ **Step 3:**
31
+ Mount route, open config-> routes.rb and write below code:
32
+
33
+ ```
34
+ mount Signup::Engine, at: '/'
35
+ ```
36
+
37
+ ## Usage
38
+ From your controller, just use:
39
+
40
+ ```
41
+ before_action :authorized?
42
+ ```
43
+
44
+ This will prevent guest user to enter in your view.
45
+
46
+ ## Administrator
47
+ Username: admin@signup.com
48
+
49
+ Password: secret
50
+
51
+ ## Advanced
52
+ Make a dashboard under admin namespace in your project folder as like this code:
53
+
54
+ ```
55
+ $ rails g contoller admin/dashboard index
56
+ ```
57
+ And configure in your project routes as like:
58
+ ```
59
+ namespace :admin do
60
+ get 'dashboard', to:'dashboard#index'
61
+ end
62
+ ```
63
+ For this, it will redirect dashboard after sign in.
64
+
65
+ ## Contributing
66
+ If you find any issue, please inform us in our [github project repo](https://github.com/bdmade/signup)
67
+
68
+ ## License
69
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,37 @@
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 = 'Signup'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("../spec/signup_app/Rakefile", __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+
21
+ load 'rails/tasks/statistics.rake'
22
+
23
+
24
+
25
+ require 'bundler/gem_tasks'
26
+
27
+ require 'rake/testtask'
28
+
29
+ Rake::TestTask.new(:test) do |t|
30
+ t.libs << 'lib'
31
+ t.libs << 'test'
32
+ t.pattern = 'test/**/*_test.rb'
33
+ t.verbose = false
34
+ end
35
+
36
+
37
+ task default: :test
@@ -0,0 +1,2 @@
1
+ //= link_directory ../javascripts/signup .js
2
+ //= link_directory ../stylesheets/signup .css
@@ -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 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_tree signup
@@ -0,0 +1,16 @@
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
+ *
14
+ *= require_tree
15
+ *= require_self
16
+ */
@@ -0,0 +1,6 @@
1
+ module Signup
2
+ class ApplicationController < ActionController::Base
3
+ protect_from_forgery with: :exception
4
+ include Signup::UsersHelper
5
+ end
6
+ end
@@ -0,0 +1,33 @@
1
+ require_dependency 'signup/application_controller'
2
+
3
+ module Signup
4
+ class SessionsController < ApplicationController
5
+ def new
6
+ if logged_in?
7
+ redirect_to main_app.root_path
8
+ end
9
+ end
10
+
11
+ def create
12
+ user = User.find_by(email: params[:session][:email].downcase)
13
+ if user && user.authenticate(params[:session][:password])
14
+ log_in user
15
+ params[:session][:remember_me] == '1' ? remember(user) : forget(user)
16
+ if (main_app.admin_dashboard_path)
17
+ redirect_to main_app.admin_dashboard_path, notice: 'logged in !'
18
+ else
19
+ redirect_to user, notice: 'logged in !'
20
+ end
21
+ else
22
+ flash.now[:danger] = 'Invalid email/password combination' # Not quite right!
23
+ render 'new'
24
+ end
25
+
26
+ end
27
+
28
+ def destroy
29
+ log_out if logged_in?
30
+ redirect_to signup.login_path
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,96 @@
1
+ require_dependency "signup/application_controller"
2
+
3
+ module Signup
4
+ class UsersController < ApplicationController
5
+ before_action :set_user, :match_user, only: [:show, :edit, :update, :destroy]
6
+ before_action :authorized?, :admin?, except: [:signup, :create]
7
+ before_action :go_back_if_not_admin, except: [:signup, :create, :edit, :show, :update]
8
+
9
+ # GET /users
10
+ def index
11
+ @users = User.all
12
+ end
13
+
14
+ # GET /users/1
15
+ def show
16
+ end
17
+
18
+ # GET /users/new
19
+ def new
20
+ @user = User.new
21
+ end
22
+
23
+ # GET /users/1/edit
24
+ def edit
25
+ end
26
+
27
+ # POST /users
28
+ def create
29
+ @user = User.new(user_params)
30
+
31
+ if @user.save
32
+ log_in @user
33
+
34
+ if (main_app.admin_dashboard_path)
35
+ redirect_to main_app.admin_dashboard_path, notice: 'User was successfully created.'
36
+ else
37
+ redirect_to @user, notice: 'User was successfully created.'
38
+ end
39
+
40
+ else
41
+ if current_user.nil?
42
+ render :signup
43
+ else
44
+ render :new
45
+ end
46
+ end
47
+ end
48
+
49
+ # PATCH/PUT /users/1
50
+ def update
51
+ if @user.update(user_params)
52
+ redirect_to @user, notice: 'User was successfully updated.'
53
+ else
54
+ render :edit
55
+ end
56
+ end
57
+
58
+ # DELETE /users/1
59
+ def destroy
60
+ @user.destroy
61
+ redirect_to users_url, notice: 'User was successfully destroyed.'
62
+ end
63
+
64
+ # sign up page
65
+ def signup
66
+ if current_user.nil?
67
+ @user = User.new
68
+ else
69
+ redirect_to user_path(current_user), alert: 'Already signed up !'
70
+ end
71
+ end
72
+
73
+ private
74
+ # Use callbacks to share common setup or constraints between actions.
75
+ def set_user
76
+ @user = User.find(params[:id])
77
+ end
78
+
79
+ # Only allow a trusted parameter "white list" through.
80
+ def user_params
81
+ params.require(:user).permit(:firstname, :lastname, :email, :password, :password_confirmation, :admin)
82
+ end
83
+
84
+ # it matches current user with database and prevents to edit/update other user profile
85
+ def match_user
86
+ unless admin?
87
+ user = User.find(current_user)
88
+
89
+ unless user.id == set_user.id
90
+ redirect_to user_path(current_user), notice: 'You do not have any permission to grant this page !'
91
+ end
92
+ end
93
+ end
94
+
95
+ end
96
+ end
@@ -0,0 +1,12 @@
1
+ module Signup
2
+ module ApplicationHelper
3
+ def full_title(page_title = '')
4
+ base_title = 'Authentication'
5
+ if page_title.empty?
6
+ base_title
7
+ else
8
+ page_title + ' | ' + base_title
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,4 @@
1
+ module Signup
2
+ module SessionsHelper
3
+ end
4
+ end
@@ -0,0 +1,67 @@
1
+ module Signup
2
+ module UsersHelper
3
+ # Logs in the given user.
4
+ def log_in(user)
5
+ session[:user_id] = user.id
6
+ end
7
+
8
+ # Remembers a user in a persistent session.
9
+ def remember(user)
10
+ user.remember
11
+ cookies.permanent.signed[:user_id] = user.id
12
+ cookies.permanent[:remember_token] = user.remember_token
13
+ end
14
+
15
+ # Returns the user corresponding to the remember token cookie.
16
+ def current_user
17
+ if (user_id = session[:user_id])
18
+ @current_user ||= User.find_by(id: user_id)
19
+ elsif (user_id = cookies.signed[:user_id])
20
+ user = User.find_by(id: user_id)
21
+ if user && user.authenticated?(cookies[:remember_token])
22
+ log_in user
23
+ @current_user = user
24
+ end
25
+ end
26
+ end
27
+
28
+ # Returns true if the user is logged in, false otherwise.
29
+ def logged_in?
30
+ !current_user.nil?
31
+ end
32
+
33
+ # Forgets a persistent session.
34
+ def forget(user)
35
+ user.forget
36
+ cookies.delete(:user_id)
37
+ cookies.delete(:remember_token)
38
+ end
39
+
40
+ # Logs out the current user.
41
+ def log_out
42
+ forget(current_user)
43
+ session.delete(:user_id)
44
+ @current_user = nil
45
+ end
46
+
47
+ # check the current user- is it admin ?
48
+ def admin?
49
+ current_user.admin?
50
+ end
51
+
52
+ # if current user is not admin, it redirect to root path
53
+ def go_back_if_not_admin
54
+ unless admin?
55
+ # redirect_to user_path(current_user), notice: "You do not have any permission to grant this page !"
56
+ redirect_to main_app.root_path, notice: 'You do not have any permission to grant this page !'
57
+ end
58
+ end
59
+
60
+ ## before_action :authorized?, except: :index
61
+ def authorized?
62
+ if current_user.nil?
63
+ redirect_to signup.login_path, notice: 'You have to login at first'
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,4 @@
1
+ module Signup
2
+ class ApplicationJob < ActiveJob::Base
3
+ end
4
+ end
@@ -0,0 +1,6 @@
1
+ module Signup
2
+ class ApplicationMailer < ActionMailer::Base
3
+ default from: 'from@example.com'
4
+ layout 'mailer'
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ module Signup
2
+ class ApplicationRecord < ActiveRecord::Base
3
+ self.abstract_class = true
4
+ end
5
+ end
@@ -0,0 +1,43 @@
1
+ module Signup
2
+ class User < ApplicationRecord
3
+ attr_accessor :remember_token
4
+ before_save { self.email = email.downcase }
5
+ validates :firstname, presence: true, length: { maximum: 50 }
6
+ validates :lastname, presence: true, length: { maximum: 50 }
7
+ VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
8
+ validates :email, presence: true, length: { maximum: 255 },
9
+ format: { with: VALID_EMAIL_REGEX },
10
+ uniqueness: { case_sensitive: false }
11
+ has_secure_password
12
+ validates :password, presence: true, length: { minimum: 6 }
13
+
14
+ # Returns the hash digest of the given string.
15
+ def User.digest(string)
16
+ cost = ActiveModel::SecurePassword.min_cost ? BCrypt::Engine::MIN_COST :
17
+ BCrypt::Engine.cost
18
+ BCrypt::Password.create(string, cost: cost)
19
+ end
20
+
21
+ # Returns a random token.
22
+ def self.new_token
23
+ SecureRandom.urlsafe_base64
24
+ end
25
+
26
+ # Remembers a user in the database for use in persistent sessions.
27
+ def remember
28
+ self.remember_token = User.new_token
29
+ update_attribute(:remember_digest, User.digest(remember_token))
30
+ end
31
+
32
+ # Returns true if the given token matches the digest.
33
+ def authenticated?(remember_token)
34
+ return false if remember_digest.nil?
35
+ BCrypt::Password.new(remember_digest).is_password?(remember_token)
36
+ end
37
+
38
+ # Forgets a user.
39
+ def forget
40
+ update_attribute(:remember_digest, nil)
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,10 @@
1
+ <header class="navbar navbar-fixed-top navbar-inverse">
2
+ <div class="container">
3
+ <%= link_to 'Authentication', signup.login_path, id: 'logo' %>
4
+ <nav>
5
+ <ul class="nav navbar-nav navbar-right">
6
+ <li><%= link_to 'Home', main_app.root_path %></li>
7
+ </ul>
8
+ </nav>
9
+ </div>
10
+ </header>
@@ -0,0 +1,232 @@
1
+ <style type="text/css">
2
+ @import url('https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.6/css/bootstrap.min.css');
3
+ /* universal */
4
+ body {
5
+ padding-top: 60px;
6
+ }
7
+
8
+ section {
9
+ overflow: auto;
10
+ }
11
+
12
+ textarea {
13
+ resize: vertical;
14
+ }
15
+
16
+ .center {
17
+ text-align: center;
18
+ }
19
+
20
+ .center h1 {
21
+ margin-bottom: 10px;
22
+ }
23
+
24
+ /* typography */
25
+ h1, h2, h3, h4, h5, h6 {
26
+ line-height: 1;
27
+ }
28
+
29
+ h1 {
30
+ font-size: 3em;
31
+ letter-spacing: -2px;
32
+ margin-bottom: 30px;
33
+ text-align: center;
34
+ }
35
+
36
+ h2 {
37
+ font-size: 1.2em;
38
+ letter-spacing: -1px;
39
+ margin-bottom: 30px;
40
+ text-align: center;
41
+ font-weight: normal;
42
+ color: #777;
43
+ }
44
+
45
+ p {
46
+ font-size: 1.1em;
47
+ line-height: 1.7em;
48
+ }
49
+
50
+ /* header */
51
+ #logo {
52
+ float: left;
53
+ margin-right: 10px;
54
+ font-size: 1.7em;
55
+ color: #fff;
56
+ text-transform: uppercase;
57
+ letter-spacing: -1px;
58
+ padding-top: 9px;
59
+ font-weight: bold;
60
+ }
61
+
62
+ #logo:hover {
63
+ color: #fff;
64
+ text-decoration: none;
65
+ }
66
+
67
+ /* footer */
68
+ footer {
69
+ margin-top: 45px;
70
+ padding-top: 5px;
71
+ border-top: 1px solid #eaeaea;
72
+ color: #777;
73
+ }
74
+
75
+ footer a {
76
+ color: #555;
77
+ }
78
+
79
+ footer a:hover {
80
+ color: #222;
81
+ }
82
+
83
+ footer small {
84
+ float: left;
85
+ }
86
+
87
+ footer ul {
88
+ float: right;
89
+ list-style: none;
90
+ }
91
+
92
+ footer ul li {
93
+ float: left;
94
+ margin-left: 15px;
95
+ }
96
+
97
+ /* miscellaneous */
98
+ .debug_dump {
99
+ clear: both;
100
+ float: left;
101
+ width: 100%;
102
+ margin-top: 45px;
103
+ -moz-box-sizing: border-box;
104
+ -webkit-box-sizing: border-box;
105
+ box-sizing: border-box;
106
+ }
107
+
108
+ /* sidebar */
109
+ aside section.user_info {
110
+ margin-top: 20px;
111
+ }
112
+ aside section {
113
+ padding: 10px 0;
114
+ margin-top: 20px;
115
+ }
116
+ aside section:first-child {
117
+ border: 0;
118
+ padding-top: 0;
119
+ }
120
+ aside section span {
121
+ display: block;
122
+ margin-bottom: 3px;
123
+ line-height: 1;
124
+ }
125
+ aside section h1 {
126
+ font-size: 1.4em;
127
+ text-align: left;
128
+ letter-spacing: -1px;
129
+ margin-bottom: 3px;
130
+ margin-top: 0px;
131
+ }
132
+
133
+ .gravatar {
134
+ float: left;
135
+ margin-right: 10px;
136
+ }
137
+
138
+ .gravatar_edit {
139
+ margin-top: 15px;
140
+ }
141
+
142
+ .stats {
143
+ overflow: auto;
144
+ margin-top: 0;
145
+ padding: 0;
146
+ }
147
+ .stats a {
148
+ float: left;
149
+ padding: 0 10px;
150
+ border-left: 1px solid #222;
151
+ color: gray;
152
+ }
153
+ .stats a:first-child {
154
+ padding-left: 0;
155
+ border: 0;
156
+ }
157
+ .stats a:hover {
158
+ text-decoration: none;
159
+ color: blue;
160
+ }
161
+ .stats strong {
162
+ display: block;
163
+ }
164
+
165
+ .user_avatars {
166
+ overflow: auto;
167
+ margin-top: 10px;
168
+ }
169
+ .user_avatars .gravatar {
170
+ margin: 1px 1px;
171
+ }
172
+ .user_avatars a {
173
+ padding: 0;
174
+ }
175
+
176
+ .users.follow {
177
+ padding: 0;
178
+ }
179
+
180
+ /* forms */
181
+ input, textarea, select, .uneditable-input {
182
+ border: 1px solid #bbb;
183
+ width: 100%;
184
+ margin-bottom: 15px;
185
+ -moz-box-sizing: border-box;
186
+ -webkit-box-sizing: border-box;
187
+ box-sizing: border-box;
188
+ }
189
+
190
+ input {
191
+ height: auto !important;
192
+ }
193
+
194
+ #error_explanation {
195
+ color: red;
196
+ }
197
+ #error_explanation ul {
198
+ color: red;
199
+ margin: 0 0 30px 0;
200
+ }
201
+
202
+ .field_with_errors .form-control {
203
+ color: #a94442;
204
+ }
205
+
206
+ .checkbox {
207
+ margin-top: -10px;
208
+ margin-bottom: 10px;
209
+ }
210
+ .checkbox span {
211
+ margin-left: 20px;
212
+ font-weight: normal;
213
+ }
214
+
215
+ #session_remember_me {
216
+ width: auto;
217
+ margin-left: 0;
218
+ }
219
+
220
+ /* Users index */
221
+ .users {
222
+ list-style: none;
223
+ margin: 0;
224
+ }
225
+ .users li {
226
+ overflow: auto;
227
+ padding: 10px 0;
228
+ border-bottom: 1px solid #222;
229
+ }
230
+
231
+
232
+ </style>
@@ -0,0 +1,4 @@
1
+ <!--[if lt IE 9]>
2
+ <script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/r29/html5.min.js">
3
+ </script>
4
+ <![endif]-->
@@ -0,0 +1,18 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title><%= full_title(yield(:title)) %></title>
5
+ <%= csrf_meta_tags %>
6
+ <%= stylesheet_link_tag 'application', media: 'all',
7
+ 'data-turbolinks-track': 'reload' %>
8
+ <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
9
+ <%= render 'layouts/signup/shim' %>
10
+ <%= render 'layouts/signup/inline_css' %>
11
+ </head>
12
+ <body>
13
+ <%= render 'layouts/signup/header' %>
14
+ <div class="container">
15
+ <%= yield %>
16
+ </div>
17
+ </body>
18
+ </html>
@@ -0,0 +1,31 @@
1
+ <% provide(:title, 'Log in') %>
2
+
3
+ <div class="row">
4
+ <div class="col-md-6 col-md-offset-3">
5
+ <%= render partial: 'signup/shared/flash_notice' %>
6
+ <h1>Log in </h1>
7
+ </div>
8
+ </div>
9
+
10
+ <div class="row">
11
+
12
+ <div class="col-md-6 col-md-offset-3">
13
+ <%= form_for(:session, url: login_path) do |f| %>
14
+
15
+ <%= f.label :email %>
16
+ <%= f.email_field :email, class: 'form-control' %>
17
+
18
+ <%= f.label :password %>
19
+ <%= f.password_field :password, class: 'form-control' %>
20
+
21
+ <%= f.label :remember_me, class: "checkbox inline" do %>
22
+ <%= f.check_box :remember_me %>
23
+ <span>Remember me on this computer</span>
24
+ <% end %>
25
+
26
+ <%= f.submit 'Log in', class: 'btn btn-primary' %>
27
+ <% end %>
28
+
29
+ <p>New user? <%= link_to 'Sign up now!', signup_path %></p>
30
+ </div>
31
+ </div>
@@ -0,0 +1,3 @@
1
+ <% flash.each do |message_type, message| %>
2
+ <div class="alert alert-<%= message_type %>"><%= message %></div>
3
+ <% end %>
@@ -0,0 +1,62 @@
1
+ <% provide(:title, 'Sign up') %>
2
+ <div class="row">
3
+ <div class="col-md-6 col-md-offset-3">
4
+ <%= render partial: 'signup/shared/flash_notice' %>
5
+ </div>
6
+ </div>
7
+ <div class="row">
8
+ <div class="col-md-6 col-md-offset-3">
9
+ <%= form_for(user) do |f| %>
10
+
11
+ <% if user.errors.any? %>
12
+ <div id="error_explanation">
13
+ <h2><%= pluralize(user.errors.count, "error") %> prohibited this user from being saved:</h2>
14
+
15
+ <ul>
16
+ <% user.errors.full_messages.each do |message| %>
17
+ <li><%= message %></li>
18
+ <% end %>
19
+ </ul>
20
+ </div>
21
+ <% end %>
22
+
23
+ <div class="field">
24
+ <%= f.label :firstname %>
25
+ <%= f.text_field :firstname, required: 'require', class: 'form-control' %>
26
+ </div>
27
+
28
+ <div class="field">
29
+ <%= f.label :lastname %>
30
+ <%= f.text_field :lastname, required: 'require', class: 'form-control' %>
31
+ </div>
32
+
33
+ <div class="field">
34
+ <%= f.label :email %>
35
+ <%= f.email_field :email, required: 'require', class: 'form-control' %>
36
+ </div>
37
+
38
+ <div class="field">
39
+ <%= f.label :password %>
40
+ <%= f.password_field :password, required: 'require', class: 'form-control' %>
41
+ </div>
42
+
43
+ <div class="field">
44
+ <%= f.label :password_confirmation %>
45
+ <%= f.password_field :password_confirmation, required: 'require', class: 'form-control' %>
46
+ </div>
47
+
48
+ <% if current_user.admin? %>
49
+ <%= f.label :admin, class: 'checkbox inline' do %>
50
+ <%= f.check_box :admin %>
51
+ <span>Administrator</span>
52
+ <% end %>
53
+ <% else %>
54
+ <%= f.hidden_field :admin, value: 0, required: 'required' %>
55
+ <% end %>
56
+
57
+ <div class="actions">
58
+ <%= f.submit 'Create new account', class: 'btn btn-primary' %>
59
+ </div>
60
+ <% end %>
61
+ </div>
62
+ </div>
@@ -0,0 +1,20 @@
1
+ <h1>Editing User</h1>
2
+
3
+ <%= render 'form', user: @user %>
4
+ <br/>
5
+ <div class="row">
6
+ <div class="col-md-6 col-md-offset-3">
7
+
8
+ <%= link_to 'Show', @user, class: 'btn btn-info' %> |
9
+
10
+ <% if admin? %>
11
+ <%= link_to 'Back', users_path, class: 'btn btn-primary' %>
12
+ <% else %>
13
+ <% if main_app.admin_dashboard_path %>
14
+ <%= link_to 'Back', main_app.admin_dashboard_path, class: 'btn btn-primary' %>
15
+ <% else %>
16
+ <%= link_to 'Back', main_app.root_path, class: 'btn btn-primary' %>
17
+ <% end %>
18
+ <% end %>
19
+ </div>
20
+ </div>
@@ -0,0 +1,35 @@
1
+ <%= render partial: 'signup/shared/flash_notice' %>
2
+
3
+ <h1>Users</h1>
4
+
5
+ <table>
6
+ <thead>
7
+ <tr>
8
+ <th>Firstname</th>
9
+ <th>Lastname</th>
10
+ <th>Email</th>
11
+ <th>Remember</th>
12
+ <th>Admin</th>
13
+ <th colspan="3"></th>
14
+ </tr>
15
+ </thead>
16
+
17
+ <tbody>
18
+ <% @users.each do |user| %>
19
+ <tr>
20
+ <td><%= user.firstname %></td>
21
+ <td><%= user.lastname %></td>
22
+ <td><%= user.email %></td>
23
+ <td><% if user.remember_digest %>true<% else %>false<% end %></td>
24
+ <td><%= user.admin %></td>
25
+ <td><%= link_to 'Show', user %></td>
26
+ <td><%= link_to 'Edit', edit_user_path(user) %></td>
27
+ <td><%= link_to 'Destroy', user, method: :delete, data: { confirm: 'Are you sure?' } %></td>
28
+ </tr>
29
+ <% end %>
30
+ </tbody>
31
+ </table>
32
+
33
+ <br>
34
+
35
+ <%= link_to 'New User', new_user_path %>
@@ -0,0 +1,18 @@
1
+ <h1>New User</h1>
2
+
3
+ <%= render 'form', user: @user %>
4
+ <br/>
5
+ <div class="row">
6
+ <div class="col-md-6 col-md-offset-3">
7
+
8
+ <% if admin? %>
9
+ <%= link_to 'Back', users_path, class: 'btn btn-block btn-info' %>
10
+ <% else %>
11
+ <% if main_app.admin_dashboard_path %>
12
+ <%= link_to 'Back', main_app.admin_dashboard_path, class: 'btn btn-block btn-info' %>
13
+ <% else %>
14
+ <%= link_to 'Back', main_app.root_path, class: 'btn btn-block btn-info' %>
15
+ <% end %>
16
+ <% end %>
17
+ </div>
18
+ </div>
@@ -0,0 +1,38 @@
1
+ <% provide(:title, 'User') %>
2
+ <%= render partial: 'signup/shared/flash_notice' %>
3
+
4
+ <div class="row">
5
+ <div class="col-md-6 col-md-offset-3">
6
+
7
+ <p>
8
+ <strong>Firstname:</strong>
9
+ <%= @user.firstname %>
10
+ </p>
11
+ <p>
12
+ <strong>Lastname:</strong>
13
+ <%= @user.lastname %>
14
+ </p>
15
+ <p>
16
+ <strong>Email:</strong>
17
+ <%= @user.email %>
18
+ </p>
19
+ <% if admin? %>
20
+ <p>
21
+ <strong>Admin:</strong>
22
+ <%= @user.admin %>
23
+ </p>
24
+ <% end %>
25
+
26
+ <%= link_to 'Edit', edit_user_path(@user), class: 'btn btn-info' %> |
27
+
28
+ <% if admin? %>
29
+ <%= link_to 'Back', users_path, class: 'btn btn-primary' %>
30
+ <% else %>
31
+ <% if main_app.admin_dashboard_path %>
32
+ <%= link_to 'Back', main_app.admin_dashboard_path, class: 'btn btn-primary' %>
33
+ <% else %>
34
+ <%= link_to 'Back', main_app.root_path, class: 'btn btn-primary' %>
35
+ <% end %>
36
+ <% end %>
37
+ </div>
38
+ </div>
@@ -0,0 +1,59 @@
1
+ <% provide(:title, 'Sign up') %>
2
+
3
+ <div class="row">
4
+ <div class="col-md-6 col-md-offset-3">
5
+ <%= render partial: 'signup/shared/flash_notice' %>
6
+ <h1>Sign up</h1>
7
+ </div>
8
+ </div>
9
+
10
+ <div class="row">
11
+ <div class="col-md-6 col-md-offset-3">
12
+ <%= form_for @user do |f| %>
13
+ <% if @user.errors.any? %>
14
+ <div id="error_explanation">
15
+ <h2><%= pluralize(@user.errors.count, "error") %> prohibited this user from being saved:</h2>
16
+
17
+ <ul>
18
+ <% @user.errors.full_messages.each do |message| %>
19
+ <li><%= message %></li>
20
+ <% end %>
21
+ </ul>
22
+ </div>
23
+ <% end %>
24
+
25
+ <div class="field">
26
+ <%= f.label :firstname %>
27
+ <%= f.text_field :firstname, required: 'require', class: 'form-control' %>
28
+ </div>
29
+
30
+ <div class="field">
31
+ <%= f.label :lastname %>
32
+ <%= f.text_field :lastname, required: 'require', class: 'form-control' %>
33
+ </div>
34
+
35
+ <div class="field">
36
+ <%= f.label :email %>
37
+ <%= f.email_field :email, required: 'require', class: 'form-control' %>
38
+ </div>
39
+
40
+ <div class="field">
41
+ <%= f.label :password %>
42
+ <%= f.password_field :password, required: 'require', class: 'form-control' %>
43
+ </div>
44
+
45
+ <div class="field">
46
+ <%= f.label :password_confirmation %>
47
+ <%= f.password_field :password_confirmation, required: 'require', class: 'form-control' %>
48
+ </div>
49
+
50
+ <div class="field">
51
+ <%= f.hidden_field :admin, value: 0, required: 'required' %>
52
+ </div>
53
+
54
+ <div class="actions">
55
+ <%= f.submit 'Create my account', class: 'btn btn-primary' %>
56
+ </div>
57
+ <% end %>
58
+ </div>
59
+ </div>
@@ -0,0 +1,9 @@
1
+ Signup::Engine.routes.draw do
2
+ resources :users
3
+ resources :sessions, only: [:new, :create, :destroy]
4
+ get 'signup', to: 'users#signup', as: 'signup'
5
+ post 'signup', to: 'users#create'
6
+ get 'login', to: 'sessions#new', as: 'login'
7
+ post 'login', to: 'sessions#create'
8
+ get 'logout', to: 'sessions#destroy', as: 'logout'
9
+ end
@@ -0,0 +1,15 @@
1
+ class CreateSignupUsers < ActiveRecord::Migration[5.0]
2
+ def change
3
+ create_table :signup_users do |t|
4
+ t.string :firstname
5
+ t.string :lastname
6
+ t.string :email
7
+ t.string :password_digest
8
+ t.string :remember_digest
9
+ t.boolean :admin
10
+
11
+ t.timestamps
12
+ t.index ['email'], name: 'index_users_on_email', unique: true
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,9 @@
1
+ # This file should contain all the record creation needed to seed the database with its default values.
2
+ # The data can then be loaded with the rails db:seed command (or created alongside the database with db:setup).
3
+ #
4
+ # Examples:
5
+ #
6
+ # movies = Movie.create([{ name: 'Star Wars' }, { name: 'Lord of the Rings' }])
7
+ # Character.create(name: 'Luke', movie: movies.first)
8
+
9
+ Signup::User.create(firstname: 'Rails', lastname: 'Administrator', password: 'secret',email:'admin@signup.com',admin: true)
@@ -0,0 +1,3 @@
1
+ require 'signup/engine'
2
+ module Signup
3
+ end
@@ -0,0 +1,18 @@
1
+ require 'bcrypt'
2
+ module Signup
3
+ class Engine < ::Rails::Engine
4
+ isolate_namespace Signup
5
+
6
+ config.generators do |g|
7
+ g.assets false
8
+ end
9
+
10
+ initializer :append_migrations do |app|
11
+ unless app.root.to_s.match root.to_s
12
+ config.paths['db/migrate'].expanded.each do |expanded_path|
13
+ app.config.paths['db/migrate'] << expanded_path
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,3 @@
1
+ module Signup
2
+ VERSION = '1.0.0'
3
+ end
@@ -0,0 +1,12 @@
1
+ # desc "Explaining what the task does"
2
+ namespace :signup do
3
+ task :install do
4
+ sh "sudo sed -i '/protect_from_forgery with: :exception/a\
5
+ include Signup::UsersHelper' app/controllers/application_controller.rb"
6
+ sh 'echo Signup::Engine.load_seed >> db/seeds.rb'
7
+ sh 'rake db:migrate'
8
+ sh 'rake db:seed'
9
+ sh 'clear'
10
+ end
11
+ end
12
+
metadata ADDED
@@ -0,0 +1,147 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: signup
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Hasan Mohammad Tanbir
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-01-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 5.0.0
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 5.0.0.1
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: 5.0.0
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 5.0.0.1
33
+ - !ruby/object:Gem::Dependency
34
+ name: bcrypt
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '3.1'
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 3.1.11
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '3.1'
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 3.1.11
53
+ - !ruby/object:Gem::Dependency
54
+ name: sqlite3
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ type: :development
61
+ prerelease: false
62
+ version_requirements: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ - !ruby/object:Gem::Dependency
68
+ name: bcrypt
69
+ requirement: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ type: :development
75
+ prerelease: false
76
+ version_requirements: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ description: This gem make authentication very simple
82
+ email:
83
+ - tanbir2025@gmail.com
84
+ executables: []
85
+ extensions: []
86
+ extra_rdoc_files: []
87
+ files:
88
+ - MIT-LICENSE
89
+ - README.md
90
+ - Rakefile
91
+ - app/assets/config/signup_manifest.js
92
+ - app/assets/javascripts/application.js
93
+ - app/assets/stylesheets/application.css
94
+ - app/controllers/signup/application_controller.rb
95
+ - app/controllers/signup/sessions_controller.rb
96
+ - app/controllers/signup/users_controller.rb
97
+ - app/helpers/signup/application_helper.rb
98
+ - app/helpers/signup/sessions_helper.rb
99
+ - app/helpers/signup/users_helper.rb
100
+ - app/jobs/signup/application_job.rb
101
+ - app/mailers/signup/application_mailer.rb
102
+ - app/models/signup/application_record.rb
103
+ - app/models/signup/user.rb
104
+ - app/views/layouts/signup/_header.html.erb
105
+ - app/views/layouts/signup/_inline_css.html.erb
106
+ - app/views/layouts/signup/_shim.html.erb
107
+ - app/views/layouts/signup/application.html.erb
108
+ - app/views/signup/sessions/new.html.erb
109
+ - app/views/signup/shared/_flash_notice.html.erb
110
+ - app/views/signup/users/_form.html.erb
111
+ - app/views/signup/users/edit.html.erb
112
+ - app/views/signup/users/index.html.erb
113
+ - app/views/signup/users/new.html.erb
114
+ - app/views/signup/users/show.html.erb
115
+ - app/views/signup/users/signup.html.erb
116
+ - config/routes.rb
117
+ - db/migrate/20160930163056_create_signup_users.rb
118
+ - db/seeds.rb
119
+ - lib/signup.rb
120
+ - lib/signup/engine.rb
121
+ - lib/signup/version.rb
122
+ - lib/tasks/signup_tasks.rake
123
+ homepage: https://github.com/bdmade/signup
124
+ licenses:
125
+ - MIT
126
+ metadata: {}
127
+ post_install_message:
128
+ rdoc_options: []
129
+ require_paths:
130
+ - lib
131
+ required_ruby_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: 2.2.2
136
+ required_rubygems_version: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ requirements: []
142
+ rubyforge_project:
143
+ rubygems_version: 2.5.1
144
+ signing_key:
145
+ specification_version: 4
146
+ summary: It is authentication gem.
147
+ test_files: []