Make /user/new handle already logged in users better
authorTom Hughes <tom@compton.nu>
Mon, 7 Nov 2011 17:38:11 +0000 (17:38 +0000)
committerTom Hughes <tom@compton.nu>
Mon, 14 Nov 2011 09:42:58 +0000 (09:42 +0000)
app/controllers/user_controller.rb

index 92a602ff17776a26b9c2ab43e237409daedcc0bf..3622b037d683abac9ce4f44c1cc7b243f98ca439 100644 (file)
@@ -253,16 +253,21 @@ class UserController < ApplicationController
   def new
     @title = t 'user.new.title'
     @referer = params[:referer] || session[:referer]
-    @user = User.new(:email => params[:email],
-                     :email_confirmation => params[:email],
-                     :display_name => params[:nickname],
-                     :openid_url => params[:openid])
 
-    if session[:user]
+    if @user
       # The user is logged in already, so don't show them the signup
       # page, instead send them to the home page
-      redirect_to :controller => 'site', :action => 'index'
-    elsif not params['openid'].nil?
+      if @referer
+        redirect_to @referer
+      else
+        redirect_to :controller => 'site', :action => 'index'
+      end
+    elsif params.key?(:openid)
+      @user = User.new(:email => params[:email],
+                       :email_confirmation => params[:email],
+                       :display_name => params[:nickname],
+                       :openid_url => params[:openid])
+
       flash.now[:notice] = t 'user.new.openid association'
     end
   end