]> git.openstreetmap.org Git - rails.git/blob - app/controllers/accounts_controller.rb
Merge remote-tracking branch 'upstream/pull/5188'
[rails.git] / app / controllers / accounts_controller.rb
1 class AccountsController < ApplicationController
2   include SessionMethods
3   include UserMethods
4
5   layout "site"
6
7   before_action :authorize_web
8   before_action :set_locale
9
10   authorize_resource :class => false
11
12   before_action :check_database_readable
13   before_action :check_database_writable, :only => [:update]
14
15   allow_thirdparty_images :only => [:edit, :update]
16   allow_social_login :only => [:edit, :update]
17
18   def edit
19     if errors = session.delete(:user_errors)
20       errors.each do |attribute, error|
21         current_user.errors.add(attribute, error)
22       end
23     end
24     @title = t ".title"
25   end
26
27   def update
28     user_params = params.require(:user).permit(:display_name, :new_email, :pass_crypt, :pass_crypt_confirmation, :auth_provider)
29
30     if params[:user][:auth_provider].blank? ||
31        (params[:user][:auth_provider] == current_user.auth_provider &&
32         params[:user][:auth_uid] == current_user.auth_uid)
33       update_user(current_user, user_params)
34       if current_user.errors.count.zero?
35         redirect_to edit_account_path
36       else
37         render :edit
38       end
39     else
40       session[:new_user_settings] = user_params.to_h
41       redirect_to auth_url(params[:user][:auth_provider], params[:user][:auth_uid]), :status => :temporary_redirect
42     end
43   end
44
45   def destroy
46     if current_user.deletion_allowed?
47       current_user.soft_destroy!
48
49       session.delete(:user)
50       session_expires_automatically
51
52       flash[:notice] = t ".success"
53       redirect_to root_path
54     else
55       head :bad_request
56     end
57   end
58 end