cartoonist 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,9 +1,9 @@
1
1
  class AdminController < ApplicationController
2
2
  before_filter :ensure_ssl!, :except => [:cache_cron, :tweet_cron]
3
- before_filter :check_admin!, :except => [:cache_cron, :index, :sign_in, :tweet_cron]
3
+ before_filter :check_admin!, :except => [:cache_cron, :tweet_cron]
4
4
 
5
5
  def index
6
- redirect_to "/admin/sign_in"
6
+ redirect_to "/admin/main"
7
7
  end
8
8
 
9
9
  def backup
@@ -65,29 +65,4 @@ class AdminController < ApplicationController
65
65
  rescue
66
66
  render :text => "Failure.", :layout => false
67
67
  end
68
-
69
- def sign_in
70
- return redirect_to "/admin/main" if session[:admin]
71
- return redirect_to "/settings/initial_setup" if initial_setup_required?
72
-
73
- if request.post?
74
- user = Setting[:admin_users][params[:username]]
75
-
76
- if user && params[:password] == user[:password]
77
- session[:admin] = true
78
- session[:user] = user[:name]
79
- return redirect_to "/admin/main"
80
- else
81
- flash[:error] = "Wrong username or password!"
82
- return redirect_to "/admin/sign_in"
83
- end
84
- end
85
-
86
- render :layout => "sign_in"
87
- end
88
-
89
- def logout
90
- reset_session
91
- redirect_to "/admin/sign_in"
92
- end
93
68
  end
@@ -4,7 +4,7 @@ class ApplicationController < ActionController::Base
4
4
 
5
5
  private
6
6
  def initial_setup_required?
7
- Setting[:admin_users].empty?
7
+ User.count == 0
8
8
  end
9
9
 
10
10
  def ensure_ssl!
@@ -13,7 +13,19 @@ class ApplicationController < ActionController::Base
13
13
  end
14
14
 
15
15
  def check_admin!
16
- raise ActionController::RoutingError.new("Not Found") unless session[:admin]
16
+ if initial_setup_required?
17
+ redirect_to "/settings/initial_setup"
18
+ else
19
+ authenticate_user!
20
+ end
21
+ end
22
+
23
+ def after_sign_out_path_for(resource_or_scope)
24
+ "/admin"
25
+ end
26
+
27
+ def after_sign_in_path_for(resource_or_scope)
28
+ "/admin"
17
29
  end
18
30
 
19
31
  def check_mobile
@@ -20,16 +20,18 @@ class SettingsController < ApplicationController
20
20
  end
21
21
 
22
22
  def initial_setup
23
- return redirect_to "/admin/sign_in" unless initial_setup_required?
24
- render :layout => "sign_in"
23
+ return redirect_to "/admin" unless initial_setup_required?
24
+ render :layout => "initial_setup"
25
25
  end
26
26
 
27
27
  def save_initial_setup
28
- return redirect_to "/admin/sign_in" unless initial_setup_required?
29
- Setting[:admin_users] = { params[:admin_username] => { :name => params[:admin_name], :password => params[:admin_password] } }
28
+ return redirect_to "/admin" unless initial_setup_required?
30
29
  Setting[:domain] = params[:domain]
31
30
  Setting[:site_name] = params[:site_name]
32
31
  Setting[:secret_token] = SecureRandom.hex 30
33
- redirect_to "/admin/sign_in"
32
+ Setting[:devise_pepper] = SecureRandom.hex 64
33
+ # This MUST go AFTER we set the pepper
34
+ User.create! :email => params[:admin_email], :password => params[:admin_password], :name => params[:admin_name]
35
+ redirect_to "/admin"
34
36
  end
35
37
  end
@@ -0,0 +1,6 @@
1
+ class User < ActiveRecord::Base
2
+ devise :database_authenticatable, :recoverable, :rememberable, :trackable, :validatable
3
+
4
+ # Setup accessible (or protected) attributes for your model
5
+ attr_accessible :email, :password, :password_confirmation, :remember_me, :name
6
+ end
@@ -8,12 +8,15 @@
8
8
  <link rel="shortcut icon" href="http://<%= Setting[:domain] %><%= asset_path Cartoonist::Theme.favicon %>" type="image/x-icon" />
9
9
  </head>
10
10
  <body>
