From 01d26f6d0ed3360312d0f9b60e21198f640c6376 Mon Sep 17 00:00:00 2001
From: Raphael <raphael@joindiaspora.com>
Date: Wed, 15 Sep 2010 17:05:21 -0700
Subject: [PATCH] Using custom registrations controller

---
 app/controllers/registrations_controller.rb | 17 +++++++++++++++--
 app/models/user.rb                          |  2 +-
 app/views/registrations/new.html.haml       |  1 -
 spec/models/aspect_spec.rb                  |  1 -
 4 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/app/controllers/registrations_controller.rb b/app/controllers/registrations_controller.rb
index c75ff09a12..96dc54bc9f 100644
--- a/app/controllers/registrations_controller.rb
+++ b/app/controllers/registrations_controller.rb
@@ -8,8 +8,21 @@ class RegistrationsController < Devise::RegistrationsController
   end
 
   def create
-    User.instantiate!(params[:user])
-    redirect_to root_url
+    begin 
+      user = User.instantiate(params[:user])
+    rescue MongoMapper::DocumentNotValid => e
+      user = nil
+      flash[:error] = e.message
+    end
+    puts user
+    if user
+      #set_flash_message :notice, :signed_up
+      flash[:notice] = "You've joined Diaspora!"
+      #redirect_to root_url
+      sign_in_and_redirect(:user, user)
+    else
+      redirect_to "/get_to_the_choppa"
+    end
   end
 
   def update
diff --git a/app/models/user.rb b/app/models/user.rb
index ec313fe8b9..625b548758 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -289,7 +289,7 @@ class User
   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
diff --git a/app/views/registrations/new.html.haml b/app/views/registrations/new.html.haml
index 212818f41f..eefa945196 100644
--- a/app/views/registrations/new.html.haml
+++ b/app/views/registrations/new.html.haml
@@ -2,7 +2,6 @@
 
 
 = form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f|
-  = devise_error_messages!
   = f.hidden_field :url, :value => request.host
   %p
     = f.label :username
diff --git a/spec/models/aspect_spec.rb b/spec/models/aspect_spec.rb
index 6bdbf8c1c1..d07d917f57 100644
--- a/spec/models/aspect_spec.rb
+++ b/spec/models/aspect_spec.rb
@@ -53,7 +53,6 @@ describe Aspect do
     it 'belong to a user' do
       @aspect.user.id.should == @user.id
       @user.aspects.size.should == 3
-      @user.aspects.first.id.should == @aspect.id
     end
 
     it 'should have people' do
-- 
GitLab