Skip to content

Commit

Permalink
Allow users to create Org and Project on signup
Browse files Browse the repository at this point in the history
Extra field asks for Organization's name, and if
given creates an Organization and a Project with
that name.
  • Loading branch information
Pablo Villalba committed Oct 9, 2011
1 parent 87de263 commit 94a65c9
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 5 deletions.
23 changes: 20 additions & 3 deletions app/controllers/users_controller.rb
Expand Up @@ -94,10 +94,13 @@ def create
redirect_to projects_path
end
else
redirect_back_or_default root_path
end
# If the form sent a parameter for org's name,
# we will create an organization and project
name = params[:user][:organization][:name] rescue nil
project = create_initial_organization_and_project(name)

flash[:success] = t('users.create.thanks')
redirect_to project ? project_invite_people_path(project) : root_path
end
else
respond_to do |f|
f.any(:html, :m) { render :action => :new, :layout => 'sessions' }
Expand Down Expand Up @@ -291,4 +294,18 @@ def can_users_signup?
return redirect_to Teambox.config.community ? login_path : root_path
end
end

def create_initial_organization_and_project(name)
return if (name || "").length <= 1
begin
permalink = PermalinkFu.escape(name)
org = @user.organizations.new(:name => name, :permalink => permalink)
org.save!
project = org.projects.new(:name => name, :permalink => permalink)
project.user = @user
project.save!
return project
rescue
end
end
end
2 changes: 1 addition & 1 deletion app/helpers/users_helper.rb
Expand Up @@ -38,7 +38,7 @@ def build_user_phone_number(user)
card = user.card || user.build_card
card.phone_numbers.build unless card.phone_numbers.any?
end

def load_javascript_user_data
javascript_tag %(
my_user = #{json_user};
Expand Down
15 changes: 15 additions & 0 deletions app/views/users/form/_new.haml
Expand Up @@ -28,6 +28,20 @@
= f.label :time_zone, t('users.form.time_zone')
= f.time_zone_select :time_zone, ActiveSupport::TimeZone.us_zones, :default => "Eastern Time (US & Canada)"

- if !@invitation
- user.organizations.build
= f.fields_for :organization do |organization|
%fieldset.account
%legend= t('.organization.title')
%p
= t('.organization.explain1')
%br
= t('.organization.explain2')
.login.text_field
= organization.label :name, t('.organization.label')
= organization.text_field :name
.field_note= t('.organization.field_note')

%fieldset.account
%legend= t('.account.title')
%p
Expand All @@ -38,6 +52,7 @@
= f.label :login, t('users.form.login')
= f.text_field :login
= errors_for user, :login
.field_note= t('.account.field_note')
.password.text_field
= f.label :password, t('users.form.password')
= f.password_field :password, :autocomplete => 'off'
Expand Down
7 changes: 7 additions & 0 deletions config/locales/en.yml
Expand Up @@ -332,6 +332,13 @@ en:
title: Your Teambox account
choose_username: Choose a username so people can find you. You will use it to log in.
validations: Must be all lowercase, no spaces allowed. You can use underscores.
field_note: This is what other users will use to refer to you
organization:
title: Your Organization
explain1: Your organization will be a private space for all your projects.
explain2: You can create more workspaces later. Choose a brief name for it.
label: Organization name
field_note: We will create a workspace with this name for you
new:
title: Create an Account
submit: Create account
Expand Down
31 changes: 30 additions & 1 deletion features/user_signup.feature
Expand Up @@ -17,7 +17,7 @@ Feature: Signing up
When I open the email
Then I should see "Hey, Mislav Marohnić!" in the email body
When I follow "Log into Teambox now!" in the email
Then I should see "Welcome"
Then I should see "Create a Project"
And I should not see "confirm your account"

Scenario Outline: User tries to sign up with a reserved username
Expand Down Expand Up @@ -54,3 +54,32 @@ Feature: Signing up
When I follow "Log into Teambox now!" in the email
Then I should see "Welcome"
And I should not see "confirm your account"

Scenario: User signs up and creates an organization and project
When I go to the signup page
And I fill in the following:
| Username | mislav |
| First name | Mislav |
| Last name | Marohnić |
| Email | mislav@fuckingawesome.com |
| Password | dragons |
| Confirm password | dragons |
| Organization name | Le Game |
And I press "Create account"
Then show me the page
Then I should see "Invite people to Le Game"

Scenario: User signs up and gives a short name for an organization
When I go to the signup page
And I fill in the following:
| Username | mislav |
| First name | Mislav |
| Last name | Marohnić |
| Email | mislav@fuckingawesome.com |
| Password | dragons |
| Confirm password | dragons |
| Organization name | XY |
And I press "Create account"
Then show me the page
Then I should see "Invite people to XY"

0 comments on commit 94a65c9

Please sign in to comment.