Email Verification Laravel 8 - email

i am using laravel 8 and trying to verify my email at the time of registration
and getting error
Cannot send message without a sender address
as this is error i'm getting
here is my SMTP setting in .env file
MAIL_MAILER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=abc#gmail.com
MAIL_PASSWORD=password
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=admin#gmail.com
MAIL_FROM_NAME="${APP_NAME}"
and here is my user model code
<?php
namespace App\Models;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
class User extends Authenticatable implements MustVerifyEmail
{
use HasFactory, Notifiable,HasRoles;
/**
* The attributes that are mass assignable.
*
* #var array
*/
protected $fillable = [
'name',
'email',
'password',
];
/**
* The attributes that should be hidden for arrays.
*
* #var array
*/
protected $hidden = [
'password',
'remember_token',
];
/**
* The attributes that should be cast to native types.
*
* #var array
*/
protected $casts = [
'email_verified_at' => 'datetime',
];
}
and this is my route from web.php
Auth::routes(['verify' => true]);

Change your port or you can do php artisan config:cache

Go to folder vendor\swiftmailer\lib\classes\Swift\Transport\StreamBuffer.php and then change $options = []; to $options['ssl'] = array('verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true);
I found the solutions here https://laracasts.com/discuss/channels/laravel/stream-socket-enable-crypto-ssl-operation-failed-with-code-laravel-7. Its work for me.

Related

TYPO3 FileReference does not save the tablename on the DB. Uploading file from frontend on TYPO3

In my custom extension on TYPO3 10.4 I'm trying to upload a file (image) from the frontend. The file gets uploaded just fine, the rows on the DB seemed to be inserted just fine but there is some data missing.
This is my form:
<f:form method="post" action="create" name="blackboard"
object="{blackboard}" enctype="multipart/form-data">
<f:form.textfield placeholder="Titel*" required="true" property="title"></f:form.textfield>
<f:form.upload property="image" name="image" />
<f:form.submit class="btn btn-primary" value="{f:translate(key: 'submit', default: 'Absenden')}"></f:form.submit>
</f:form>
The model:
/**
* image
*
* #var \TYPO3\CMS\Extbase\Domain\Model\FileReference
* #TYPO3\CMS\Extbase\Annotation\ORM\Cascade("remove")
*/
protected $image = null;
/**
* Returns the image
*
* #return \TYPO3\CMS\Extbase\Domain\Model\FileReference $image
*/
public function getImage()
{
return $this->image;
}
/**
* Sets the image
*
* #param \TYPO3\CMS\Extbase\Domain\Model\FileReference $image
* #return void
*/
public function setImage(\TYPO3\CMS\Extbase\Domain\Model\FileReference $image)
{
$this->image = $image;
}
The controller:
/**
* action create
* #param Blackboard
*/
public function createAction(Blackboard $blackboard)
{
$blackboard->setPid($GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['hebo_blackboards']['BlackboardsStoragePId']);
$blackboard->setUser($GLOBALS['TSFE']->fe_user->user['uid']);
$this->blackboardRepository->add($blackboard);
}
Surprisingly, just that easy, this seems to work just fine. I get the image uploaded on the server, the correct UID of that sys_file_reference on my custom table, the sys_file_reference gets the correct UID of that sys_file... but as you can see in the pic that follows there are a few data missing, "tablename" and "table_local" and as soon as I add that data manually the relationships work (the first rows, where this data is not missing is from rows created from the backend, working fine)
My question is, why? What do I do to fix that?
The problem is that extbase doesn't know those values, therefore you need to state those in the TCA. Given this example
'extra_files' => [
'label' => 'A file',
'config' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig(
'extra_files',
[
'foreign_match_fields' => [
'tablenames' => 'tx_yourtable_domain_model_fo',
'table_local' => 'sys_file'
]
],
$GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext']
),
],
The foreign_match_fields part is the relevant one which is not needed if you don't handle file uploads in the Frontend.

TYPO3 Extbase how to empty ObjectStorage

I want to "empty" an ObjectStorage when updating a Object:
It's TYPO3 4.6 with a Extbase Extension which allows you to show/add/edit/delete datasets in the frontend. At first sight everything looks good.
I have one field referencing another table:
TCA:
'partner' => array(
'exclude' => 0,
'label' => 'LLL:EXT:toco3_marketingdb/Resources/Private/Language/locallang_db.xlf:tx_toco3marketingdb_domain_model_firma.partner',
'config' => array(
'type' => 'select',
'size' => 5,
'foreign_table' => 'tx_toco3marketingdb_domain_model_partner',
'foreign_table_where' => 'ORDER BY tx_toco3marketingdb_domain_model_partner.partnerpkey',
'minitems' => 0,
'maxitems' => 20,
),
),
Model:
/**
* Partner
*
* #var Tx_Extbase_Persistence_ObjectStorage<Tx_Toco3Marketingdb_Domain_Model_Partner>
* #lazy
*/
protected $partner;
/**
* Sets the partner
*
* #param Tx_Extbase_Persistence_ObjectStorage<Tx_Toco3Marketingdb_Domain_Model_Partner> $partner
* #return void
*/
public function setPartner(Tx_Extbase_Persistence_ObjectStorage $partner) {
$this->partner = $partner;
}
Controller:
$partner = new Tx_Extbase_Persistence_ObjectStorage();
if (count($partnerarr) > 0){
foreach($partnerarr as $p){
$partner->attach( $this->partnerRepository->findByUid($p));
}
}
$organisation = $this->organisationRepository->findByUid($uid)
$organisation->setPartner($partner);
This is working as long there is an Object in the ObjectStorage. So I can add/delete/change relations. But when $partnerarr is empty an no objects get attached an empty Tx_Extbase_Persistence_ObjectStorage is assigned, the old values do not get "deleted". I also tried to assign null or "" but the an error occures because an ObjectStorage is needed. If I assign the empty ObjectStorage I don't get an error, but the old values still maintain :(
Any idea?
Thank you
Christian
Call the detach or removeAll methods to remove certain or all objects of the storage.
/** #var \Tx_Extbase_Persistence_ObjectStorage $organisationPartners */
$organisationPartners = $organisation->getPartner();
foreach ($organisationPartners as $partner) {
$organisationPartners->detach($partner);
}
Thank you #Wolfgang for your message.
I added the following function to my model:
/**
* detach Partner
*
* #param Tx_Toco3Marketingdb_Domain_Model_Partner $partner
* #return void
*/
public function detachPartner($partner) {
$this->partner->detach($partner);
}
In the controller I added:
$persistanceManager = t3lib_div::makeInstance('Tx_Extbase_Persistence_Manager');
$organisation = $this->firmaRepository->findByUid($uid);
$organisationPartners = $organisation->getPartner();
foreach ($organisationPartners as $organisationPartner) {
$organisation->detachPartner($organisationPartner);
}
$persistanceManager->persistAll();
$organisation->setPartner($partner);
It is important to persist before setting the new (empty) value...

Symfony 3 | Custom constraints on CollectionType entities

I followed the documentation and was able to add custom constraints on many of my fields (http://symfony.com/doc/current/validation/custom_constraint.html).
I'm figuring a problem with CollectionType field.
My custom constraint just check if user didn't tap multiple space in field (the constraint doesn't matter anyway).
I have a Question form with a title and answers :
$builder
->add('title', TextType::class)
->add('answers', CollectionType::class, array(
'entry_type' => AnswerType::class,
'allow_add' => true,
'allow_delete' => true,
'by_reference' => false
))
I have my constraint :
use Symfony\Component\Validator\Constraint;
/**
* #Annotation
*/
class ContainsText extends Constraint
{
public $message = 'constraint_error';
}
And my constraint validator :
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
class ContainsTextValidator extends ConstraintValidator
{
public function validate($value, Constraint $constraint)
{
// It checks if user didn't had multiple space in field
if (strlen(trim($value)) == 0) {
$this->context->buildViolation($constraint->message)
->addViolation();
}
}
}
In my entities :
Question:
use XX\XXBundle\Validator\Constraints as CustomAssert;
class Question
{
/**
* #var string
*
* #ORM\Column(name="title", type="string", length=255, unique=true)
* #CustomAssert\ContainsText
*/
private $title;
...
}
Answer :
use XX\XXBundle\Validator\Constraints as CustomAssert;
class Answer
{
/**
* #var string
*
* #ORM\Column(name="text", type="string", length=255, unique=true)
* #CustomAssert\ContainsText
*/
private $text;
...
}
In my form validation, if in Question title I tap many spaces, I get a form validation error with my "constraint_error" message => Everything is working.
But, if in Question answers text I tap many spaces, the form validation doesn't return any errors and my question is created with empty answers !
It seems that, if the field comes from a CollectionType, the custom asserts are ignored.
What I don't understand is, if i had a Assert (like #Assert\Blank(), not a custom one) on answer text, even if we are in a CollectionType, the assert is not ignored and I can't validate a form with a blank answer.
What did I miss here ? TY
Not sure which Symfony 2 version you use, but depending if that is pre 2.8 or later you have different ways to tackle this:
v2.8+ and v3.0+
Starting with v2.8, which I suspect you could be using given AnswerType::class, cascade_validation was deprecated. Instead, you need to applty Valid constraint, on you Question::$answers class member. Something like this:
class Question
{
/**
* ... Other anotaions go here
*
* #Assert\Valid()
*/
private $answers
}
Pre v2.8:
You need to specify cascade_validation option:
$builder
->add('title', TextType::class)
->add('answers', CollectionType::class, array(
'entry_type' => AnswerType::class,
'allow_add' => true,
'allow_delete' => true,
'by_reference' => false,
'cascade_validation' => true // <========= THIS
));
Hope this helps...

Using FAL in Extbase correctly

Domain model
class Image extends AbstractContent {
/**
* #var \TYPO3\CMS\Extbase\Domain\Model\FileReference
*/
protected $file;
/**
* Gets the image file
*
* #return \TYPO3\CMS\Extbase\Domain\Model\FileReference
*/
public function getFile() {
return $this->file;
}
/**
* Sets the image file
*
* #param \TYPO3\CMS\Extbase\Domain\Model\FileReference $file
* #return void
*/
public function setFile($file) {
$this->file = $file;
}
}
Import service fragments
/**
* #var \TYPO3\CMS\Core\Resource\ResourceStorage
*/
protected $defaultStorage;
[...]
$this->defaultStorage = ResourceFactory::getInstance()->getDefaultStorage();
[...]
$file = $this->defaultStorage->addFile(
'/tmp/4711',
$this->defaultStorage->getRootLevelFolder(),
'foo.jpg',
'overrideExistingFile'
);
$falReference = ResourceFactory::getInstance()->createFileReferenceObject(
array(
'uid_local' => $file->getUid(),
'uid_foreign' => uniqid('NEW_'),
'uid' => uniqid('NEW_'),
)
);
$reference = GeneralUtility::makeInstance(FileReference::class);
$reference->setOriginalResource($falReference);
$content = GeneralUtility::makeInstance(Image::class);
$content->setFile($reference);
After saving $content the image is available through the record and the filemount but the Ref column in BE > FILE > File List) is - and not >= 1. So its look like the reference is some how broken. When I'm using the BE to add an image to the record it's all fine. I'm using TYPO3 CMS 7.3-dev.
What's wrong with my code?
I get the hint in the Slack channel of TYPO3.
You just need to set plugin.tx_myext.persistence.updateReferenceIndex = 1 respectively module.tx_myext.persistence.updateReferenceIndex = 1 and the index will be updated.
Alternatively you could use \TYPO3\CMS\Core\Database\ReferenceIndex::updateRefIndexTable().
When I had to use FAL in my extension I found this link:
http://t3-developer.com/extbase-fluid/extensions-erweitern/fal-in-eigenen-extensions/fal-in-typo3-extensions-verwenden/
Since it is in German, I will in the very shortest explain what is done there:
extend your data model in ext_tables.sql
add a column of some char type (e.g. varchar)
add your column to the column section in your TCA array in ext_tables.php
'mypictures' => array(
'exclude' => 1,
'label' => 'My Pictures',
'config' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig('image', array(
'appearance' => array(
'createNewRelationLinkTitle' => 'LLL:EXT:cms/locallang_ttc.xlf:images.addFileReference'
),
'minitems' => 0,
'maxitems' => 99,
), $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext']),
),
Extend your modelfiles. Pay attention to annotations!
You can use your media in your fluid template

Symfony2 mapping file not found

I have a little form, with just a file field to upload a document. I'm using Symfony2.6 with mongodb annotation. I get a "No mapping found for field 'file'" exception.
My document class :
namespace My\Bundle\Document;
use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;
use Symfony\Component\Validator\Constraints as Assert;
/**
* #MongoDB\Document
*/
class ImportFile
{
[...]
/**
* #Assert\File(maxSize = "5M", mimeTypes = {"image/jpeg", "image/gif", "image/png"})
*/
protected $file;
[...]
/**
* #return $file
*/
public function getFile()
{
return $this->file;
}
/**
* #param $file
*/
public function setFile($file)
{
$this->file = $file;
}
(the namespace is correct, i changed it for the post)
Here is my controller with my form builder :
$importFile = new ImportFile();
$form = $this->createFormBuilder($importFile)
->add('file')
->getForm();
The file field should be automatically detected (as it mentioned here http://symfony.com/doc/current/cookbook/doctrine/file_uploads.html) but it doesn't work. If i add:
$form = $this->createFormBuilder($importFile)
->add('file','file')
->getForm();
it works, but i should'nt have to add the file type as it should be automatically detected. what am i doing wrong ?
I think the problem is in your annotation. You added just an assert but no field definition:
/**
* #Field(type="file")
* #Assert\File(maxSize = "5M", mimeTypes = {"image/jpeg", "image/gif", "image/png"})
*/
I hope it helps.
As you mention here:
I don't want this field to be mapped in the database
You should use mapped property at form field definition:
mapped => false
So, this should resolved your problem ( but remeber that after submit, value from file property will not be mapped with your odm Document ):
$form = $this->createFormBuilder($importFile)
->add('file', 'file', array(
'mapped' => false
))
->getForm();
More here: http://symfony.com/doc/current/reference/forms/types/text.html#mapped