]> git.openstreetmap.org Git - rails.git/blob - app/controllers/accounts/terms_controller.rb
0513a031c96ad2cdb8ac84f7a91adb7095c45142
[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         elsif current_user.nil?
27           redirect_to login_path(:referer => request.fullpath)
28         end
29       end
30     end
31
32     def update
33       @title = t "users.new.title"
34
35       if params[:decline] || !(params[:read_tou] && params[:read_ct])
36         if current_user
37           current_user.terms_seen = true
38
39           flash[:notice] = { :partial => "accounts/terms/terms_declined_flash" } if current_user.save
40
41           referer = safe_referer(params[:referer]) if params[:referer]
42
43           redirect_to referer || edit_account_path
44         elsif params[:decline]
45           redirect_to t("users.terms.declined"), :allow_other_host => true
46         else
47           redirect_to account_terms_path
48         end
49       elsif current_user
50         unless current_user.terms_agreed?
51           current_user.consider_pd = params[:user][:consider_pd]
52           current_user.tou_agreed = Time.now.utc
53           current_user.terms_agreed = Time.now.utc
54           current_user.terms_seen = true
55
56           flash[:notice] = t "users.new.terms accepted" if current_user.save
57         end
58
59         referer = safe_referer(params[:referer]) if params[:referer]
60
61         redirect_to referer || edit_account_path
62       end
63     end
64   end
65 end