phoenixbricks 3.2.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/Gemfile +7 -0
- data/LICENSE.txt +674 -0
- data/README.md +85 -0
- data/bin/rbricks +5 -0
- data/lib/railsbricks.rb +115 -0
- data/lib/railsbricks/app_generator.rb +352 -0
- data/lib/railsbricks/assets/config/admin_post_routes.rbr +3 -0
- data/lib/railsbricks/assets/config/application.yml +9 -0
- data/lib/railsbricks/assets/config/contact_routes.rbr +2 -0
- data/lib/railsbricks/assets/config/initializers/devise_email/devise.rb +267 -0
- data/lib/railsbricks/assets/config/initializers/devise_username/devise.rb +267 -0
- data/lib/railsbricks/assets/config/post_routes.rbr +2 -0
- data/lib/railsbricks/assets/config/routes.rb +15 -0
- data/lib/railsbricks/assets/config/unicorn.rb +22 -0
- data/lib/railsbricks/assets/controllers/admin/base_controller.rb +10 -0
- data/lib/railsbricks/assets/controllers/admin/devise_email/users_controller.rb +66 -0
- data/lib/railsbricks/assets/controllers/admin/devise_username/users_controller.rb +69 -0
- data/lib/railsbricks/assets/controllers/admin/posts_controller.rb +73 -0
- data/lib/railsbricks/assets/controllers/brick_contact.rbr +23 -0
- data/lib/railsbricks/assets/controllers/devise_email/application_controller.rb +54 -0
- data/lib/railsbricks/assets/controllers/devise_username/application_controller.rb +56 -0
- data/lib/railsbricks/assets/controllers/pages_controller.rb +13 -0
- data/lib/railsbricks/assets/controllers/posts_controller.rbr +10 -0
- data/lib/railsbricks/assets/database/postgresql.yml +12 -0
- data/lib/railsbricks/assets/database/sqlite3.yml +8 -0
- data/lib/railsbricks/assets/gemfile/Gemfile +44 -0
- data/lib/railsbricks/assets/git/gitignore +30 -0
- data/lib/railsbricks/assets/javascripts/analytics.js.coffee +5 -0
- data/lib/railsbricks/assets/lib/markdown_writer.rb +19 -0
- data/lib/railsbricks/assets/mailers/contact_mailer.rb +13 -0
- data/lib/railsbricks/assets/migrations/20141010133702_create_posts.rb +17 -0
- data/lib/railsbricks/assets/migrations/devise_email/20141010133701_devise_create_users.rb +48 -0
- data/lib/railsbricks/assets/migrations/devise_username/20141010133701_devise_create_users.rb +54 -0
- data/lib/railsbricks/assets/models/devise_email/user.rb +41 -0
- data/lib/railsbricks/assets/models/devise_username/user.rb +57 -0
- data/lib/railsbricks/assets/models/post.rb +30 -0
- data/lib/railsbricks/assets/procfile/Procfile +1 -0
- data/lib/railsbricks/assets/seeds/devise_email/seeds_no_test_users.rb +11 -0
- data/lib/railsbricks/assets/seeds/devise_email/seeds_test_users.rb +24 -0
- data/lib/railsbricks/assets/seeds/devise_username/seeds_no_test_users.rb +12 -0
- data/lib/railsbricks/assets/seeds/devise_username/seeds_test_users.rb +26 -0
- data/lib/railsbricks/assets/stylesheets/application.scss +6 -0
- data/lib/railsbricks/assets/stylesheets/railsbricks_custom.scss +562 -0
- data/lib/railsbricks/assets/views/admin/base/admin_posts_link.rbr +1 -0
- data/lib/railsbricks/assets/views/admin/base/devise_email/index.html.erb +41 -0
- data/lib/railsbricks/assets/views/admin/base/devise_username/index.html.erb +41 -0
- data/lib/railsbricks/assets/views/admin/posts/_form.html.erb +54 -0
- data/lib/railsbricks/assets/views/admin/posts/dashboard.html.erb +9 -0
- data/lib/railsbricks/assets/views/admin/posts/drafts.html.erb +23 -0
- data/lib/railsbricks/assets/views/admin/posts/edit.html.erb +10 -0
- data/lib/railsbricks/assets/views/admin/posts/index.html.erb +23 -0
- data/lib/railsbricks/assets/views/admin/posts/new.html.erb +6 -0
- data/lib/railsbricks/assets/views/admin/users/devise_email/edit.html.erb +65 -0
- data/lib/railsbricks/assets/views/admin/users/devise_email/index.html.erb +54 -0
- data/lib/railsbricks/assets/views/admin/users/devise_username/edit.html.erb +74 -0
- data/lib/railsbricks/assets/views/admin/users/devise_username/index.html.erb +56 -0
- data/lib/railsbricks/assets/views/contact_mailer/contact_message.html.erb +5 -0
- data/lib/railsbricks/assets/views/devise/allow_signup_links.rbr +11 -0
- data/lib/railsbricks/assets/views/devise/devise_email/confirmations/new.html.erb +31 -0
- data/lib/railsbricks/assets/views/devise/devise_email/mailer/confirmation_instructions.html.erb +12 -0
- data/lib/railsbricks/assets/views/devise/devise_email/mailer/reset_password_instructions.html.erb +15 -0
- data/lib/railsbricks/assets/views/devise/devise_email/passwords/edit.html.erb +43 -0
- data/lib/railsbricks/assets/views/devise/devise_email/passwords/new.html.erb +31 -0
- data/lib/railsbricks/assets/views/devise/devise_email/registrations/edit.html.erb +63 -0
- data/lib/railsbricks/assets/views/devise/devise_email/registrations/new.html.erb +49 -0
- data/lib/railsbricks/assets/views/devise/devise_email/sessions/new.html.erb +49 -0
- data/lib/railsbricks/assets/views/devise/devise_email/shared/_links.erb +19 -0
- data/lib/railsbricks/assets/views/devise/devise_username/confirmations/new.html.erb +31 -0
- data/lib/railsbricks/assets/views/devise/devise_username/mailer/confirmation_instructions.html.erb +12 -0
- data/lib/railsbricks/assets/views/devise/devise_username/mailer/reset_password_instructions.html.erb +15 -0
- data/lib/railsbricks/assets/views/devise/devise_username/passwords/edit.html.erb +43 -0
- data/lib/railsbricks/assets/views/devise/devise_username/passwords/new.html.erb +31 -0
- data/lib/railsbricks/assets/views/devise/devise_username/registrations/edit.html.erb +63 -0
- data/lib/railsbricks/assets/views/devise/devise_username/registrations/new.html.erb +58 -0
- data/lib/railsbricks/assets/views/devise/devise_username/sessions/new.html.erb +49 -0
- data/lib/railsbricks/assets/views/devise/devise_username/shared/_links.erb +19 -0
- data/lib/railsbricks/assets/views/layouts/_navigation_links.html.erb +15 -0
- data/lib/railsbricks/assets/views/layouts/brick_analytics.rbr +11 -0
- data/lib/railsbricks/assets/views/pages/contact.html.erb +46 -0
- data/lib/railsbricks/assets/views/pages/inside.html.erb +4 -0
- data/lib/railsbricks/assets/views/pages/posts.html.erb +18 -0
- data/lib/railsbricks/assets/views/pages/show_post.html.erb +6 -0
- data/lib/railsbricks/auth_builder.rb +147 -0
- data/lib/railsbricks/config_helpers.rb +27 -0
- data/lib/railsbricks/config_values.rb +14 -0
- data/lib/railsbricks/errors.rb +18 -0
- data/lib/railsbricks/file_helpers.rb +54 -0
- data/lib/railsbricks/foundation/README.md +24 -0
- data/lib/railsbricks/foundation/Rakefile +6 -0
- data/lib/railsbricks/foundation/app/assets/images/.keep +0 -0
- data/lib/railsbricks/foundation/app/assets/images/apple-touch-icon-precomposed.png +0 -0
- data/lib/railsbricks/foundation/app/assets/images/apple-touch-icon.png +0 -0
- data/lib/railsbricks/foundation/app/assets/images/favicon.ico +0 -0
- data/lib/railsbricks/foundation/app/assets/javascripts/application.js +17 -0
- data/lib/railsbricks/foundation/app/assets/javascripts/common.js +7 -0
- data/lib/railsbricks/foundation/app/controllers/application_controller.rb +5 -0
- data/lib/railsbricks/foundation/app/controllers/concerns/.keep +0 -0
- data/lib/railsbricks/foundation/app/controllers/pages_controller.rb +7 -0
- data/lib/railsbricks/foundation/app/helpers/application_helper.rb +7 -0
- data/lib/railsbricks/foundation/app/helpers/email_helper.rb +5 -0
- data/lib/railsbricks/foundation/app/mailers/.keep +0 -0
- data/lib/railsbricks/foundation/app/models/.keep +0 -0
- data/lib/railsbricks/foundation/app/models/concerns/.keep +0 -0
- data/lib/railsbricks/foundation/app/views/layouts/_footer.html.erb +18 -0
- data/lib/railsbricks/foundation/app/views/layouts/_messages.html.erb +9 -0
- data/lib/railsbricks/foundation/app/views/layouts/_navigation.html.erb +18 -0
- data/lib/railsbricks/foundation/app/views/layouts/_navigation_links.html.erb +3 -0
- data/lib/railsbricks/foundation/app/views/layouts/application.html.erb +38 -0
- data/lib/railsbricks/foundation/app/views/pages/home.html.erb +2 -0
- data/lib/railsbricks/foundation/bin/bundle +3 -0
- data/lib/railsbricks/foundation/bin/rails +4 -0
- data/lib/railsbricks/foundation/bin/rake +4 -0
- data/lib/railsbricks/foundation/config.ru +4 -0
- data/lib/railsbricks/foundation/config/application.rb +34 -0
- data/lib/railsbricks/foundation/config/boot.rb +4 -0
- data/lib/railsbricks/foundation/config/environment.rb +5 -0
- data/lib/railsbricks/foundation/config/environments/development.rb +41 -0
- data/lib/railsbricks/foundation/config/environments/production.rb +95 -0
- data/lib/railsbricks/foundation/config/environments/test.rb +51 -0
- data/lib/railsbricks/foundation/config/initializers/backtrace_silencers.rb +7 -0
- data/lib/railsbricks/foundation/config/initializers/date_format.rb +27 -0
- data/lib/railsbricks/foundation/config/initializers/filter_parameter_logging.rb +4 -0
- data/lib/railsbricks/foundation/config/initializers/friendly_id.rb +88 -0
- data/lib/railsbricks/foundation/config/initializers/inflections.rb +16 -0
- data/lib/railsbricks/foundation/config/initializers/kaminari_config.rb +10 -0
- data/lib/railsbricks/foundation/config/initializers/mime_types.rb +5 -0
- data/lib/railsbricks/foundation/config/initializers/secret_token.rb +25 -0
- data/lib/railsbricks/foundation/config/initializers/session_store.rb +3 -0
- data/lib/railsbricks/foundation/config/initializers/wrap_parameters.rb +14 -0
- data/lib/railsbricks/foundation/config/locales/en.yml +23 -0
- data/lib/railsbricks/foundation/config/routes.rb +7 -0
- data/lib/railsbricks/foundation/db/migrate/20131103142222_create_friendly_id_slugs.rb +15 -0
- data/lib/railsbricks/foundation/db/schema.rb +29 -0
- data/lib/railsbricks/foundation/db/seeds.rb +0 -0
- data/lib/railsbricks/foundation/lib/assets/.keep +0 -0
- data/lib/railsbricks/foundation/lib/tasks/.keep +0 -0
- data/lib/railsbricks/foundation/public/404.html +58 -0
- data/lib/railsbricks/foundation/public/422.html +58 -0
- data/lib/railsbricks/foundation/public/500.html +57 -0
- data/lib/railsbricks/foundation/public/favicon.ico +0 -0
- data/lib/railsbricks/foundation/public/robots.txt +5 -0
- data/lib/railsbricks/foundation/vendor/assets/javascripts/.keep +0 -0
- data/lib/railsbricks/foundation/vendor/assets/stylesheets/.keep +0 -0
- data/lib/railsbricks/gemfile_builder.rb +118 -0
- data/lib/railsbricks/menu.rb +533 -0
- data/lib/railsbricks/post_builder.rb +103 -0
- data/lib/railsbricks/string_helpers.rb +39 -0
- data/lib/railsbricks/style_builder.rb +97 -0
- data/lib/railsbricks/ui_helpers.rb +11 -0
- data/lib/railsbricks/validator.rb +68 -0
- data/lib/railsbricks/version.rb +34 -0
- data/railsbricks.gemspec +16 -0
- metadata +198 -0
@@ -0,0 +1,15 @@
|
|
1
|
+
BRICK_APP_NAME::Application.routes.draw do
|
2
|
+
root "pages#home"
|
3
|
+
get "home", to: "pages#home", as: "home"
|
4
|
+
get "inside", to: "pages#inside", as: "inside"
|
5
|
+
BRICK_CONTACT_ROUTES
|
6
|
+
BRICK_POST_ROUTES
|
7
|
+
devise_for :users
|
8
|
+
|
9
|
+
namespace :admin do
|
10
|
+
root "base#index"
|
11
|
+
resources :users
|
12
|
+
BRICK_ADMIN_POST_ROUTES
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
worker_processes Integer(ENV["WEB_CONCURRENCY"] || 3)
|
2
|
+
timeout 15
|
3
|
+
preload_app true
|
4
|
+
|
5
|
+
before_fork do |server, worker|
|
6
|
+
Signal.trap 'TERM' do
|
7
|
+
puts 'Unicorn master intercepting TERM and sending myself QUIT instead'
|
8
|
+
Process.kill 'QUIT', Process.pid
|
9
|
+
end
|
10
|
+
|
11
|
+
defined?(ActiveRecord::Base) and
|
12
|
+
ActiveRecord::Base.connection.disconnect!
|
13
|
+
end
|
14
|
+
|
15
|
+
after_fork do |server, worker|
|
16
|
+
Signal.trap 'TERM' do
|
17
|
+
puts 'Unicorn worker intercepting TERM and doing nothing. Wait for master to send QUIT'
|
18
|
+
end
|
19
|
+
|
20
|
+
defined?(ActiveRecord::Base) and
|
21
|
+
ActiveRecord::Base.establish_connection
|
22
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
class Admin::UsersController < Admin::BaseController
|
2
|
+
|
3
|
+
before_action :set_user, only: [
|
4
|
+
:show,
|
5
|
+
:edit,
|
6
|
+
:update,
|
7
|
+
:destroy
|
8
|
+
]
|
9
|
+
|
10
|
+
|
11
|
+
def index
|
12
|
+
@users = User.search_and_order(params[:search], params[:page])
|
13
|
+
end
|
14
|
+
|
15
|
+
def show
|
16
|
+
redirect_to edit_admin_user_path(params[:id])
|
17
|
+
end
|
18
|
+
|
19
|
+
def edit
|
20
|
+
end
|
21
|
+
|
22
|
+
def update
|
23
|
+
old_email = @user.email
|
24
|
+
new_params = user_params.dup
|
25
|
+
new_params[:email] = new_params[:email].strip
|
26
|
+
|
27
|
+
@user.email = new_params[:email]
|
28
|
+
@user.password = new_params[:password] if new_params[:password].strip.length > 0
|
29
|
+
@user.password_confirmation = new_params[:password_confirmation] if new_params[:password_confirmation].strip.length > 0
|
30
|
+
|
31
|
+
if current_user.id != @user.id
|
32
|
+
@user.admin = new_params[:admin]=="0" ? false : true
|
33
|
+
@user.locked = new_params[:locked]=="0" ? false : true
|
34
|
+
end
|
35
|
+
|
36
|
+
if @user.valid?
|
37
|
+
@user.skip_reconfirmation!
|
38
|
+
@user.save
|
39
|
+
redirect_to admin_users_path, notice: "#{@user.email} updated."
|
40
|
+
else
|
41
|
+
flash[:alert] = "#{old_email} couldn't be updated."
|
42
|
+
render :edit
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def set_user
|
50
|
+
@user = User.find(params[:id])
|
51
|
+
rescue
|
52
|
+
flash[:alert] = "The user with an id of #{params[:id]} doesn't exist."
|
53
|
+
redirect_to admin_users_path
|
54
|
+
end
|
55
|
+
|
56
|
+
def user_params
|
57
|
+
params.require(:user).permit(
|
58
|
+
:email,
|
59
|
+
:password,
|
60
|
+
:password_confirmation,
|
61
|
+
:admin,
|
62
|
+
:locked
|
63
|
+
)
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
class Admin::UsersController < Admin::BaseController
|
2
|
+
|
3
|
+
before_action :set_user, only: [
|
4
|
+
:show,
|
5
|
+
:edit,
|
6
|
+
:update,
|
7
|
+
:destroy
|
8
|
+
]
|
9
|
+
|
10
|
+
|
11
|
+
def index
|
12
|
+
@users = User.search_and_order(params[:search], params[:page])
|
13
|
+
end
|
14
|
+
|
15
|
+
def show
|
16
|
+
redirect_to edit_admin_user_path(params[:id])
|
17
|
+
end
|
18
|
+
|
19
|
+
def edit
|
20
|
+
end
|
21
|
+
|
22
|
+
def update
|
23
|
+
old_username = @user.username
|
24
|
+
new_params = user_params.dup
|
25
|
+
new_params[:username] = new_params[:username].strip
|
26
|
+
new_params[:email] = new_params[:email].strip
|
27
|
+
|
28
|
+
@user.username = new_params[:username]
|
29
|
+
@user.email = new_params[:email]
|
30
|
+
@user.password = new_params[:password] if new_params[:password].strip.length > 0
|
31
|
+
@user.password_confirmation = new_params[:password_confirmation] if new_params[:password_confirmation].strip.length > 0
|
32
|
+
|
33
|
+
if current_user.id != @user.id
|
34
|
+
@user.admin = new_params[:admin]=="0" ? false : true
|
35
|
+
@user.locked = new_params[:locked]=="0" ? false : true
|
36
|
+
end
|
37
|
+
|
38
|
+
if @user.valid?
|
39
|
+
@user.skip_reconfirmation!
|
40
|
+
@user.save
|
41
|
+
redirect_to admin_users_path, notice: "#{@user.username} updated."
|
42
|
+
else
|
43
|
+
flash[:alert] = "#{old_username} couldn't be updated."
|
44
|
+
render :edit
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def set_user
|
52
|
+
@user = User.friendly.find(params[:id])
|
53
|
+
rescue
|
54
|
+
flash[:alert] = "The user with an id of #{params[:id]} doesn't exist."
|
55
|
+
redirect_to admin_users_path
|
56
|
+
end
|
57
|
+
|
58
|
+
def user_params
|
59
|
+
params.require(:user).permit(
|
60
|
+
:username,
|
61
|
+
:email,
|
62
|
+
:password,
|
63
|
+
:password_confirmation,
|
64
|
+
:admin,
|
65
|
+
:locked
|
66
|
+
)
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
class Admin::PostsController < Admin::BaseController
|
2
|
+
|
3
|
+
before_action :set_post, only: [
|
4
|
+
:edit,
|
5
|
+
:update,
|
6
|
+
:destroy
|
7
|
+
]
|
8
|
+
|
9
|
+
|
10
|
+
def dashboard
|
11
|
+
@published_post_count = Post.published.count
|
12
|
+
@draft_post_count = Post.drafted.count
|
13
|
+
end
|
14
|
+
|
15
|
+
def index
|
16
|
+
@posts = Post.published.page(params[:page]).per(50)
|
17
|
+
end
|
18
|
+
|
19
|
+
def drafts
|
20
|
+
@posts = Post.drafted.page(params[:page]).per(50)
|
21
|
+
end
|
22
|
+
|
23
|
+
def new
|
24
|
+
@post = Post.new
|
25
|
+
end
|
26
|
+
|
27
|
+
def create
|
28
|
+
@post = Post.new(post_params)
|
29
|
+
@post.user_id = current_user.id
|
30
|
+
if @post.save
|
31
|
+
redirect_to admin_posts_dashboard_path, notice: "New post published."
|
32
|
+
else
|
33
|
+
flash[:alert] = "Post not published."
|
34
|
+
render :new
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def edit
|
39
|
+
end
|
40
|
+
|
41
|
+
def update
|
42
|
+
@post.slug = nil
|
43
|
+
if @post.update(post_params)
|
44
|
+
redirect_to admin_posts_dashboard_path, notice: "Post successfully edited."
|
45
|
+
else
|
46
|
+
flash[:alert] = "The post was not edited."
|
47
|
+
render :edit
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def destroy
|
52
|
+
@post.destroy
|
53
|
+
redirect_to admin_posts_path, notice: "The post has been deleted."
|
54
|
+
end
|
55
|
+
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
def set_post
|
60
|
+
@post = Post.friendly.find(params[:id])
|
61
|
+
end
|
62
|
+
|
63
|
+
def post_params
|
64
|
+
params.require(:post).permit(
|
65
|
+
:title,
|
66
|
+
:content_md,
|
67
|
+
:draft,
|
68
|
+
:updated_at
|
69
|
+
)
|
70
|
+
end
|
71
|
+
|
72
|
+
|
73
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
|
2
|
+
def email
|
3
|
+
@name = params[:name]
|
4
|
+
@email = params[:email]
|
5
|
+
@message = params[:message]
|
6
|
+
|
7
|
+
if @name.blank?
|
8
|
+
flash[:alert] = "Please enter your name before sending your message. Thank you."
|
9
|
+
render :contact
|
10
|
+
elsif @email.blank? || @email.scan(/\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i).size < 1
|
11
|
+
flash[:alert] = "You must provide a valid email address before sending your message. Thank you."
|
12
|
+
render :contact
|
13
|
+
elsif @message.blank? || @message.length < 10
|
14
|
+
flash[:alert] = "Your message is empty. Requires at least 10 characters. Nothing to send."
|
15
|
+
render :contact
|
16
|
+
elsif @message.scan(/<a href=/).size > 0 || @message.scan(/\[url=/).size > 0 || @message.scan(/\[link=/).size > 0 || @message.scan(/http:\/\//).size > 0
|
17
|
+
flash[:alert] = "You can't send links. Thank you for your understanding."
|
18
|
+
render :contact
|
19
|
+
else
|
20
|
+
ContactMailer.contact_message(@name,@email,@message).deliver_now
|
21
|
+
redirect_to root_path, notice: "Your message was sent. Thank you."
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
class ApplicationController < ActionController::Base
|
2
|
+
# Prevent CSRF attacks by raising an exception.
|
3
|
+
# For APIs, you may want to use :null_session instead.
|
4
|
+
protect_from_forgery with: :exception
|
5
|
+
|
6
|
+
before_filter :configure_permitted_parameters, if: :devise_controller?
|
7
|
+
before_filter :reject_locked!, if: :devise_controller?
|
8
|
+
|
9
|
+
|
10
|
+
# Devise permitted params
|
11
|
+
def configure_permitted_parameters
|
12
|
+
devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(
|
13
|
+
:email,
|
14
|
+
:password,
|
15
|
+
:password_confirmation)
|
16
|
+
}
|
17
|
+
devise_parameter_sanitizer.for(:account_update) { |u| u.permit(
|
18
|
+
:email,
|
19
|
+
:password,
|
20
|
+
:password_confirmation,
|
21
|
+
:current_password
|
22
|
+
)
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
# Redirects on successful sign in
|
27
|
+
def after_sign_in_path_for(resource)
|
28
|
+
inside_path
|
29
|
+
end
|
30
|
+
|
31
|
+
# Auto-sign out locked users
|
32
|
+
def reject_locked!
|
33
|
+
if current_user && current_user.locked?
|
34
|
+
sign_out current_user
|
35
|
+
user_session = nil
|
36
|
+
current_user = nil
|
37
|
+
flash[:alert] = "Your account is locked."
|
38
|
+
flash[:notice] = nil
|
39
|
+
redirect_to root_url
|
40
|
+
end
|
41
|
+
end
|
42
|
+
helper_method :reject_locked!
|
43
|
+
|
44
|
+
# Only permits admin users
|
45
|
+
def require_admin!
|
46
|
+
authenticate_user!
|
47
|
+
|
48
|
+
if current_user && !current_user.admin?
|
49
|
+
redirect_to root_path
|
50
|
+
end
|
51
|
+
end
|
52
|
+
helper_method :require_admin!
|
53
|
+
|
54
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
class ApplicationController < ActionController::Base
|
2
|
+
# Prevent CSRF attacks by raising an exception.
|
3
|
+
# For APIs, you may want to use :null_session instead.
|
4
|
+
protect_from_forgery with: :exception
|
5
|
+
|
6
|
+
before_filter :configure_permitted_parameters, if: :devise_controller?
|
7
|
+
before_filter :reject_locked!, if: :devise_controller?
|
8
|
+
|
9
|
+
|
10
|
+
# Devise permitted params
|
11
|
+
def configure_permitted_parameters
|
12
|
+
devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(
|
13
|
+
:username,
|
14
|
+
:email,
|
15
|
+
:password,
|
16
|
+
:password_confirmation)
|
17
|
+
}
|
18
|
+
devise_parameter_sanitizer.for(:account_update) { |u| u.permit(
|
19
|
+
:username,
|
20
|
+
:email,
|
21
|
+
:password,
|
22
|
+
:password_confirmation,
|
23
|
+
:current_password
|
24
|
+
)
|
25
|
+
}
|
26
|
+
end
|
27
|
+
|
28
|
+
# Redirects on successful sign in
|
29
|
+
def after_sign_in_path_for(resource)
|
30
|
+
inside_path
|
31
|
+
end
|
32
|
+
|
33
|
+
# Auto-sign out locked users
|
34
|
+
def reject_locked!
|
35
|
+
if current_user && current_user.locked?
|
36
|
+
sign_out current_user
|
37
|
+
user_session = nil
|
38
|
+
current_user = nil
|
39
|
+
flash[:alert] = "Your account is locked."
|
40
|
+
flash[:notice] = nil
|
41
|
+
redirect_to root_url
|
42
|
+
end
|
43
|
+
end
|
44
|
+
helper_method :reject_locked!
|
45
|
+
|
46
|
+
# Only permits admin users
|
47
|
+
def require_admin!
|
48
|
+
authenticate_user!
|
49
|
+
|
50
|
+
if current_user && !current_user.admin?
|
51
|
+
redirect_to root_path
|
52
|
+
end
|
53
|
+
end
|
54
|
+
helper_method :require_admin!
|
55
|
+
|
56
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
# PostgreSQL
|
2
|
+
# Ensure the PostgreSQL gem is defined in your Gemfile
|
3
|
+
# gem 'pg'
|
4
|
+
development:
|
5
|
+
adapter: postgresql
|
6
|
+
encoding: utf8
|
7
|
+
database: BRICK_DB_NAME
|
8
|
+
username: BRICK_DB_USERNAME
|
9
|
+
host: BRICK_DB_SERVER
|
10
|
+
pool: 5
|
11
|
+
port: BRICK_DB_PORT
|
12
|
+
BRICK_DB_PASSWORD
|