]> git.openstreetmap.org Git - rails.git/blob - app/controllers/accounts/terms_controller.rb
Merge remote-tracking branch 'upstream/pull/5499'
[rails.git] / app / controllers / accounts / terms_controller.rb
1 module Accounts
2   class TermsController < ApplicationController
3     include SessionMethods
4
5     layout "site"
6
7     before_action :disable_terms_redirect
8     before_action :authorize_web
9     before_action :set_locale
10     before_action :check_database_readable
11
12     authorize_resource :class => :account_terms
13
14     def show
15       @legale = params[:legale] || OSM.ip_to_country(request.remote_ip) || Settings.default_legale
16       @text = OSM.legal_text_for_country(@legale)
17
18       if request.xhr?
19         render :partial => "terms"
20       else
21         @title = t ".title"
22
23         if current_user.terms_agreed?
24           # Already agreed to terms, so just show settings
25           redirect_to edit_account_path
26         end
27       end
28     end
29
30     def update
31       if params[:decline] || !(params[:read_tou] && params[:read_ct])
32         current_user.terms_seen = true
33
34         flash[:notice] = { :partial => "accounts/terms/terms_declined_flash" } if current_user.save
35       else
36         unless current_user.terms_agreed?
37           current_user.consider_pd = params[:user][:consider_pd]
38           current_user.tou_agreed = Time.now.utc
39           current_user.terms_agreed = Time.now.utc
40           current_user.terms_seen = true
41
42           flash[:notice] = t ".terms accepted" if current_user.save
43         end
44       end
45
46       referer = safe_referer(params[:referer]) if params[:referer]
47
48       redirect_to referer || edit_account_path
49     end
50   end
51 end