Posts

Showing posts with the label Yii2

Yii2: Authentication with Google and Facebook

Image
This is continuation from https://takdekeje.kuceng.my/2018/08/yii2-validate-email-after-registration.html . Objective: Register and login with Google and Facebook account. Link existing account with Google and Facebook. Unlink  existing account from Google and Facebook. You may truncate both tables to start fresh. Part 1: Initial setup Install  AuthClient Extension . composer require "yiisoft/yii2-authclient:*" Create new migration to update DB yii migrate/create authclient Edit the migration file: <?php use yii\db\Migration; /** * Class m180926_083206_auth */ class m180926_083206_auth extends Migration { /** * {@inheritdoc} */ public function safeUp() { } /** * {@inheritdoc} */ public function safeDown() { echo "m180926_083206_auth cannot be reverted.\n"; return false; } // Use up()/down() to run migration code without a t...

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` ...