Skip to content

Instantly share code, notes, and snippets.

View maxloncar's full-sized avatar

Max Lončar maxloncar

View GitHub Profile
@maxloncar
maxloncar / createUserHandler.php
Last active November 11, 2022 11:53
Handler class
<?php
// src/User/Message/createUserHandler.php
namespace App\User\Handler;
use Doctrine\ORM\EntityManagerInterface;
use Exception;
use App\Domain\User\Entity\User;
use App\Domain\Translation\ValueObject\ErrorMessage;
use App\User\Message\CreateUserMessage;
use Symfony\Component\Messenger\Handler\MessageHandlerInterface;
@maxloncar
maxloncar / CreateUser.php
Last active November 11, 2022 11:53
Creating a user
<?php
// src/User/Action/CreateUser.php
namespace App\User\Action;
use App\Core\REST\Action\AbstractApiAction;
use App\Core\REST\ValueObject\ApiResponse;
use App\Domain\User\Representation\UserRepresentation;
use App\User\Message\CreateUserMessage;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
@maxloncar
maxloncar / CreateUserMessage.php
Last active November 11, 2022 11:53
Message class
<?php
// src/User/Message/CreateUserMessage.php
namespace App\User\Message;
use Assert\Assert;
use Symfony\Component\HttpFoundation\Request;
/**
* Class CreateUserMessage
*
@maxloncar
maxloncar / User.php
Last active November 11, 2022 11:54
User Entity
<?php
// src/Domain/User/Entity/User.php
namespace App\Domain\User\Entity;
use Doctrine\ORM\Mapping as ORM;
use App\Domain\User\Repository\UserRepository;
use Symfony\Component\Validator\Constraints as Assert;
/**
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "VisualEditor0",
"Effect": "Allow",
"Action": [
"s3:PutObject",
"s3:GetObjectAcl",
"s3:GetObject",
SitemapGenerator::Sitemap.sitemaps_path = "sitemaps/" //find the folder in the S3 bucket
SitemapGenerator::Sitemap.adapter = SitemapGenerator::AwsSdkAdapter.new(ENV.fetch("S3_BUCKET_NAME"),

aws_access_key_id: ENV.fetch("AWS_ACCESS_KEY_ID"),
aws_secret_access_key: ENV.fetch("AWS_SECRET_ACCESS_KEY"),
region: ENV.fetch("AWS_REGION")
)
@maxloncar
maxloncar / turbo_controller.rb
Last active November 17, 2022 12:30
Update on how the error messages are being handled
# app/controllers/turbo_controller.rb
class TurboController < ApplicationController
class Responder < ActionController::Responder
def to_turbo_stream
controller.render(options.merge(formats: :html))
rescue ActionView::MissingTemplate => error
if get?
raise error
elsif has_errors? && default_action
@maxloncar
maxloncar / two_columns.rb
Last active November 17, 2022 12:30
Add two columns to your users table so that a user can hold an 'uid' and a 'provider'
add_column(:users, :provider, :string, limit: 50, null: false, default:'')
add_column(:users, :uid, :string, limit: 50, null: false, default:'')
@maxloncar
maxloncar / fix_omniauth.rb
Last active November 17, 2022 12:31
Initializer if OmniAuth decides not to cooperate with your project when dealing with raised exceptions after unsuccessful login attempts
# config/initializers/fix_omniauth.rb
begin
require "omniauth"
require "omniauth/version"
rescue LoadError => e
warn "Could not load 'omniauth'. Please ensure you have the omniauth gem >= 1.0.0 installed and listed in your Gemfile."
raise
end
@maxloncar
maxloncar / omniauth_callbacks_controller.rb
Last active November 17, 2022 12:31
For Devise to understand additional logic happening during the authentication process
# app/controller/omniauth_callbacks_controller.rb
class OmniauthCallbacksController < Devise::OmniauthCallbacksController
def microsoft_office365
callback_from :microsoft_office365
end
def failure
redirect_to after_omniauth_failure_path_for(resource_name)
end