From e0ffc8bba0e29448c4b18eb890ff81e71eb9c6a4 Mon Sep 17 00:00:00 2001 From: Raphael Date: Wed, 15 Sep 2010 16:40:03 -0700 Subject: [PATCH] First pass at having a custom registrationsController --- app/controllers/registrations_controller.rb | 18 ++++++++++++++++++ app/models/user.rb | 18 +++--------------- .../{devise => }/registrations/edit.html.haml | 0 .../{devise => }/registrations/new.html.haml | 0 config/routes.rb | 4 ++-- db/seeds/dev.rb | 1 + 6 files changed, 24 insertions(+), 17 deletions(-) create mode 100644 app/controllers/registrations_controller.rb rename app/views/{devise => }/registrations/edit.html.haml (100%) rename app/views/{devise => }/registrations/new.html.haml (100%) diff --git a/app/controllers/registrations_controller.rb b/app/controllers/registrations_controller.rb new file mode 100644 index 000000000..c75ff09a1 --- /dev/null +++ b/app/controllers/registrations_controller.rb @@ -0,0 +1,18 @@ +# Copyright (c) 2010, Disapora Inc. This file is +# licensed under the Affero General Public License version 3. See +# the COPYRIGHT file. + +class RegistrationsController < Devise::RegistrationsController + def new + super + end + + def create + User.instantiate!(params[:user]) + redirect_to root_url + end + + def update + super + end +end diff --git a/app/models/user.rb b/app/models/user.rb index 42bf732a6..ec313fe8b 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -35,8 +35,6 @@ class User many :aspects, :class_name => 'Aspect' - before_create :setup_person - after_create :set_diaspora_handle after_create :seed_aspects before_save :downcase_username @@ -288,10 +286,10 @@ class User end ###Helpers############ - def self.instantiate!( opts = {} ) - #opts[:person][:diaspora_handle] = opts[:email] + def self.instantiate( opts = {} ) + opts[:person][:diaspora_handle] = "#{opts[:username]}@#{opts[:url]}" opts[:person][:serialized_key] = generate_key - User.create!(opts) + User.create(opts) end def seed_aspects @@ -313,16 +311,6 @@ class User "#{self.username}@#{self.terse_url}" end - def setup_person - self.person.serialized_key ||= User.generate_key.export - self.person.save! - end - - def set_diaspora_handle - self.person.diaspora_handle ||= self.diaspora_handle - self.person.save - end - def downcase_username username.downcase! end diff --git a/app/views/devise/registrations/edit.html.haml b/app/views/registrations/edit.html.haml similarity index 100% rename from app/views/devise/registrations/edit.html.haml rename to app/views/registrations/edit.html.haml diff --git a/app/views/devise/registrations/new.html.haml b/app/views/registrations/new.html.haml similarity index 100% rename from app/views/devise/registrations/new.html.haml rename to app/views/registrations/new.html.haml diff --git a/config/routes.rb b/config/routes.rb index 213e090a1..c3205ed25 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -26,10 +26,10 @@ Diaspora::Application.routes.draw do #routes for devise, not really sure you will need to mess with this in the future, lets put default, #non mutable stuff in anohter file - devise_for :users + devise_for :users, :controllers => {:registrations => "registrations"} match 'login', :to => 'devise/sessions#new', :as => "new_user_session" match 'logout', :to => 'devise/sessions#destroy', :as => "destroy_user_session" - match 'get_to_the_choppa', :to => 'devise/registrations#new', :as => "new_user_registration" + match 'get_to_the_choppa', :to => 'registrations#new', :as => "new_user_registration" #public routes # diff --git a/db/seeds/dev.rb b/db/seeds/dev.rb index 483ae7556..116a55929 100644 --- a/db/seeds/dev.rb +++ b/db/seeds/dev.rb @@ -8,6 +8,7 @@ require 'config/environment' host = "localhost:3000" url = "http://#{host}/" +username = "tom" # Create seed user user = User.instantiate!( :email => "tom@tom.joindiaspora.com", :username => "tom",