Why yii 2 mailer not send email? - yii

My yii 2 web config
'components' => [
'mailer' => [
'class' => 'yii\swiftmailer\Mailer',
'transport' => [
'class' => 'Swift_SmtpTransport',
'host' => 'smtp.send-box.ru',
'username' => 'sendbox#jobgis.ru',
'password' => 'password',
'port' => '587',
'encryption' => 'tls',
],
],
My yii 2 controller for send mail
public function actionSpam(){
Yii::$app->mailer->compose()
->setFrom('sendbox#jobgis.ru')
->setTo('jetananas#yandex.ru')
->setSubject('Тема сообщения')
->setTextBody('Текст сообщения')
->setHtmlBody('<b>текст сообщения в формате HTML</b>')
->send();
}
Why mail not sending?
Why mailer not display errors?

Related

Yii2 How disable Redis

I made the deply of my application (Yii2) in the production environment of the client and there he uses REDIS in another application (Laravel).
However in my Yii2 application I have nothing using or instantiating REDIS, however when running the error appears below. How do I disable REDIS in the application?
Example web.php
'session' => [
'name' => '_siscoopSessionId',
'savePath' => __DIR__ . '/../runtime',
],
'cache' => [
'class' => 'yii\caching\FileCache',
],
UPDATE
My db.php
return [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=srv-probat;dbname=siscoop',
'username' => 'intranet',
'password' => '*****',
'charset' => 'utf8',
];
Solution:
Remove all this code:
'session' => [
'name' => '_appnameSessionId',
'savePath' => DIR . '/../runtime',
],
'cache' => [
'class' => 'yii\caching\FileCache',
],

Laravel 5.8 LDAP Authentication not working - LdapRecord Package

I'm trying to implements an LDAP authentication in an application for my company. I'm using Laravel 5.8 and the LdapRecord package
I have succeed to connect the application with the LDAP server test see Successfully connected and my to authenticate with openldap to online server its also Successfully. but when i want to do the authentication with active directory to my app it not working , Why who can help me?
Here is my code :
The .env
LDAP_LOGGING=true
LDAP_CONNECTION=default
LDAP_HOST=server
LDAP_PORT=389
LDAP_BASE_DN="dc=mydomain,dc=local"
LDAP_TIMEOUT=5
LDAP_SSL=false
LDAP_TLS=false
The ldap.php
return [
'default' => env('LDAP_CONNECTION', 'default'),
'connections' => [
'default' => [
'hosts' => [env('LDAP_HOST', 'server')],
'username' => env('LDAP_USERNAME', ''),
'password' => env('LDAP_PASSWORD', ''),
'port' => env('LDAP_PORT', 389),
'base_dn' => env('LDAP_BASE_DN', 'dc=mydomain,dc=local'),
'timeout' => env('LDAP_TIMEOUT', 5),
'use_ssl' => env('LDAP_SSL', false),
'use_tls' => env('LDAP_TLS', false),
],
],
'logging' => env('LDAP_LOGGING', true),
'cache' => [
'enabled' => env('LDAP_CACHE', false),
'driver' => env('CACHE_DRIVER', 'file'),
],
];
The auth.php
return [
'defaults' => [
'guard' => 'web',
'passwords' => 'users',
],
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'ldap',
],
'api' => [
'driver' => 'token',
'provider' => 'users',
'hash' => false,
],
],
'providers' => [
'users' => [
'driver' => 'eloquent' ,
'model' => App \ User :: class,
],
'ldap' => [
'driver' => 'ldap',
'model' => LdapRecord\Models\ActiveDirectory\User::class,
// 'model' => LdapRecord\Models\OpenLDAP\User::class,
'database' => [
'model' => App\User::class,
'sync_passwords' => false,
'sync_attributes' => [
'name' => 'cn',
'email' => 'mail',
],
],
]
// 'users' => [
// 'driver' => 'database',
// 'table' => 'users',
// ],
],
'passwords' => [
'users' => [
'provider' => 'users',
'table' => 'password_resets',
'expire' => 60,
'throttle' => 60,
],
],
'password_timeout' => 10800,
];
The user.php model
namespace App;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use LdapRecord\Laravel\Auth\LdapAuthenticatable;
use LdapRecord\Laravel\Auth\AuthenticatesWithLdap;
class User extends Authenticatable implements LdapAuthenticatable
{
use Notifiable, AuthenticatesWithLdap, HasLdapUser ;
protected $fillable = [
'name',
'email',
'password',
];
protected $hidden = [
'password', 'remember_token' ,
];
protected $casts = [
'email_verified_at' => 'datetime',
];
}
The LoginController
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use App\Providers\RouteServiceProvider;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Http\Request;
class LoginController extends Controller
{
use AuthenticatesUsers;
protected $redirectTo = RouteServiceProvider::HOME;
/**
* Create a new controller instance.
*
* #return void
*/
public function __construct()
{
$this->middleware('guest')->except('logout');
}
protected function credentials(Request $request)
{
return [
'uid' => $request->get('username'),
'password' => $request->get('password'),
];
}
public function username()
{
return 'username';
}
}
Is there anyone who has already used this package and can help me on my code ? thank you in advance :)

