-
-
Save kevinansfield/302541 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From d93c7bfe9250c66d8900fe7a2317156a97d85f0e Mon Sep 17 00:00:00 2001 | |
From: Kevin Ansfield <[email protected]> | |
Date: Fri, 12 Feb 2010 13:08:39 +0000 | |
Subject: [PATCH] initial no-subdomain changes as per http://groups.google.com/group/saas-rails-kit/browse_thread/thread/5746a767d96970f6/c4bda592db201e24?lnk=gst&q=Subdomain+#c4bda592db201e24 | |
--- | |
.gitignore | 1 + | |
app/controllers/sessions_controller.rb | 2 +- | |
app/models/account.rb | 21 ++------------------- | |
app/models/user.rb | 4 ++-- | |
app/views/accounts/new.html.erb | 6 +----- | |
lib/authenticated_system.rb | 4 ++-- | |
lib/subscription_system.rb | 4 +--- | |
7 files changed, 10 insertions(+), 32 deletions(-) | |
diff --git a/.gitignore b/.gitignore | |
index c32b756..11d2141 100644 | |
--- a/.gitignore | |
+++ b/.gitignore | |
@@ -5,6 +5,7 @@ | |
coverage | |
db/*.sqlite3 | |
db/*.sqlite3-journal | |
+tmp/restart.txt | |
tmp/**/* | |
public/cache/**/* | |
public/system/**/* | |
\ No newline at end of file | |
diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb | |
index a89c260..2d1e4b9 100644 | |
--- a/app/controllers/sessions_controller.rb | |
+++ b/app/controllers/sessions_controller.rb | |
@@ -4,7 +4,7 @@ class SessionsController < ApplicationController | |
def create | |
logout_keeping_session! | |
- user = current_account.users.authenticate(params[:login], params[:password]) | |
+ user = User.authenticate(params[:login], params[:password]) | |
if user | |
# Protects against session fixation attacks, causes request forgery | |
# protection if user resubmits an earlier form using back | |
diff --git a/app/models/account.rb b/app/models/account.rb | |
index 250d95b..500d6e2 100644 | |
--- a/app/models/account.rb | |
+++ b/app/models/account.rb | |
@@ -5,15 +5,12 @@ class Account < ActiveRecord::Base | |
has_one :subscription, :dependent => :destroy | |
has_many :subscription_payments | |
- validates_format_of :domain, :with => /\A[a-zA-Z][a-zA-Z0-9]*\Z/ | |
- validates_exclusion_of :domain, :in => %W( support blog www billing help api #{AppConfig['admin_subdomain']} ), :message => "The domain <strong>{{value}}</strong> is not available." | |
- validate :valid_domain? | |
validate_on_create :valid_user? | |
validate_on_create :valid_plan? | |
validate_on_create :valid_payment_info? | |
validate_on_create :valid_subscription? | |
- attr_accessible :name, :domain, :user, :plan, :plan_start, :creditcard, :address | |
+ attr_accessible :name, :user, :plan, :plan_start, :creditcard, :address | |
attr_accessor :user, :plan, :plan_start, :creditcard, :address, :affiliate | |
after_create :create_admin | |
@@ -50,25 +47,11 @@ class Account < ActiveRecord::Base | |
self.subscription.next_renewal_at >= Time.now | |
end | |
- def domain | |
- @domain ||= self.full_domain.blank? ? '' : self.full_domain.split('.').first | |
- end | |
- | |
- def domain=(domain) | |
- @domain = domain | |
- self.full_domain = "#{domain}.#{AppConfig['base_domain']}" | |
- end | |
- | |
def to_s | |
- name.blank? ? full_domain : "#{name} (#{full_domain})" | |
+ name | |
end | |
protected | |
- | |
- def valid_domain? | |
- conditions = new_record? ? ['full_domain = ?', self.full_domain] : ['full_domain = ? and id <> ?', self.full_domain, self.id] | |
- self.errors.add(:domain, 'is not available') if self.full_domain.blank? || self.class.count(:conditions => conditions) > 0 | |
- end | |
# An account must have an associated user to be the administrator | |
def valid_user? | |
diff --git a/app/models/user.rb b/app/models/user.rb | |
index 0b98555..123f2bb 100644 | |
--- a/app/models/user.rb | |
+++ b/app/models/user.rb | |
@@ -9,7 +9,7 @@ class User < ActiveRecord::Base | |
validates_presence_of :login | |
validates_length_of :login, :within => 3..40 | |
- validates_uniqueness_of :login, :scope => :account_id | |
+ validates_uniqueness_of :login | |
validates_format_of :login, :with => Authentication.login_regex, :message => Authentication.bad_login_message | |
validates_format_of :name, :with => Authentication.name_regex, :message => Authentication.bad_name_message, :allow_nil => true | |
@@ -17,7 +17,7 @@ class User < ActiveRecord::Base | |
validates_presence_of :email | |
validates_length_of :email, :within => 6..100 #[email protected] | |
- validates_uniqueness_of :email, :scope => :account_id | |
+ validates_uniqueness_of :email | |
validates_format_of :email, :with => Authentication.email_regex, :message => Authentication.bad_email_message | |
diff --git a/app/views/accounts/new.html.erb b/app/views/accounts/new.html.erb | |
index 27e6ac8..8af6475 100644 | |
--- a/app/views/accounts/new.html.erb | |
+++ b/app/views/accounts/new.html.erb | |
@@ -3,7 +3,7 @@ | |
<% form_tag :action => 'create' do %> | |
<%= hidden_field_tag 'plan', params[:plan] %> | |
<p> | |
- Enter the name of your business and the subdomain you'd like to use for your site. | |
+ Enter your name and the login details you'd like to use for your account. | |
</p> | |
<% if @account.errors.any? %> | |
@@ -18,13 +18,9 @@ | |
<fieldset> | |
<% fields_for :account do |f| %> | |
<%= f.text_field :name %> | |
- <%= f.text_field :domain %>.<%= AppConfig['base_domain'] %> | |
<% end %> | |
</fieldset> | |
- <p> | |
- Enter info for the administrator account. | |
- </p> | |
<fieldset> | |
<% fields_for :user do |f| %> | |
<%= f.text_field :login %> | |
diff --git a/lib/authenticated_system.rb b/lib/authenticated_system.rb | |
index 43eea82..a76bd7d 100644 | |
--- a/lib/authenticated_system.rb | |
+++ b/lib/authenticated_system.rb | |
@@ -105,13 +105,13 @@ module AuthenticatedSystem | |
# Called from #current_user. First attempt to login by the user id stored in the session. | |
def login_from_session | |
- self.current_user = current_account.users.find_by_id(session[:user_id]) if session[:user_id] | |
+ self.current_user = User.find_by_id(session[:user_id]) if session[:user_id] | |
end | |
# Called from #current_user. Now, attempt to login by basic authentication information. | |
def login_from_basic_auth | |
authenticate_with_http_basic do |login, password| | |
- self.current_user = current_account.users.authenticate(login, password) | |
+ self.current_user = User.authenticate(login, password) | |
end | |
end | |
diff --git a/lib/subscription_system.rb b/lib/subscription_system.rb | |
index a15cc07..da32ca8 100644 | |
--- a/lib/subscription_system.rb | |
+++ b/lib/subscription_system.rb | |
@@ -11,9 +11,7 @@ module SubscriptionSystem | |
protected | |
def current_account | |
- @current_account ||= Account.find_by_full_domain(request.host) | |
- raise ActiveRecord::RecordNotFound unless @current_account | |
- @current_account | |
+ @current_account ||= current_user.account | |
end | |
def admin? | |
-- | |
1.6.6.1+GitX |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment