- # logout - this gets intercepted by controller, so this is probably
- # mostly dead code at this point.
- def logout
- session[:user_id] = nil
-
- flash[:notice] = 'You have logged off'
- return_to = params[:return_to] || root_url
- redirect_to return_to
- end
-
- # login. Redirect to LoginCluster.
- def login
- if params[:remote] !~ /^[0-9a-z]{5}$/ && !params[:remote].nil?
- return send_error 'Invalid remote cluster id', status: 400
- end
- if current_user and params[:return_to]
- # Already logged in; just need to send a token to the requesting
- # API client.
- #
- # FIXME: if current_user has never authorized this app before,
- # ask for confirmation here!
-
- return send_api_token_to(params[:return_to], current_user, params[:remote])
- end
- p = []
- p << "auth_provider=#{CGI.escape(params[:auth_provider])}" if params[:auth_provider]
-
- if !Rails.configuration.Login.LoginCluster.empty? and Rails.configuration.Login.LoginCluster != Rails.configuration.ClusterID
- host = ApiClientAuthorization.remote_host(uuid_prefix: Rails.configuration.Login.LoginCluster)
- if not host
- raise "LoginCluster #{Rails.configuration.Login.LoginCluster} missing from RemoteClusters"
- end
- scheme = "https"
- cluster = Rails.configuration.RemoteClusters[Rails.configuration.Login.LoginCluster]
- if cluster and cluster['Scheme'] and !cluster['Scheme'].empty?
- scheme = cluster['Scheme']
- end
- login_cluster = "#{scheme}://#{host}"
- p << "remote=#{CGI.escape(params[:remote])}" if params[:remote]
- p << "return_to=#{CGI.escape(params[:return_to])}" if params[:return_to]
- redirect_to "#{login_cluster}/login?#{p.join('&')}"
- else
- return send_error "Legacy code path no longer supported", status: 404
- end
- end
-