11
- <p class="tabs">
12
- <% Cartoonist::Admin::Tab.all.each do |tab| %>
13
- <a class="tab" href="<%= Cartoonist::Admin::Tab[tab] %>"><%= t tab, :scope => "admin.layout.tab" %></a>
14
- <% end %>
15
- | <%= t "admin.layout.user_heading", :user => session[:user] %> <a href="/admin/logout"><%= t "admin.layout.logout" %></a>
16
- </p>
11
+ <%= form_tag "/users/sign_out", :method => :delete do %>
12
+ <p class="tabs">
13
+ <% Cartoonist::Admin::Tab.all.each do |tab| %>
14
+ <a class="tab" href="<%= Cartoonist::Admin::Tab[tab] %>"><%= t tab, :scope => "admin.layout.tab" %></a>
15
+ <% end %>
16
+ | <%= t "admin.layout.user_heading", :user => current_user.name %>
17
+ <input type="submit" value="<%= t "admin.layout.logout" %>" />
18
+ </p>
19
+ <% end %>
17
20
 
18
21
  <% if content_for? :subtabs %>
19
22
  <p class="subtabs">
@@ -1,7 +1,7 @@
1
1
  <!DOCTYPE html>
2
2
  <html>
3
3
  <head>
4
- <title>Sign In</title>
4
+ <title>Initial Setup</title>
5
5
  <%= csrf_meta_tags %>
6
6
  <link rel="icon" href="http://<%= Setting[:domain] %><%= asset_path Cartoonist::Theme.favicon %>" type="image/x-icon" />
7
7
  <link rel="shortcut icon" href="http://<%= Setting[:domain] %><%= asset_path Cartoonist::Theme.favicon %>" type="image/x-icon" />
@@ -0,0 +1,24 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Sign In</title>
5
+ <%= csrf_meta_tags %>
6
+ <link rel="icon" href="http://<%= Setting[:domain] %><%= asset_path Cartoonist::Theme.favicon %>" type="image/x-icon" />
7
+ <link rel="shortcut icon" href="http://<%= Setting[:domain] %><%= asset_path Cartoonist::Theme.favicon %>" type="image/x-icon" />
8
+ </head>
9
+ <body>
10
+ <% if flash[:notice] %>
11
+ <div class="notice">
12
+ <%= flash[:notice] %>
13
+ </div>
14
+ <% end %>
15
+
16
+ <% if flash[:alert] %>
17
+ <div class="alert">
18
+ <%= flash[:alert] %>
19
+ </div>
20
+ <% end %>
21
+
22
+ <%= yield %>
23
+ </body>
24
+ </html>
@@ -1,6 +1,6 @@
1
1
  <%= form_tag "/settings/save_initial_setup", :method => :post do %>
2
2
  <p>
3
- <%= t "settings.initial_setup.username" %><input type="text" name="admin_username" value="<%= t "settings.initial_setup.default_username" %>" autofocus="autofocus" />
3
+ <%= t "settings.initial_setup.email" %><input type="text" name="admin_email" value="<%= t "settings.initial_setup.default_email" %>" autofocus="autofocus" />
4
4
  </p>
5
5
 
6
6
  <p>
data/cartoonist.gemspec CHANGED
@@ -10,4 +10,9 @@ Gem::Specification.new do |s|
10
10
  s.files = `git ls-files`.split("\n")
11
11
  s.require_paths = ["lib"]
12
12
  s.homepage = "http://reasonnumber.com/cartoonist"
13
+ s.add_dependency "devise", "~> 2.0.0"
14
+ s.add_dependency "jquery-rails", "~> 2.0.0"
15
+ s.add_dependency "railties", "~> 3.2.0"
16
+ s.add_dependency "redcarpet", "~> 2.1.0"
17
+ s.add_dependency "twitter", "~> 2.2.0"
13
18
  end