Get full url of current webpage in Yii2

How to get the full URl in address bar to my Yii2 Model using yii\helpers\Url ?
I use $currentUrl = Yii::$app->request->url; but it return site/submit which is defined already in my UrlManager :
'urlManager' => [
'enableStrictParsing' => true,
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
'/' => 'site/index',
'site/submit' => 'site/submit',
'admin' => 'admin/index',
'admin/login' => 'admin/login',
'admin/index' => 'admin/index',
'admin/logout' => 'admin/logout',
'/<url:.+>' => 'site/index',
'defaultRoute' => 'site/index',
],
],
Best regards,
Yii::$app->request->absoluteUrl
Plz follow this yii2 document
Yii::app()->createAbsoluteUrl(Yii::app()->request->url)

Relation two database and make join yii2

Can you help me. How to relate it and make a join
. i get error has no relation named "project".
i using ActiveRecord with my code :
$posts = MaKantor::find()
->leftJoin('project.track', '`track`.`id_office` = `m_kantor`.`kantor_id`')
->with('project.track')->where(['collecting_id' => $model->collecting_id])
->all();
and config
'db' => [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=localhost;dbname=project',
'username' => 'root',
'password' => '',
'charset' => 'utf8',
],
'db2' => [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=localhost;dbname=db_master',
'username' => 'root',
'password' => '',
'charset' => 'utf8',
],
When you use with('relationName') in query, relation function needs to be defined in MaKantor model.
For example :
public function getProject()
{
return $this->hasOne(Project::className(), ['id' => 'project_id']);
}

CakePHP 2 Auth Not Working - Blowfish

I'm using CakePHP 2.8.5. It's not letting me log in "Username or password is incorrect". This seems totally straightforward in the docs but it isn't working for me. I wonder if my model/data structure might be confusing CakePHP. I have a Users model, but the logins are associated with an Admins model. The login form and action are in the Pages model (it has forms for multiple models).
in AppController:
public $components = array(
'DebugKit.Toolbar',
'Flash',
'Session',
'Auth' => array(
'userModel' => 'Admin',
'authenticate' => array(
'Form' => array(
'fields' => array(
'username' => 'email',
'password' => 'password'
),
'passwordHasher' => 'Blowfish'
)
),
'loginAction' => array(
'controller' => 'pages',
'action' => 'login',
),
'logoutRedirect' => array(
'controller' => 'pages',
'action' => 'login',
),
'authError' => 'Please log in',
'authorize' => array('Controller')
)
);
My login view, in /View/Pages. "email" is the username field:
<?php
echo $this->Form->create('Admin');
echo $this->Form->input('email');
echo $this->Form->input('password');
echo $this->Form->end('Submit');
?>
PagesController:
public function login() {
if ($this->request->is('post')) {
if ($this->Auth->login()) {
return $this->redirect($this->Auth->redirect());
} else {
$this->Flash->error(__('Username or password is incorrect'));
}
}}
Top of Admin model:
App::uses('BlowfishPasswordHasher', 'Controller/Component/Auth');
Automatic Blowfish encryption in Admin model:
public function beforeSave($options = array()) {
if (isset($this->data['Admin']['password'])) {
$passwordHasher = new BlowfishPasswordHasher();
$this->data['Admin']['password'] = $passwordHasher->hash(
$this->data['Admin']['password']
);
}
return true;
}
I notice if I enter the same password for different Admins, I get a different encryption result, but I've read that's normal.
If you want to see anything else, I'll add it.
The userModel key is in the wrong place
Compare the config in the question:
public $components = array(
'DebugKit.Toolbar',
'Flash',
'Session',
'Auth' => array(
'userModel' => 'Admin',
'authenticate' => array(
'Form' => array(
'fields' => array(
'username' => 'email',
'password' => 'password'
),
'passwordHasher' => 'Blowfish'
)
),
To the config in the docs:
$this->Auth->authenticate = array(
'Basic' => array('userModel' => 'Member'),
'Form' => array('userModel' => 'Member')
);
In the question userModel is a top-level key, in the docs it is part of the individual authenticate keys. Looking at the api examples (or the doc blocks in the source code) the error is more clear:
... you can define settings that should be set to all authentications objects using the 'all' key:
$this->Auth->authenticate = array(
'all' => array(
'userModel' => 'Users.User',
'scope' => array('User.active' => 1)
),
'Form',
'Basic'
);
It is possible to define a global userModel for all authenticate objects to use, but the syntax is simply different than the question.
Use the all key
Therefore to define a user model to use for all authenticate options, use the all key:
public $components = array(
'DebugKit.Toolbar',
'Flash',
'Session',
'Auth' => array(
//'userModel' => 'Admin', // <- no
'authenticate' => array(
'all' => array(
'userModel' => 'Admin' // <- yes
),
'Form' => array(
'fields' => array(
'username' => 'email',
'password' => 'password'
),
'passwordHasher' => 'Blowfish'
)
),