]> git.openstreetmap.org Git - rails.git/blob - app/controllers/accounts_controller.rb
Refactor the account edit/update pages out into a separate accounts controller
[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   before_action :allow_thirdparty_images, :only => [:edit, :update]
15
16   def edit
17     @tokens = current_user.oauth_tokens.authorized
18
19     append_content_security_policy_directives(
20       :form_action => %w[accounts.google.com *.facebook.com login.live.com github.com meta.wikimedia.org]
21     )
22
23     if errors = session.delete(:user_errors)
24       errors.each do |attribute, error|
25         current_user.errors.add(attribute, error)
26       end
27     end
28     @title = t ".title"
29   end
30
31   def update
32     @tokens = current_user.oauth_tokens.authorized
33
34     append_content_security_policy_directives(
35       :form_action => %w[accounts.google.com *.facebook.com login.live.com github.com meta.wikimedia.org]
36     )
37
38     if params[:user][:auth_provider].blank? ||
39        (params[:user][:auth_provider] == current_user.auth_provider &&
40         params[:user][:auth_uid] == current_user.auth_uid)
41       update_user(current_user, params)
42       if current_user.errors.count.zero?
43         redirect_to edit_account_path
44       else
45         render :edit
46       end
47     else
48       session[:new_user_settings] = params
49       redirect_to auth_url(params[:user][:auth_provider], params[:user][:auth_uid]), :status => :temporary_redirect
50     end
51   end
52 end