@@ -0,0 +1,57 @@
1
+ # Additional translations at https://github.com/plataformatec/devise/wiki/I18n
2
+
3
+ en:
4
+ errors:
5
+ messages:
6
+ expired: "has expired, please request a new one"
7
+ not_found: "not found"
8
+ already_confirmed: "was already confirmed, please try signing in"
9
+ not_locked: "was not locked"
10
+ not_saved:
11
+ one: "1 error prohibited this %{resource} from being saved:"
12
+ other: "%{count} errors prohibited this %{resource} from being saved:"
13
+
14
+ devise:
15
+ failure:
16
+ already_authenticated: 'You are already signed in.'
17
+ unauthenticated: 'You need to sign in or sign up before continuing.'
18
+ unconfirmed: 'You have to confirm your account before continuing.'
19
+ locked: 'Your account is locked.'
20
+ invalid: 'Invalid email or password.'
21
+ invalid_token: 'Invalid authentication token.'
22
+ timeout: 'Your session expired, please sign in again to continue.'
23
+ inactive: 'Your account was not activated yet.'
24
+ sessions:
25
+ signed_in: 'Signed in successfully.'
26
+ signed_out: 'Signed out successfully.'
27
+ passwords:
28
+ send_instructions: 'You will receive an email with instructions about how to reset your password in a few minutes.'
29
+ updated: 'Your password was changed successfully. You are now signed in.'
30
+ updated_not_active: 'Your password was changed successfully.'
31
+ send_paranoid_instructions: "If your e-mail exists on our database, you will receive a password recovery link on your e-mail"
32
+ confirmations:
33
+ send_instructions: 'You will receive an email with instructions about how to confirm your account in a few minutes.'
34
+ send_paranoid_instructions: 'If your e-mail exists on our database, you will receive an email with instructions about how to confirm your account in a few minutes.'
35
+ confirmed: 'Your account was successfully confirmed. You are now signed in.'
36
+ registrations:
37
+ signed_up: 'Welcome! You have signed up successfully.'
38
+ signed_up_but_unconfirmed: 'A message with a confirmation link has been sent to your email address. Please open the link to activate your account.'
39
+ signed_up_but_inactive: 'You have signed up successfully. However, we could not sign you in because your account is not yet activated.'
40
+ signed_up_but_locked: 'You have signed up successfully. However, we could not sign you in because your account is locked.'
41
+ updated: 'You updated your account successfully.'
42
+ update_needs_confirmation: "You updated your account successfully, but we need to verify your new email address. Please check your email and click on the confirm link to finalize confirming your new email address."
43
+ destroyed: 'Bye! Your account was successfully cancelled. We hope to see you again soon.'
44
+ unlocks:
45
+ send_instructions: 'You will receive an email with instructions about how to unlock your account in a few minutes.'
46
+ unlocked: 'Your account has been unlocked successfully. Please sign in to continue.'
47
+ send_paranoid_instructions: 'If your account exists, you will receive an email with instructions about how to unlock it in a few minutes.'
48
+ omniauth_callbacks:
49
+ success: 'Successfully authorized from %{kind} account.'
50
+ failure: 'Could not authorize you from %{kind} because "%{reason}".'
51
+ mailer:
52
+ confirmation_instructions:
53
+ subject: 'Confirmation instructions'
54
+ reset_password_instructions:
55
+ subject: 'Reset password instructions'
56
+ unlock_instructions:
57
+ subject: 'Unlock Instructions'
@@ -43,9 +43,10 @@ en:
43
43
  www_tmp: www tmp
44
44
  settings:
45
45
  initial_setup:
46
+ default_email: you@youremail.com
46
47
  default_name: Anonymous
47
- default_username: admin
48
48
  domain: "Domain: "
49
+ email: "Email: "
49
50
  name: "Name: "
50
51
  password: "Password: "
51
52
  save: Save
@@ -67,6 +68,7 @@ en:
67
68
  site_name: "Site Name: "
68
69
  site_heading: "Site Heading: "
69
70
  site_update_description: "Site Update Description: "
71
+ root_path: "Root Path: "
70
72
  theme: "Theme: "
71
73
  schedule: "Schedule: "
72
74
  copyright_starting_year: "Copyright Starting Year: "
@@ -86,8 +88,8 @@ en:
86
88
  disqus_comic_category: "Disqus Comic Category: "
87
89
  disqus_blog_post_category: "Disqus Blog Post Category: "
88
90
  disqus_page_category: "Disqus Page Category: "
89
- admin_users: "Admin Users: "
90
91
  secret_token: "Secret Token: "
92
+ devise_pepper: "Devise Pepper: "
91
93
  tabs:
92
94
  advanced: Advanced
93
95
  general: General
