Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Close #2047 implement JWT on email confirmation #2048

Merged
merged 1 commit into from
Dec 4, 2024

Conversation

SreyMochOrng
Copy link
Collaborator

@SreyMochOrng SreyMochOrng commented Nov 7, 2024

When we click View More, it will redirect to web booking details it redirect to this page without authentication by just using JWT token to verify
image image

@SreyMochOrng SreyMochOrng added the L From 2 to 3 days to make it ready label Nov 7, 2024
@SreyMochOrng SreyMochOrng self-assigned this Nov 7, 2024
@SreyMochOrng SreyMochOrng force-pushed the 2047-implement-JWT-on-email-confirmation branch 2 times, most recently from ffa0b33 to dfd6c23 Compare November 13, 2024 08:26
@SreyMochOrng SreyMochOrng force-pushed the 2047-implement-JWT-on-email-confirmation branch from dfd6c23 to 47cbf6d Compare November 20, 2024 02:28
@channainfo channainfo changed the title 2047 implement jwt on email confirmation Close #2047 implement JWT on email confirmation Nov 25, 2024
def show_anonymous_order
token = params[:token]

decoded_token = JWT.decode(token, nil, false)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's encapsulate this to class to find an order by jwt_token called order_jwt_token ( encode, decode ).

@SreyMochOrng SreyMochOrng force-pushed the 2047-implement-JWT-on-email-confirmation branch 7 times, most recently from 4eb8092 to 901178e Compare December 4, 2024 08:11

private

def order_jwt_token(token)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's move this to libs/cm_commissioners/order_jwt_token.rb service

module CmCommissioner
  class OrderJwtToken
      def self.encode(order)
           # construct the payload to encode here
           # encode  and return jwt_token string
      end

      def self.decode(jwt_token)
           # decode and return order or nil is invalid
      end
   end
end






class AnonymousOrderController < Spree::Api::V2::BaseController
def show_anonymous_order
token = params[:token]
order = order_jwt_token(token)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

order = CmCommissioner::OrderJwtToken.decode(token)

@@ -18,6 +18,8 @@ def confirm_email(order, resend: false)

subject = (resend ? "[#{Spree.t(:resend).upcase}] " : '')
subject += "#{@current_store&.name} Booking Confirmation ##{@order.number}"
payload = { order_number: @order.number, user_id: @order.user.id, store_id: @current_store.id }
@jwt_token = JWT.encode(payload, @order.token, 'HS256')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jwt_token = OrderJwtToken.encode(@order)

@@ -18,6 +18,8 @@ def confirm_email(order, resend: false)

subject = (resend ? "[#{Spree.t(:resend).upcase}] " : '')
subject += "#{@current_store&.name} Booking Confirmation ##{@order.number}"
payload = { order_number: @order.number, user_id: @order.user.id, store_id: @current_store.id }
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use @order.user_id instead of @order.user.id

@SreyMochOrng SreyMochOrng force-pushed the 2047-implement-JWT-on-email-confirmation branch from 901178e to 78b290d Compare December 4, 2024 10:28
@SreyMochOrng SreyMochOrng force-pushed the 2047-implement-JWT-on-email-confirmation branch from 78b290d to e14f847 Compare December 4, 2024 10:34
@channainfo channainfo merged commit 7e07804 into develop Dec 4, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
L From 2 to 3 days to make it ready
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants