]> git.openstreetmap.org Git - rails.git/blobdiff - app/controllers/user_controller.rb
Localisation updates from http://translatewiki.net.
[rails.git] / app / controllers / user_controller.rb
index e5a2f04bd1792149c1423e01d1c8fc1b3001ad06..6935af3bca5f3508fa7d2222a2f142975ebdc5b8 100644 (file)
@@ -32,7 +32,12 @@ class UserController < ApplicationController
 
       if @user
         if @user.invalid?
-          render :action => :new
+          if @user.new_record?
+            render :action => :new
+          else
+            flash[:errors] = @user.errors
+            redirect_to :action => :account, :display_name => @user.display_name
+          end
         elsif @user.terms_agreed?
           redirect_to :action => :account, :display_name => @user.display_name
         end
@@ -72,6 +77,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 => params[:referer]))
+        session[:token] = @user.tokens.create.token
         redirect_to :action => 'login'
       else
         render :action => 'new'
@@ -103,6 +109,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
+
       if @user.save
         set_locale
 
@@ -123,7 +135,7 @@ class UserController < ApplicationController
     else
       if flash[:errors]
         flash[:errors].each do |attr,msg|
-          attr = "new_email" if attr == "email"
+          attr = "new_email" if attr == "email" and !@user.new_email.nil?
           @user.errors.add(attr,msg)
         end
       end
@@ -259,14 +271,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