@@ -0,0 +1,50 @@
1
+ class DeviseCreateUsers < ActiveRecord::Migration
2
+ def change
3
+ create_table(:users) do |t|
4
+ ## Database authenticatable
5
+ t.string :email, :null => false, :default => ""
6
+ t.string :encrypted_password, :null => false, :default => ""
7
+
8
+ ## Recoverable
9
+ t.string :reset_password_token
10
+ t.datetime :reset_password_sent_at
11
+
12
+ ## Rememberable
13
+ t.datetime :remember_created_at
14
+
15
+ ## Trackable
16
+ t.integer :sign_in_count, :default => 0
17
+ t.datetime :current_sign_in_at
18
+ t.datetime :last_sign_in_at
19
+ t.string :current_sign_in_ip
20
+ t.string :last_sign_in_ip
21
+
22
+ ## Encryptable
23
+ # t.string :password_salt
24
+
25
+ ## Confirmable
26
+ # t.string :confirmation_token
27
+ # t.datetime :confirmed_at
28
+ # t.datetime :confirmation_sent_at
29
+ # t.string :unconfirmed_email # Only if using reconfirmable
30
+
31
+ ## Lockable
32
+ # t.integer :failed_attempts, :default => 0 # Only if lock strategy is :failed_attempts
33
+ # t.string :unlock_token # Only if unlock strategy is :email or :both
34
+ # t.datetime :locked_at
35
+
36
+ ## Token authenticatable
37
+ # t.string :authentication_token
38
+
39
+
40
+ t.string :name
41
+ t.timestamps
42
+ end
43
+
44
+ add_index :users, :email, :unique => true
45
+ add_index :users, :reset_password_token, :unique => true
46
+ # add_index :users, :confirmation_token, :unique => true
47
+ # add_index :users, :unlock_token, :unique => true
48
+ # add_index :users, :authentication_token, :unique => true
49
+ end
50
+ end
data/lib/cartoonist.rb CHANGED
@@ -1,3 +1,8 @@
1
+ require "devise"
2
+ require "jquery-rails"
3
+ require "redcarpet"
4
+ require "twitter"
5
+
1
6
  module Cartoonist
2
7
  module Admin
3
8
  class Tab
@@ -147,6 +152,34 @@ module Cartoonist
147
152
  end
148
153
  end
149
154
 
155
+ class RootPath
156
+ @@all = []
157
+ @@paths = {}
158
+
159
+ class << self
160
+ def all
161
+ @@all
162
+ end
163
+
164
+ def add(path_name, path)
165
+ (@@all << path_name.to_sym).sort! unless @@all.include? path_name.to_sym
166
+ @@paths[path_name.to_sym] = path unless @@paths.include? path_name.to_sym
167
+ end
168
+
169
+ def [](key)
170
+ @@paths[key.to_sym]
171
+ end
172
+
173
+ def current_key
174
+ Setting[:root_path]
175
+ end
176
+
177
+ def current
178
+ self[current_key]
179
+ end
180
+ end
181
+ end
182
+
150
183
  class Routes
151
184
  @@begin = []
152
185
  @@middle = []
@@ -1,5 +1,229 @@
1
1
  module Cartoonist
2
2
  class Engine < ::Rails::Engine
