Posts

Yii2: Validate email after registration

Image
Goals: Verify user email Deny login for unverified email Resend verification for expired/lost verification Verify within certain time frame  Recover lost password Recover within certain time frame Resend recovery for expired/lost recovery  You may want to read this first . Part 1: Configuration Edit config\db.php to point to your DB. Create table for users and verification token. CREATE TABLE `users` ( `id` bigint unsigned NOT NULL AUTO_INCREMENT, `email` varchar(255) NOT NULL, `password_hash` varchar(255) NOT NULL, `confirmed_at` datetime NOT NULL, `registration_ip` varchar(255) NOT NULL, `created_at` datetime NOT NULL, `updated_at` datetime NOT NULL ON UPDATE CURRENT_TIMESTAMP, `last_login_at` datetime NOT NULL, `last_login_ip` varchar(255) NOT NULL, PRIMARY KEY (`id`), KEY `email` (`email`) USING BTREE ); CREATE TABLE `token` ( `uid` bigint unsigned NOT NULL, `code` varchar(32) COLLATE utf8_unicode_ci NOT NULL, `created_at` ...

Comfigure VLAN for TM Unifi

Router: WAN Port (Internet): Enable VLAN: Yes VLAN ID: 500 Tagged: Tagged IP TV Port: Enable VLAN: Yes VLAN ID: 600 Tagged: Untagged Other Ports (LAN): Enable VLAN: No VLAN ID: <Blank&gt> Tagged: Exclude Network Switch: VLAN 1 ID: 1 Name: Default Ports: Select all ports Tagged Ports: None Untagged Ports: Select all ports VLAN 2 ID: 500 Name: Internet Ports: 1 and 2 (or select any other 2 ports) Tagged Ports: 1 (This will connect to BTU) Untagged Ports: 2 (This will connect to router or PC) VLAN 3 ID: 600 Name: IPTV Ports: 1 and 3 (select same port as tagged port in VLAN 500 and select one other unused port) Tagged Ports: 1 (This will connect to BTU, same tagged port as in VLAN 500) Untagged Ports: 3 (This will connect to IPTV STB) Note, you cannot use other ports in the switch for your LAN. Credit: https://www.blacktubi.com/guide/make-any-router-work-on-unifi

Enable Search Engine Friendly (Pretty URLs) in Yii2

In config/web.php : 'urlManager' => [ 'class' => 'yii\web\UrlManager', // Hide index.php 'showScriptName' => false, // Use pretty URLs 'enablePrettyUrl' => true, 'rules' => [ ], ], Create .htaccess file in web root folder: RewriteEngine on # If a directory or a file exists, use the request directly RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d # Otherwise forward the request to index.php RewriteRule . index.php To use Gii in Pretty URL, add these in rules: 'urlManager' => [ 'class' => 'yii\web\UrlManager', // Hide index.php 'showScriptName' => false, // Use pretty URLs 'enablePrettyUrl' => true, 'rules' => [ 'gii' => 'gii', 'gii/<controller:\w+>' => 'gii/<controller>', 'gii/<controller:\w+>/...

Yii2 login from database

Image
Create users table CREATE TABLE `users` (   `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,   `email` varchar(255) DEFAULT NULL,   `password_hash` varchar(255) DEFAULT NULL,   PRIMARY KEY (`id`),   KEY `email` (`email`) USING BTREE );    Create Users Model While you are at Gii, you should create search model too. Add the following namespaces in Users model class use yii\base\NotSupportedException; use yii\db\ActiveRecord; use yii\helpers\Security; use yii\web\IdentityInterface;  Implements the IdentityInterface interface class with Users model class class Users extends \yii\db\ActiveRecord  implements IdentityInterface Then add all the inherited functions from yii\web\IdentityInterface . See https://www.yiiframework.com/doc/api/2.0/yii-web-identityinterface Add function validatePassword in model/Users.php. /**      * Validates password   ...

Find table in MySQL

show tables like '%part_of_table_name%'

Installing Yii2

composer create-project --prefer-dist yiisoft/yii2-app-basic [folder_name]

PostgreSQL in WAMP

Uncomment the lines extension=pdo_pgsql.so and e xtension=pgsql.so in php.ini . Copy libpq.dll from C:\wamp\bin\php\php5.*\ into C:\wamp\bin\apache*\bin and restart all services through the WampServer interface.