Added subdomains to users

1.0
Fernando Blat 13 years ago
parent 0b42d2ba32
commit 487e79a7df

@ -18,6 +18,8 @@ class User < Sequel::Model
## Validations
def validate
super
validates_presence :subdomain
validates_unique :subdomain, :message => 'is already taken'
validates_presence :email
validates_unique :email, :message => 'is already taken'
validates_format EmailAddressValidator::Regexp::ADDR_SPEC, :email, :message => 'is not a valid address'

@ -0,0 +1,15 @@
class AddSubdomainsMigration < Sequel::Migration
def up
add_column :users, :subdomain, 'character varying'
alter_table(:users) do
add_index [:subdomain], :unique => true
end
end
def down
drop_column :users, :subdomain
end
end

@ -19,6 +19,7 @@ if Rails.env.development?
admin.password = 'example'
admin.password_confirmation = 'example'
admin.username = 'admin'
admin.subdomain = 'vizzuality'
admin.admin = true
admin.save

@ -4,6 +4,7 @@ module CartoDB
attributes = attributes.dup
user = User.new
user.username = attributes[:username] || String.random(5)
user.subdomain = user.username
user.email = attributes[:email] || String.random(5).downcase + '@' + String.random(5).downcase + '.com'
user.password = attributes[:password] || user.email.split('@').first
user.password_confirmation = user.password

Loading…
Cancel
Save