3
+ # Use this hook to configure devise mailer, warden hooks and so forth.
4
+ # Many of these configuration options can be set straight in your model.
5
+ Devise.setup do |devise_config|
6
+ # ==> Mailer Configuration
7
+ # Configure the e-mail address which will be shown in Devise::Mailer,
8
+ # note that it will be overwritten if you use your own mailer class with default "from" parameter.
9
+ devise_config.mailer_sender = "no-reply@willbesetlater.com"
10
+
11
+ # Configure the class responsible to send e-mails.
12
+ # devise_config.mailer = "Devise::Mailer"
13
+
14
+ # Automatically apply schema changes in tableless databases
15
+ devise_config.apply_schema = false
16
+
17
+ # ==> ORM configuration
18
+ # Load and configure the ORM. Supports :active_record (default) and
19
+ # :mongoid (bson_ext recommended) by default. Other ORMs may be
20
+ # available as additional gems.
21
+ require "devise/orm/active_record"
22
+
23
+ # ==> Configuration for any authentication mechanism
24
+ # Configure which keys are used when authenticating a user. The default is
25
+ # just :email. You can configure it to use [:username, :subdomain], so for
26
+ # authenticating a user, both parameters are required. Remember that those
27
+ # parameters are used only when authenticating and not when retrieving from
28
+ # session. If you need permissions, you should implement that in a before filter.
29
+ # You can also supply a hash where the value is a boolean determining whether
30
+ # or not authentication should be aborted when the value is not present.
31
+ # devise_config.authentication_keys = [ :email ]
32
+
33
+ # Configure parameters from the request object used for authentication. Each entry
34
+ # given should be a request method and it will automatically be passed to the
35
+ # find_for_authentication method and considered in your model lookup. For instance,
36
+ # if you set :request_keys to [:subdomain], :subdomain will be used on authentication.
37
+ # The same considerations mentioned for authentication_keys also apply to request_keys.
38
+ # devise_config.request_keys = []
39
+
40
+ # Configure which authentication keys should be case-insensitive.
41
+ # These keys will be downcased upon creating or modifying a user and when used
42
+ # to authenticate or find a user. Default is :email.
43
+ devise_config.case_insensitive_keys = [ :email ]
44
+
45
+ # Configure which authentication keys should have whitespace stripped.
46
+ # These keys will have whitespace before and after removed upon creating or
47
+ # modifying a user and when used to authenticate or find a user. Default is :email.
48
+ devise_config.strip_whitespace_keys = [ :email ]
49
+
50
+ # Tell if authentication through request.params is enabled. True by default.
51
+ # It can be set to an array that will enable params authentication only for the
52
+ # given strategies, for example, `devise_config.params_authenticatable = [:database]` will
53
+ # enable it only for database (email + password) authentication.
54
+ # devise_config.params_authenticatable = true
55
+
56
+ # Tell if authentication through HTTP Basic Auth is enabled. False by default.
57
+ # It can be set to an array that will enable http authentication only for the
58
+ # given strategies, for example, `devise_config.http_authenticatable = [:token]` will
59
+ # enable it only for token authentication.
60
+ # devise_config.http_authenticatable = false
61
+
62
+ # If http headers should be returned for AJAX requests. True by default.
63
+ # devise_config.http_authenticatable_on_xhr = true
64
+
65
+ # The realm used in Http Basic Authentication. "Application" by default.
66
+ # devise_config.http_authentication_realm = "Application"
67
+
68
+ # It will change confirmation, password recovery and other workflows
69
+ # to behave the same regardless if the e-mail provided was right or wrong.
70
+ # Does not affect registerable.
71
+ # devise_config.paranoid = true
72
+
73
+ # By default Devise will store the user in session. You can skip storage for
74
+ # :http_auth and :token_auth by adding those symbols to the array below.
75
+ # Notice that if you are skipping storage for all authentication paths, you
76
+ # may want to disable generating routes to Devise's sessions controller by
77
+ # passing :skip => :sessions to `devise_for` in your config/routes.rb
78
+ devise_config.skip_session_storage = [:http_auth]
79
+
80
+ # ==> Configuration for :database_authenticatable
81
+ # For bcrypt, this is the cost for hashing the password and defaults to 10. If
82
+ # using other encryptors, it sets how many times you want the password re-encrypted.
83
+ #
84
+ # Limiting the stretches to just one in testing will increase the performance of
85
+ # your test suite dramatically. However, it is STRONGLY RECOMMENDED to not use
86
+ # a value less than 10 in other environments.
87
+ devise_config.stretches = Rails.env.test? ? 1 : 10
88
+
89
+ # Setup a pepper to generate the encrypted password.
90
+ devise_config.pepper = "temporary... this is initialized later, in the to_prepare block"
91
+
92
+ # ==> Configuration for :confirmable
93
+ # A period that the user is allowed to access the website even without
94
+ # confirming his account. For instance, if set to 2.days, the user will be
95
+ # able to access the website for two days without confirming his account,
96
+ # access will be blocked just in the third day. Default is 0.days, meaning
97
+ # the user cannot access the website without confirming his account.
98
+ # devise_config.allow_unconfirmed_access_for = 2.days
99
+
100
+ # If true, requires any email changes to be confirmed (exctly the same way as
101
+ # initial account confirmation) to be applied. Requires additional unconfirmed_email
102
+ # db field (see migrations). Until confirmed new email is stored in
103
+ # unconfirmed email column, and copied to email column on successful confirmation.
104
+ devise_config.reconfirmable = true
105
+
106
+ # Defines which key will be used when confirming an account
107
+ # devise_config.confirmation_keys = [ :email ]
108
+
109
+ # ==> Configuration for :rememberable
110
+ # The time the user will be remembered without asking for credentials again.
111
+ # devise_config.remember_for = 2.weeks
112
+
113
+ # If true, extends the user's remember period when remembered via cookie.
114
+ # devise_config.extend_remember_period = false
115
+
116
+ # If true, uses the password salt as remember token. This should be turned
117
+ # to false if you are not using database authenticatable.
118
+ devise_config.use_salt_as_remember_token = true
119
+
120
+ # Options to be passed to the created cookie. For instance, you can set
121
+ # :secure => true in order to force SSL only cookies.
122
+ # devise_config.cookie_options = {}
123
+
124
+ # ==> Configuration for :validatable
125
+ # Range for password length. Default is 6..128.
126
+ # devise_config.password_length = 6..128
127
+
128
+ # Email regex used to validate email formats. It simply asserts that
129
+ # an one (and only one) @ exists in the given string. This is mainly
130
+ # to give user feedback and not to assert the e-mail validity.
131
+ # devise_config.email_regexp = /\A[^@]+@[^@]+\z/
132
+
133
+ # ==> Configuration for :timeoutable
134
+ # The time you want to timeout the user session without activity. After this
135
+ # time the user will be asked for credentials again. Default is 30 minutes.
136
+ # devise_config.timeout_in = 30.minutes
137
+
138
+ # ==> Configuration for :lockable
139
+ # Defines which strategy will be used to lock an account.
140
+ # :failed_attempts = Locks an account after a number of failed attempts to sign in.
141
+ # :none = No lock strategy. You should handle locking by yourself.
142
+ # devise_config.lock_strategy = :failed_attempts
143
+
144
+ # Defines which key will be used when locking and unlocking an account
145
+ # devise_config.unlock_keys = [ :email ]
146
+
147
+ # Defines which strategy will be used to unlock an account.
148
+ # :email = Sends an unlock link to the user email
149
+ # :time = Re-enables login after a certain amount of time (see :unlock_in below)
150
+ # :both = Enables both strategies
151
+ # :none = No unlock strategy. You should handle unlocking by yourself.
152
+ # devise_config.unlock_strategy = :both
153
+
154
+ # Number of authentication tries before locking an account if lock_strategy
155
+ # is failed attempts.
156
+ # devise_config.maximum_attempts = 20
157
+
158
+ # Time interval to unlock the account if :time is enabled as unlock_strategy.
159
+ # devise_config.unlock_in = 1.hour
160
+
161
+ # ==> Configuration for :recoverable
162
+ #
163
+ # Defines which key will be used when recovering the password for an account
164
+ # devise_config.reset_password_keys = [ :email ]
165
+
166
+ # Time interval you can reset your password with a reset password key.
167
+ # Don't put a too small interval or your users won't have the time to
168
+ # change their passwords.
169
+ devise_config.reset_password_within = 6.hours
170
+
171
+ # ==> Configuration for :encryptable
172
+ # Allow you to use another encryption algorithm besides bcrypt (default). You can use
173
+ # :sha1, :sha512 or encryptors from others authentication tools as :clearance_sha1,
174
+ # :authlogic_sha512 (then you should set stretches above to 20 for default behavior)
175
+ # and :restful_authentication_sha1 (then you should set stretches to 10, and copy
176
+ # REST_AUTH_SITE_KEY to pepper)
177
+ # devise_config.encryptor = :sha512
178
+
179
+ # ==> Configuration for :token_authenticatable
180
+ # Defines name of the authentication token params key
181
+ # devise_config.token_authentication_key = :auth_token
182
+
183
+ # ==> Scopes configuration
184
+ # Turn scoped views on. Before rendering "sessions/new", it will first check for
185
+ # "users/sessions/new". It's turned off by default because it's slower if you
186
+ # are using only default views.
187
+ # devise_config.scoped_views = false
188
+
189
+ # Configure the default scope given to Warden. By default it's the first
190
+ # devise role declared in your routes (usually :user).
191
+ # devise_config.default_scope = :user
192
+
193
+ # Configure sign_out behavior.
194
+ # Sign_out action can be scoped (i.e. /users/sign_out affects only :user scope).
195
+ # The default is true, which means any logout action will sign out all active scopes.
196
+ # devise_config.sign_out_all_scopes = true
197
+
198
+ # ==> Navigation configuration
199
+ # Lists the formats that should be treated as navigational. Formats like
200
+ # :html, should redirect to the sign in page when the user does not have
201
+ # access, but formats like :xml or :json, should return 401.
202
+ #
203
+ # If you have any extra navigational formats, like :iphone or :mobile, you
204
+ # should add them to the navigational formats lists.
205
+ #
206
+ # The "*/*" below is required to match Internet Explorer requests.
207
+ # devise_config.navigational_formats = ["*/*", :html]
208
+
209
+ # The default HTTP method used to sign out a resource. Default is :delete.
210
+ devise_config.sign_out_via = :delete
211
+
212
+ # ==> OmniAuth
213
+ # Add a new OmniAuth provider. Check the wiki for more information on setting
214
+ # up on your models and hooks.
215
+ # devise_config.omniauth :github, 'APP_ID', 'APP_SECRET', :scope => 'user,public_repo'
216
+
217
+ # ==> Warden configuration
218
+ # If you want to use other strategies, that are not supported by Devise, or
219
+ # change the failure app, you can configure them inside the devise_config.warden block.
220
+ #
221
+ # devise_config.warden do |manager|
222
+ # manager.intercept_401 = false
223
+ # manager.default_strategies(:scope => :user).unshift :some_external_strategy
224
+ # end
225
+ end
226
+
3
227
  config.before_initialize do
