]> git.openstreetmap.org Git - rails.git/blobdiff - app/controllers/user_controller.rb
Merge branch 'master' into openid
[rails.git] / app / controllers / user_controller.rb
index d456c1353ef9f45a230927d09a804f61f0ba1cd4..1193ec9106b151887fb7518bd727184bd19276ef 100644 (file)
@@ -108,6 +108,7 @@ class UserController < ApplicationController
       if @user.save
         flash[:notice] = t 'user.new.flash create success message', :email => @user.email
         Notifier.deliver_signup_confirm(@user, @user.tokens.create(:referer => session.delete(:referer)))
+        session[:token] = @user.tokens.create.token
         redirect_to :action => 'login'
       else
         render :action => 'new'
@@ -139,6 +140,12 @@ class UserController < ApplicationController
       @user.home_lat = params[:user][:home_lat]
       @user.home_lon = params[:user][:home_lon]
 
+      if params[:user][:preferred_editor] == "default"
+        @user.preferred_editor = nil
+      else
+        @user.preferred_editor = params[:user][:preferred_editor]
+      end
+
       @user.openid_url = nil if params[:user][:openid_url].empty?
 
       if params[:user][:openid_url].length > 0 and
@@ -283,14 +290,29 @@ class UserController < ApplicationController
           user.save!
           referer = token.referer
           token.destroy
-          session[:user] = user.id
 
-          unless referer.nil?
+          if session[:token] 
+            token = UserToken.find_by_token(session[:token])
+            session.delete(:token)
+          else
+            token = nil
+          end
+
+          if token.nil? or token.user != user
             flash[:notice] = t('user.confirm.success')
-            redirect_to referer
+            redirect_to :action => :login, :referer => referer
           else
-            flash[:notice] = t('user.confirm.success') + "<br /><br />" + t('user.confirm.before you start')
-            redirect_to :action => 'account', :display_name => user.display_name
+            token.destroy
+
+            session[:user] = user.id
+
+            if referer.nil?
+              flash[:notice] = t('user.confirm.success') + "<br /><br />" + t('user.confirm.before you start')
+              redirect_to :action => :account, :display_name => user.display_name
+            else
+              flash[:notice] = t('user.confirm.success')
+              redirect_to referer
+            end
           end
         end
       else