]> git.openstreetmap.org Git - rails.git/blobdiff - app/controllers/user_controller.rb
Merge branch 'master' of git://git.openstreetmap.org/rails
[rails.git] / app / controllers / user_controller.rb
index e5db74f38ee9c019701fa7db53836d00cf94210b..e07b65af76502278deb69b98c62283bc76f20e39 100644 (file)
@@ -18,11 +18,29 @@ class UserController < ApplicationController
 
   cache_sweeper :user_sweeper, :only => [:account, :set_status, :delete]
 
+  def terms
+    @title = t 'user.new.title'
+    @user = User.new(params[:user])
+
+    @legale = params[:legale] || OSM.IPToCountry(request.remote_ip) || APP_CONFIG['default_legale']
+    @text = OSM.legal_text_for_country(@legale)
+
+    if request.xhr?
+      render :update do |page|
+        page.replace_html "contributorTerms", :partial => "terms"
+      end
+    elsif @user.invalid?
+      render :action => 'new'
+    end
+  end
+
   def save
     @title = t 'user.new.title'
 
     if Acl.find_by_address(request.remote_ip, :conditions => {:k => "no_account_creation"})
       render :action => 'new'
+    elsif params[:decline]
+      redirect_to t('user.terms.declined')
     else
       @user = User.new(params[:user])
 
@@ -31,6 +49,7 @@ class UserController < ApplicationController
       @user.description = "" if @user.description.nil?
       @user.creation_ip = request.remote_ip
       @user.languages = request.user_preferred_languages
+      @user.terms_agreed = Time.now.getutc
 
       if @user.save
         flash[:notice] = t 'user.new.flash create success message'
@@ -70,9 +89,9 @@ class UserController < ApplicationController
         set_locale
 
         if @user.new_email.nil? or @user.new_email.empty?
-          flash.now[:notice] = t 'user.account.flash update success'
+          flash[:notice] = t 'user.account.flash update success'
         else
-          flash.now[:notice] = t 'user.account.flash update success confirm needed'
+          flash[:notice] = t 'user.account.flash update success confirm needed'
 
           begin
             Notifier.deliver_email_confirm(@user, @user.tokens.create)
@@ -80,6 +99,8 @@ class UserController < ApplicationController
             # Ignore errors sending email
           end
         end
+
+        redirect_to :action => "account", :display_name => @user.display_name
       end
     else
       if flash[:errors]
@@ -127,7 +148,7 @@ class UserController < ApplicationController
         if params[:user]
           @user.pass_crypt = params[:user][:pass_crypt]
           @user.pass_crypt_confirmation = params[:user][:pass_crypt_confirmation]
-          @user.status = "active"
+          @user.status = "active" if @user.status == "pending"
           @user.email_valid = true
 
           if @user.save
@@ -337,16 +358,18 @@ class UserController < ApplicationController
 
       User.update_all("status = 'confirmed'", :id => ids) if params[:confirm]
       User.update_all("status = 'deleted'", :id => ids) if params[:hide]
-    end
 
-    conditions = Hash.new
-    conditions[:status] = params[:status] if params[:status]
-    conditions[:creation_ip] = params[:ip] if params[:ip]
-
-    @user_pages, @users = paginate(:users,
-                                   :conditions => conditions,
-                                   :order => :id,
-                                   :per_page => 50)
+      redirect_to url_for(:status => params[:status], :ip => params[:ip], :page => params[:page])
+    else
+      conditions = Hash.new
+      conditions[:status] = params[:status] if params[:status]
+      conditions[:creation_ip] = params[:ip] if params[:ip]
+
+      @user_pages, @users = paginate(:users,
+                                     :conditions => conditions,
+                                     :order => :id,
+                                     :per_page => 50)
+    end
   end
 
 private