4
228
  # Add in various configuration from plugins
5
229
  Rails.application.config.assets.precompile += ["admin.css"]
@@ -14,6 +238,8 @@ module Cartoonist
14
238
  end
15
239
 
16
240
  config.to_prepare do
241
+ Devise::SessionsController.layout "users"
242
+
17
243
  if Setting.table_exists?
18
244
  secret_token_changed = lambda do
19
245
  # Your secret key for verifying the integrity of signed cookies.
@@ -24,11 +250,18 @@ module Cartoonist
24
250
  end
25
251
 
26
252
  twitter_auth_changed = lambda do
27
- Twitter.configure do |config|
28
- config.consumer_key = Setting[:twitter_consumer_key]
29
- config.consumer_secret = Setting[:twitter_consumer_secret]
30
- config.oauth_token = Setting[:twitter_oauth_token]
31
- config.oauth_token_secret = Setting[:twitter_oauth_token_secret]
253
+ Twitter.configure do |twitter_config|
254
+ twitter_config.consumer_key = Setting[:twitter_consumer_key]
255
+ twitter_config.consumer_secret = Setting[:twitter_consumer_secret]
256
+ twitter_config.oauth_token = Setting[:twitter_oauth_token]
257
+ twitter_config.oauth_token_secret = Setting[:twitter_oauth_token_secret]
258
+ end
259
+ end
260
+
261
+ devise_pepper_changed = lambda do
262
+ Devise.setup do |devise_config|
263
+ devise_config.mailer_sender = "no-reply@#{Setting[:domain]}"
264
+ devise_config.pepper = Setting[:devise_pepper]
32
265
  end
