Merge pull request #1996 from Haendlerbund/introduce-api-token-columns-into-database

add missing api_token columns to database (table customers and admins)
This commit is contained in:
Jitendra Singh 2020-01-27 18:31:13 +05:30 committed by GitHub
commit 0cd4a2678a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 70 additions and 7 deletions

View File

@ -0,0 +1,52 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddApiTokenColumns extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
// @see https://laravel.com/docs/6.x/api-authentication#database-preparation
Schema::table('customers', function ($table) {
$table
->string('api_token', 80)
->after('password')
->unique()
->nullable()
->default(null);
});
Schema::table('admins', function ($table) {
$table
->string('api_token', 80)
->after('password')
->unique()
->nullable()
->default(null);
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('customers', function (Blueprint $table) {
$table->dropColumn('api_token');
});
Schema::table('admins', function (Blueprint $table) {
$table->dropColumn('api_token');
});
}
}

View File

@ -2,6 +2,8 @@
namespace Webkul\Customer\Http\Controllers;
use Illuminate\Support\Str;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\Mail;
use Webkul\Customer\Mail\RegistrationEmail;
@ -85,6 +87,7 @@ class RegistrationController extends Controller
$data = request()->input();
$data['password'] = bcrypt($data['password']);
$data['api_token'] = Str::random(80);
if (core()->getConfigData('customer.settings.email.verification')) {
$data['is_verified'] = 0;

View File

@ -17,9 +17,9 @@ class Customer extends Authenticatable implements CustomerContract, JWTSubject
protected $table = 'customers';
protected $fillable = ['first_name', 'last_name', 'gender', 'date_of_birth', 'email', 'phone', 'password', 'customer_group_id', 'subscribed_to_news_letter', 'is_verified', 'token', 'notes', 'status'];
protected $fillable = ['first_name', 'last_name', 'gender', 'date_of_birth', 'email', 'phone', 'password', 'api_token', 'customer_group_id', 'subscribed_to_news_letter', 'is_verified', 'token', 'notes', 'status'];
protected $hidden = ['password', 'remember_token'];
protected $hidden = ['password', 'api_token', 'remember_token'];
/**
* Get the customer full name.

View File

@ -2,6 +2,7 @@
namespace Webkul\User\Database\Seeders;
use Illuminate\Support\Str;
use Illuminate\Database\Seeder;
use DB;
@ -16,6 +17,9 @@ class AdminsTableSeeder extends Seeder
'name' => 'Example',
'email' => 'admin@example.com',
'password' => bcrypt('admin123'),
'api_token' => Str::random(80),
'created_at' => date('Y-m-d H:i:s'),
'updated_at' => date('Y-m-d H:i:s'),
'status' => 1,
'role_id' => 1,
]);

View File

@ -2,6 +2,7 @@
namespace Webkul\User\Http\Controllers;
use Illuminate\Support\Str;
use Illuminate\Support\Facades\Event;
use Webkul\User\Repositories\AdminRepository;
use Webkul\User\Repositories\RoleRepository;
@ -90,8 +91,10 @@ class UserController extends Controller
{
$data = $request->all();
if (isset($data['password']) && $data['password'])
if (isset($data['password']) && $data['password']) {
$data['password'] = bcrypt($data['password']);
$data['api_token'] = Str::random(80);
}
Event::dispatch('user.admin.create.before');
@ -130,10 +133,11 @@ class UserController extends Controller
{
$data = $request->all();
if (! $data['password'])
if (! $data['password']) {
unset($data['password']);
else
} else {
$data['password'] = bcrypt($data['password']);
}
if (isset($data['status'])) {
$data['status'] = 1;

View File

@ -19,7 +19,7 @@ class Admin extends Authenticatable implements AdminContract
* @var array
*/
protected $fillable = [
'name', 'email', 'password', 'role_id', 'status',
'name', 'email', 'password', 'api_token', 'role_id', 'status',
];
/**
@ -28,7 +28,7 @@ class Admin extends Authenticatable implements AdminContract
* @var array
*/
protected $hidden = [
'password', 'remember_token',
'password', 'api_token', 'remember_token',
];
/**