-
Notifications
You must be signed in to change notification settings - Fork 4
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
Conversation
SreyMochOrng
commented
Nov 7, 2024
•
edited
Loading
edited
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 |
---|---|
ffa0b33
to
dfd6c23
Compare
dfd6c23
to
47cbf6d
Compare
def show_anonymous_order | ||
token = params[:token] | ||
|
||
decoded_token = JWT.decode(token, nil, false) |
There was a problem hiding this comment.
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 ).
4eb8092
to
901178e
Compare
|
||
private | ||
|
||
def order_jwt_token(token) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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') |
There was a problem hiding this comment.
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 } |
There was a problem hiding this comment.
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
901178e
to
78b290d
Compare
78b290d
to
e14f847
Compare