33
266
  end
34
267
 
@@ -36,12 +269,12 @@ module Cartoonist
36
269
  Setting.define :site_name, :order => 2
37
270
  Setting.define :site_heading, :order => 3
38
271
  Setting.define :site_update_description, :order => 4
39
- Setting.define :theme, :type => :symbol, :default => :cartoonist_default_theme, :order => 5, :select_from => lambda { Cartoonist::Theme.all }
40
- Setting.define :schedule, :type => :array, :default => [:monday, :wednesday, :friday], :order => 6
41
- Setting.define :copyright_starting_year, :type => :int, :order => 7
42
- Setting.define :copyright_owners, :order => 8
43
- Setting.define :default_title, :order => 9
44
- Setting.define :admin_users, :type => :hash, :order => 10
272
+ Setting.define :root_path, :type => :symbol, :default => Cartoonist::RootPath.all.first, :order => 5, :select_from => lambda { Cartoonist::RootPath.all }, :onchange => lambda { Rails.application.reload_routes! }
273
+ Setting.define :theme, :type => :symbol, :default => :cartoonist_default_theme, :order => 6, :select_from => lambda { Cartoonist::Theme.all }
274
+ Setting.define :schedule, :type => :array, :default => [:monday, :wednesday, :friday], :order => 7
275
+ Setting.define :copyright_starting_year, :type => :int, :order => 8
276
+ Setting.define :copyright_owners, :order => 9
277
+ Setting.define :default_title, :order => 10
45
278
 
46
279
  Setting::Tab.define :social_and_analytics, :order => 1 do
47
280
  Setting::Section.define :google_analytics, :order => 1 do
@@ -70,10 +303,12 @@ module Cartoonist
70
303
 
71
304
  Setting::Tab.define :advanced, :order => 2 do
72
305
  Setting.define :secret_token, :default => "ThisTokenMustBeRegenerated....", :onchange => secret_token_changed
306
+ Setting.define :devise_pepper, :default => "ThisTokenMustBeRegenerated....", :onchange => devise_pepper_changed
73
307
  end
74
308
 
75
309
  secret_token_changed.call
76
310
  twitter_auth_changed.call
311
+ devise_pepper_changed.call
77
312
  end
78
313
  end
79
314
 
