Skip to content

Commit

Permalink
Adding a setup to typo blog. Will redirect user to the editor after f…
Browse files Browse the repository at this point in the history
…irst account creation
  • Loading branch information
Frédéric de Villamil committed Feb 18, 2010
1 parent e4102a3 commit 56d89d2
Show file tree
Hide file tree
Showing 9 changed files with 167 additions and 7 deletions.
6 changes: 5 additions & 1 deletion app/controllers/accounts_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class AccountsController < ApplicationController

before_filter :verify_config
before_filter :verify_users, :only => [:login, :recover_password]
filter_parameter_logging "password"

Expand Down Expand Up @@ -106,5 +107,8 @@ def verify_users
redirect_to(:controller => "accounts", :action => "signup") if User.count == 0
true
end


def verify_config
redirect_to :controller => "setup", :action => "index" if ! this_blog.configured?
end
end
7 changes: 3 additions & 4 deletions app/controllers/articles_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
class ArticlesController < ContentController
before_filter :verify_config
before_filter :login_required, :only => [:preview]
before_filter :auto_discovery_feed, :only => [:show, :index]

Expand Down Expand Up @@ -187,10 +186,10 @@ def markup_help
private

def verify_config
if User.count == 0
if ! this_blog.configured?
redirect_to :controller => "setup", :action => "index"
elsif User.count == 0
redirect_to :controller => "accounts", :action => "signup"
elsif ! this_blog.configured?
redirect_to :controller => "admin/settings", :action => "redirect"
else
return true
end
Expand Down
25 changes: 25 additions & 0 deletions app/controllers/setup_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
class SetupController < ApplicationController
before_filter :check_config
layout 'accounts'

def index
if request.post?
Blog.transaction do
params[:setting].each { |k,v| this_blog.send("#{k.to_s}=", v) }
this_blog.save
redirect_to :controller => 'accounts', :action => 'signup'
end
end
end

private
def check_config
return unless this_blog.configured?

if User.count == 0
redirect_to :controller => "accounts", :action => "signup"
else
redirect_to :controller => 'articles', :action => 'index'
end
end
end
2 changes: 1 addition & 1 deletion app/views/accounts/confirm.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
<%= _("Don't lose the mail sent at %s or you won't be able to login anymore", current_user.email)%>
</p>
<p class='input_text_title right'>
<%= _("Proceed to %s", link_to(_("admin"), :controller => 'admin/settings')) %>
<%= _("Proceed to %s", link_to(_("admin"), :controller => 'admin/content/new')) %>
</p>
1 change: 1 addition & 0 deletions app/views/accounts/signup.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

<% form_tag :action=> "signup" do %>
<div>
<h1><%= _("Create an account")%></h1>
<h2><label for="user_login"><%= _("Username") %>:</label></h2>
<p class='input_text_title'>
<%= text_field(:user, :login, {:class => 'title large'})%>
Expand Down
20 changes: 20 additions & 0 deletions app/views/setup/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<%= content_tag :h3, link_to(image_tag("/images/admin/typologo.gif", :alt=>"Typo website"), "http://typosphere.org") %>

<div id="flash"><%= error_messages_for 'setup' %></div>

<% form_tag :action=> 'index' do %>
<div>
<h1><%= _("Setup")%></h1>
<h2><label for="user_login"><%= _("Blog name") %>:</label></h2>
<p class='input_text_title'>
<%= text_field(:setting, :blog_name, {:class => 'title large'})%>
</p>
</div>
<div>
<h2><label for="user_email"><%= _("Blog url")%>:</label></h2>
<p class='input_text_title'>
<%= text_field(:setting, :base_url, {:class => 'title large'})%>
</p>
</div>
<p><input type="submit" id="submit" class='save large' value="<%= _('Save')%>" /></p>
<% end %>
3 changes: 2 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
map.search '/search/:q.:format', :controller => "articles", :action => "search"
map.search_base '/search/', :controller => "articles", :action => "search"
map.connect '/archives/', :controller => "articles", :action => "archives"

map.connect '/setup', :controller => 'setup', :action => 'index'

# I thinks it's useless. More investigating
map.connect "trackbacks/:id/:day/:month/:year",
:controller => 'trackbacks', :action => 'create', :conditions => {:method => :post}
Expand Down
69 changes: 69 additions & 0 deletions spec/controllers/accounts_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,75 @@ def params
end
end

describe 'GET signup with 0 existing users and unconfigured blog' do
controller_name :accounts

before(:each) do
Blog.delete_all
@blog = Blog.new.save
User.delete_all
end

it 'redirects to setup' do
get 'signup'
response.should redirect_to(:controller => 'setup', :action => 'index')
end
end

describe 'POST signup with 0 existing users and unconfigured blog' do
controller_name :accounts

before(:each) do
Blog.delete_all
@blog = Blog.new.save
User.delete_all
end

it 'redirects to setup' do
post 'signup', params
response.should redirect_to(:controller => 'setup', :action => 'index')
end

def params
{'user' => {'login' => 'newbob', 'password' => 'newpassword',
'password_confirmation' => 'newpassword'}}
end
end

describe 'GET login with 0 existing users and unconfigured blog' do
controller_name :accounts

before(:each) do
Blog.delete_all
@blog = Blog.new.save
User.delete_all
end

it 'redirects to setup' do
get 'login'
response.should redirect_to(:controller => 'setup', :action => 'index')
end
end

describe 'POST login with 0 existing users and unconfigured blog' do
controller_name :accounts

before(:each) do
Blog.delete_all
@blog = Blog.new.save
User.delete_all
end

it 'redirects to setup' do
post 'login', params
response.should redirect_to(:controller => 'setup', :action => 'index')
end

def params
{'user' => {'login' => 'newbob', 'password' => 'newpassword'}}
end
end

describe 'POST signup with 0 existing users' do
controller_name :accounts

Expand Down
41 changes: 41 additions & 0 deletions spec/controllers/setup_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
require File.dirname(__FILE__) + '/../spec_helper'

describe 'GET setup with no configured blog' do
controller_name :setup

before(:each) do
Blog.delete_all
@blog = Blog.new.save
end

it 'renders index' do
get 'index'
response.should render_template('index')
end
end

describe 'GET setup with a configured blog and no user' do
controller_name :setup

before(:each) do
User.stub!(:count).and_return(0)
@user = mock("user")
@user.stub!(:reload).and_return(@user)
User.stub!(:new).and_return(@user)

end

it 'redirects to setup' do
get 'index'
response.should redirect_to(:controller => 'accounts', :action => 'signup')
end
end

describe 'GET setup with a configured blog and some users' do
controller_name :setup

it 'redirects to login' do
get 'index'
response.should redirect_to(:controller => 'articles', :action => 'index')
end
end

0 comments on commit 56d89d2

Please sign in to comment.