mirror of
https://github.com/SrIzan10/hc-harbor.git
synced 2026-05-01 10:45:21 +00:00
51 lines
1.4 KiB
Ruby
51 lines
1.4 KiB
Ruby
module Api
|
|
module Internal
|
|
class MagicLinksController < ApplicationController
|
|
def create
|
|
slack_uid = params[:id]
|
|
email = params[:email]
|
|
|
|
unless slack_uid.present?
|
|
return render json: {
|
|
error: "gotta provide an ID, buddy..."
|
|
}, status: 400
|
|
end
|
|
|
|
unless email.present?
|
|
return render json: {
|
|
error: "weird things happen without an email...,,"
|
|
}, status: 400
|
|
end
|
|
|
|
begin
|
|
user = User.find_or_create_by!(slack_uid: slack_uid)
|
|
existing = user.persisted?
|
|
|
|
unless user.email_addresses.exists?(email: email)
|
|
user.email_addresses.create!(email: email)
|
|
end
|
|
|
|
sign_in_token = user.sign_in_tokens.create!(
|
|
magic_link_params.merge(
|
|
auth_type: :program_magic_link,
|
|
expires_at: Time.now + 5.minutes
|
|
)
|
|
)
|
|
|
|
render json: {
|
|
magic_link: auth_token_url(sign_in_token.token),
|
|
existing:
|
|
}
|
|
rescue => e
|
|
Honeybadger.notify(e, context: { slack_uid: slack_uid, email: email, params: params.to_unsafe_h })
|
|
render json: { error: "internal error creating magic link" }, status: 500
|
|
end
|
|
end
|
|
|
|
def magic_link_params
|
|
params.permit(:continue_param, return_data: {})
|
|
end
|
|
end
|
|
end
|
|
end
|