@@ -89,11 +324,21 @@ module Cartoonist
89
324
  Setting.order(:id).all
90
325
  end
91
326
 
327
+ Cartoonist::Backup.for :users do
328
+ User.order(:id).all
329
+ end
330
+
331
+ Cartoonist::Routes.add_begin do
332
+ root :to => Cartoonist::RootPath.current
333
+ end
334
+
92
335
  Cartoonist::Routes.add do
93
336
  match "favicon" => "site#favicon", :defaults => { :format => "ico" }
94
337
  match "sitemap" => "site#sitemap", :defaults => { :format => "xml" }
95
338
  match "robots" => "site#robots", :defaults => { :format => "text" }
96
339
 
340
+ devise_for :users
341
+
97
342
  resources :cache do
98
343
  collection do
99
344
  post "expire_www"
@@ -113,11 +358,8 @@ module Cartoonist
113
358
  collection do
114
359
  get "cache_cron"
115
360
  get "backup"
116
- get "logout"
117
361
  get "main"
118
362
  get "reload"
119
- get "sign_in"
120
- post "sign_in"
121
363
  get "tweet_cron"
122
364
  end
123
365
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cartoonist
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,8 +9,63 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-16 00:00:00.000000000 Z
13
- dependencies: []
12
+ date: 2012-04-17 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: devise
16
+ requirement: &16995580 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 2.0.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *16995580
25
+ - !ruby/object:Gem::Dependency
26
+ name: jquery-rails
27
+ requirement: &16993360 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: 2.0.0
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *16993360
36
+ - !ruby/object:Gem::Dependency
37
+ name: railties
38
+ requirement: &16988280 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: 3.2.0
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *16988280
47
+ - !ruby/object:Gem::Dependency
48
+ name: redcarpet
49
+ requirement: &16987660 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 2.1.0
55
+ type: :runtime
56
+ prerelease: false
57
+ version_requirements: *16987660
58
+ - !ruby/object:Gem::Dependency
59
+ name: twitter
60
+ requirement: &16986940 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ~>
64
+ - !ruby/object:Gem::Version
65
+ version: 2.2.0
66
+ type: :runtime
67
+ prerelease: false
68
+ version_requirements: *16986940
14
69
  description: This provides the main functionality and plugin api for Cartoonist.
15
70
  email: reasonnumber@gmail.com
16
71
  executables: []
@@ -37,24 +92,27 @@ files:
37
92
  - app/models/sitemap_entry.rb
38
93
  - app/models/static_cache.rb
39
94
  - app/models/tweetable.rb
95
+ - app/models/user.rb
40
96
  - app/views/admin/main.html.erb
41
- - app/views/admin/sign_in.html.erb
42
97
  - app/views/cache/index.html.erb
43
98
  - app/views/layouts/admin.html.erb
44
99
  - app/views/layouts/application.html.erb
45
100
  - app/views/layouts/application.rss.erb
46
101
  - app/views/layouts/application.xml.erb
47
102
  - app/views/layouts/general_admin.html.erb
48
- - app/views/layouts/sign_in.html.erb
103
+ - app/views/layouts/initial_setup.html.erb
104
+ - app/views/layouts/users.html.erb
49
105
  - app/views/settings/initial_setup.html.erb
50
106
  - app/views/settings/show.html.erb
51
107
  - app/views/site/robots.text.erb
52
108
  - app/views/site/sitemap.xml.erb
53
109
  - app/views/static_cache/index.html.erb
54
110
  - cartoonist.gemspec
111
+ - config/locales/devise.en.yml
55
112
  - config/locales/en.yml
56
113
  - db/migrate/20120320043253_create_database_files.rb
57
114
  - db/migrate/20120401014029_create_settings.rb
115
+ - db/migrate/20120417075756_devise_create_users.rb
58
116
  - lib/cartoonist.rb
59
117
  - lib/cartoonist/engine.rb
60
118
  - public/errors/404.html
@@ -1,19 +0,0 @@
1
- <% if flash[:error] %>
2
- <p style="color: red;">
3
- <%= flash[:error] %>
4
- </p>
5
- <% end %>
6
-
7
- <%= form_tag "/admin/sign_in", :method => :post do %>
8
- <p>
9
- Username: <input type="text" name="username" autofocus="autofocus" />
10
- </p>
11
-
12
- <p>
13
- Password: <input type="password" name="password" />
14
- </p>
15
-
16
- <p>
17
- <input type="submit" value="Sign in" />
18
- </p>
19
- <% end %>