From b0124fbd26e896c7ea2e34bce3e716989cfdf1f9 Mon Sep 17 00:00:00 2001 From: Manuel Bustillo Date: Sat, 30 Nov 2024 18:46:25 +0100 Subject: [PATCH] Configure email confirmation flow --- .../users/confirmations_controller.rb | 18 +++++++++++++++++ config/routes.rb | 3 +++ spec/requests/users/confirmations_spec.rb | 20 +++++++++++++++++++ 3 files changed, 41 insertions(+) create mode 100644 app/controllers/users/confirmations_controller.rb create mode 100644 spec/requests/users/confirmations_spec.rb diff --git a/app/controllers/users/confirmations_controller.rb b/app/controllers/users/confirmations_controller.rb new file mode 100644 index 0000000..5708a64 --- /dev/null +++ b/app/controllers/users/confirmations_controller.rb @@ -0,0 +1,18 @@ +class Users::ConfirmationsController < Devise::ConfirmationsController + clear_respond_to + respond_to :json + + def show + super do |resource| + if resource.errors.empty? + render json: resource, status: :ok + else + render json: { + message: 'Record invalid', + errors: resource.errors.full_messages + }, status: :unprocessable_entity + end + return + end + end +end \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index ffd2772..4599490 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,11 +1,14 @@ # Copyright (C) 2024 Manuel Bustillo Rails.application.routes.draw do + devise_for :users, skip: [:registration, :session, :confirmation] devise_scope :user do post 'users', to: 'users/registrations#create' post '/users/sign_in', to: 'users/sessions#create' delete '/users/sign_out', to: 'users/sessions#destroy' + + get '/users/confirmation', to: 'users/confirmations#show', as: :confirmation end mount Rswag::Ui::Engine => '/api-docs' diff --git a/spec/requests/users/confirmations_spec.rb b/spec/requests/users/confirmations_spec.rb new file mode 100644 index 0000000..77355ca --- /dev/null +++ b/spec/requests/users/confirmations_spec.rb @@ -0,0 +1,20 @@ +require 'swagger_helper' + +RSpec.describe 'users/confirmations', type: :request do + + path '/users/confirmation' do + get('confirm user email') do + tags 'Users' + produces 'application/json' + + parameter name: :confirmation_token, in: :query, type: :string, required: true + + response(200, 'confirmed') do + schema Swagger::Schema::USER + xit + end + + response_422 + end + end +end