validator fixed

This commit is contained in:
ilmedova 2022-07-06 17:38:03 +05:00
parent e9f3fdfd38
commit ca9e516315
30 changed files with 735 additions and 30 deletions

View File

@ -2,9 +2,11 @@
namespace App\Http\Controllers;
use App\Mail\EmailVerification;
use App\Mail\ResetPassword;
use App\Models\Client;
use App\Models\User;
use Exception;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;
@ -15,6 +17,7 @@
use Illuminate\Support\Facades\Password;
use Illuminate\Support\Facades\Validator;
use Illuminate\Auth\Events\PasswordReset;
use Illuminate\Support\Facades\Config;
use Illuminate\Validation\ValidationException;
/**
@ -69,30 +72,31 @@ class AuthController extends Controller
* )
*/
public function login(Request $request){
$validatedData = request()->validate([
'email' => 'required',
'password' => 'required|min:6'
]);
if($request->email == null || $request->password == null){
// get user object
$client = Client::where('email', request()->email)->first();
// get user object
$client = Client::where('email', request()->email)->first();
if($client){
// do the passwords match?
if (!Hash::check(request()->password, $client->password)) {
// no they don't
return response()->json(['error' => 'Unauthorized'], 401);
if($client){
// do the passwords match?
if (!Hash::check(request()->password, $client->password)){
// no they don't
return response()->json(['error' => 'Unauthorized'], 401);
}
Auth::login($client);
// get new token
$tokenResult = $client->createToken('auth_token');
// return token in json response
return response()->json(['success' => ['token' => $tokenResult, 'client' => $client]], 200);
}
Auth::login($client);
// get new token
$tokenResult = $client->createToken('auth_token');
// return token in json response
return response()->json(['success' => ['token' => $tokenResult, 'client' => $client]], 200);
return response()->json(['error' => ['message' => 'email not found']], 404);
}
else{
return response()->json(['error' => ['message' => 'missing fields']], 400);
}
return response()->json(['error' => ['message' => 'email not found']], 404);
}
/**
@ -135,6 +139,45 @@ public function login(Request $request){
* )
*/
public function register(Request $request){
$email_verification = Config::get('email_verification');
if($email_verification){
$validatedData = request()->validate([
'email' => 'required',
'password' => 'required|min:6',
'firstname' => 'required',
'lastname' => 'required',
]);
$data = $request->all();
// hashing client's passord
$data['password'] = Hash::make($data['password']);
$token = rand(1000, 9999);//generate code
$data['token'] = $token;
$data['is_verified'] = 0;//is_verified is false until i checke the code sent to mail of the client
// set client's status to false (Admin will set the client's status from Admin Panel)
$data['status'] = false;
$client = Client::where('email', $data['email'])->first();
if($client){
return response()->json([
'error' => 'This email is already used'
], 401);
}
$client = Client::create($data);
Mail::to($request->email)->send(new EmailVerification($client->firstname, $token));
return response()->json([
'message' => 'confirmation code sent',
'email' => $client->email
],200);
}
$validatedData = request()->validate([
'email' => 'required',
'password' => 'required|min:6',
@ -168,6 +211,16 @@ public function register(Request $request){
return response()->json(['success' => ['token' => $tokenResult]], 200);
}
public function verifyEmail(Request $request){
$data = $request->all();
if(count($data) < 2){
return response()->json([
'message' => 'Oops! Email or code missing'
],400);
}
}
/**
* @OA\GET(
* path="/api/client",
@ -260,7 +313,7 @@ public function sendPasswordResetLinkEmail(Request $request) {
$user['is_verified'] = 0;
$user->save();
Mail::to($request->email)->send(new ResetPassword($user->name, $token));
Mail::to($request->email)->send(new ResetPassword($user->firstname, $token));
return response()->json([
'message' => 'OK'

View File

@ -0,0 +1,42 @@
<?php
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
class EmailVerification extends Mailable
{
use Queueable, SerializesModels;
/**
* Create a new message instance.
*
* @return void
*/
public $name;
public $token;
public function __construct($name, $token)
{
$this->name = $name;
$this->token = $token;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
$user['name'] = $this->name;
$user['token'] = $this->token;
return $this->from("milmedova96@gmail.com", "Email Verification")
->subject('Verify your email')
->view('emails.email-verification', ['user' => $user]);
}
}

View File

@ -36,8 +36,8 @@ public function build()
$user['name'] = $this->name;
$user['token'] = $this->token;
return $this->from("milmedova96@gmail.com", "Birzha Legalizasiya")
->subject('Password Reset Code')
return $this->from("milmedova96@gmail.com", "Password reset code")
->subject('Resetting your password')
->view('emails.reset-password', ['user' => $user]);
}
}

View File

@ -11,6 +11,7 @@
"backpack/langfilemanager": "^4.1",
"backpack/logmanager": "^4.0",
"backpack/permissionmanager": "^6.0",
"backpack/settings": "^3.0",
"darkaonline/l5-swagger": "^8.3",
"guzzlehttp/guzzle": "^7.2",
"laravel/framework": "^9.11",

70
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "34dfb40a282b09cd02b95d2d446a0cd6",
"content-hash": "78b0d0de785ca43a7043e048b3e717b6",
"packages": [
{
"name": "backpack/crud",
@ -379,6 +379,74 @@
},
"time": "2022-04-18T13:32:50+00:00"
},
{
"name": "backpack/settings",
"version": "3.0.16",
"source": {
"type": "git",
"url": "https://github.com/Laravel-Backpack/Settings.git",
"reference": "c487c532f91236ec573b208ba022bb1a04e6d0a2"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/Laravel-Backpack/Settings/zipball/c487c532f91236ec573b208ba022bb1a04e6d0a2",
"reference": "c487c532f91236ec573b208ba022bb1a04e6d0a2",
"shasum": ""
},
"require": {
"backpack/crud": "^4.0|^5.0"
},
"require-dev": {
"phpunit/phpunit": "^9.0||^7.0",
"scrutinizer/ocular": "~1.1"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.0-dev"
},
"laravel": {
"providers": [
"Backpack\\Settings\\SettingsServiceProvider"
]
}
},
"autoload": {
"psr-4": {
"Backpack\\Settings\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"proprietary"
],
"authors": [
{
"name": "Cristian Tabacitu",
"email": "tabacitu@backpackforlaravel.com",
"homepage": "https://backpackforlaravel.com",
"role": "Chief Architect & Lead Developer"
}
],
"description": "Application settings interface for Laravel 5 using Backpack CRUD.",
"homepage": "https://github.com/laravel-backpack/settings",
"keywords": [
"backpack",
"backpack settings",
"dick",
"dick settings",
"laravel backpack",
"manage settings",
"settings admin",
"tabacitu",
"updivision"
],
"support": {
"issues": "https://github.com/Laravel-Backpack/Settings/issues",
"source": "https://github.com/Laravel-Backpack/Settings/tree/3.0.16"
},
"time": "2022-04-18T13:27:13+00:00"
},
{
"name": "barryvdh/elfinder-flysystem-driver",
"version": "v0.4.3",

View File

@ -0,0 +1,50 @@
<?php
return [
/*
|--------------------------------------------------------------------------
| Table Name
|--------------------------------------------------------------------------
|
| Database Settings Table Name
|
*/
'table_name' => 'settings',
/*
|--------------------------------------------------------------------------
| Route
|--------------------------------------------------------------------------
|
| URL Segment aka route to the Settings panel.
|
*/
'route' => 'setting',
/*
|--------------------------------------------------------------------------
| Config Prefix
|--------------------------------------------------------------------------
|
| The prefix used to add your settings into the configuration array.
| With this default you can grab your settings with: config('settings.your_setting_key')
|
| WARNING: WE ADVISE TO NOT LEAVE THIS EMPTY / CHECK IF IT DOES NOT CONFLICT WITH OTHER CONFIG FILE NAMES
|
| - if you leave this empty and your keys match other configuration files you might ovewrite them.
|
*/
'config_prefix' => 'settings',
/*
|--------------------------------------------------------------------------
| Migration file name
|--------------------------------------------------------------------------
|
| The file name for the settings migration file. It will be created in database_path('/migrations/%name_you_choose%.php)
| Note: .php extension is automatically added.
|
*/
'migration_name' => '2015_08_04_131614_create_settings_table',
];

View File

@ -0,0 +1,36 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
class CreateSettingsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create(config('backpack.settings.table_name'), function (Blueprint $table) {
$table->increments('id');
$table->string('key')->unique();
$table->string('name');
$table->string('description')->nullable();
$table->text('value')->nullable();
$table->text('field');
$table->tinyInteger('active');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop(config('backpack.settings.table_name'));
}
}

View File

@ -14,11 +14,9 @@ class DatabaseSeeder extends Seeder
*/
public function run()
{
// \App\Models\User::factory(10)->create();
// \App\Models\User::factory()->create([
// 'name' => 'Test User',
// 'email' => 'test@example.com',
// ]);
$this->call([
SettingsSeeder::class,
]);
}
}

View File

@ -0,0 +1,44 @@
<?php
namespace Database\Seeders;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
class SettingsSeeder extends Seeder
{
/**
* The settings to add.
*/
protected $settings = [
[
'key' => 'email_verification',
'name' => 'Email verification of clients',
'description' => 'Controllable email verification',
'value' => true,
'field' => '{"name":"value","label":"Value","type":"checkbox"}',
'active' => 1,
],
];
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
foreach ($this->settings as $index => $setting) {
$result = DB::table(config('backpack.settings.table_name'))->insert($setting);
if (!$result) {
$this->command->info("Insert failed at record $index.");
return;
}
}
$this->command->info('Inserted '.count($this->settings).' records.');
}
}

18
lang/vendor/backpack/ar/settings.php vendored Normal file
View File

@ -0,0 +1,18 @@
<?php
return [
/*
|--------------------------------------------------------------------------
| Settings Language Lines
|--------------------------------------------------------------------------
|
| The following language lines are used for Laravel Backpack - Settings
|
*/
'name' => 'الإسم',
'value' => 'القيمة',
'description' => 'الوصف',
'setting_singular' => 'إعداد',
'setting_plural' => 'إعدادات',
];

18
lang/vendor/backpack/da_DK/settings.php vendored Normal file
View File

@ -0,0 +1,18 @@
<?php
return [
/*
|--------------------------------------------------------------------------
| Settings Language Lines
|--------------------------------------------------------------------------
|
| The following language lines are used for Laravel Backpack - Settings
| Author: Frederik Rabøl (frederik-rm@hotmail.com)
*/
'name' => 'Navn',
'value' => 'værdi',
'description' => 'beskrivelse',
'setting_singular' => 'indstilling',
'setting_plural' => 'indstillinger',
];

18
lang/vendor/backpack/de/settings.php vendored Normal file
View File

@ -0,0 +1,18 @@
<?php
return [
/*
|--------------------------------------------------------------------------
| Settings Language Lines
|--------------------------------------------------------------------------
|
| The following language lines are used for Laravel Backpack - Settings
|
*/
'name' => 'Name',
'value' => 'Wert',
'description' => 'Beschreibung',
'setting_singular' => 'Einstellung',
'setting_plural' => 'Einstellungen',
];

18
lang/vendor/backpack/en/settings.php vendored Normal file
View File

@ -0,0 +1,18 @@
<?php
return [
/*
|--------------------------------------------------------------------------
| Settings Language Lines
|--------------------------------------------------------------------------
|
| The following language lines are used for Laravel Backpack - Settings
|
*/
'name' => 'Name',
'value' => 'Value',
'description' => 'Description',
'setting_singular' => 'setting',
'setting_plural' => 'settings',
];

18
lang/vendor/backpack/es/settings.php vendored Normal file
View File

@ -0,0 +1,18 @@
<?php
return [
/*
|--------------------------------------------------------------------------
| Settings Language Lines
|--------------------------------------------------------------------------
|
| The following language lines are used for Laravel Backpack - Settings
|
*/
'name' => 'Nombre',
'value' => 'Valor',
'description' => 'Descripción',
'setting_singular' => 'configuración',
'setting_plural' => 'configuraciones',
];

18
lang/vendor/backpack/fa/settings.php vendored Normal file
View File

@ -0,0 +1,18 @@
<?php
return [
/*
|--------------------------------------------------------------------------
| Settings Language Lines
|--------------------------------------------------------------------------
|
| The following language lines are used for Laravel Backpack - Settings
|
*/
'name' => 'نام',
'value' => 'ارزش',
'description' => 'توضیحات',
'setting_singular' => 'تنظیمات',
'setting_plural' => 'تنظیمات',
];

18
lang/vendor/backpack/fr/settings.php vendored Normal file
View File

@ -0,0 +1,18 @@
<?php
return [
/*
|--------------------------------------------------------------------------
| Settings Language Lines
|--------------------------------------------------------------------------
|
| The following language lines are used for Laravel Backpack - Settings
|
*/
'name' => 'Nom',
'value' => 'Valeur',
'description' => 'Description',
'setting_singular' => 'paramètre',
'setting_plural' => 'paramètres',
];

18
lang/vendor/backpack/id/settings.php vendored Normal file
View File

@ -0,0 +1,18 @@
<?php
return [
/*
|--------------------------------------------------------------------------
| Settings Language Lines
|--------------------------------------------------------------------------
|
| The following language lines are used for Laravel Backpack - Settings
|
*/
'name' => 'Nama',
'value' => 'Nilai',
'description' => 'Deskripsi',
'setting_singular' => 'Pengaturan',
'setting_plural' => 'Pengaturan',
];

18
lang/vendor/backpack/it/settings.php vendored Normal file
View File

@ -0,0 +1,18 @@
<?php
return [
/*
|--------------------------------------------------------------------------
| Settings Language Lines
|--------------------------------------------------------------------------
|
| The following language lines are used for Laravel Backpack - Settings
|
*/
'name' => 'Nome',
'value' => 'Valore',
'description' => 'Descrizione',
'setting_singular' => 'impostazione',
'setting_plural' => 'impostazioni',
];

18
lang/vendor/backpack/lo/settings.php vendored Normal file
View File

@ -0,0 +1,18 @@
<?php
return [
/*
|--------------------------------------------------------------------------
| Settings Language Lines
|--------------------------------------------------------------------------
|
| The following language lines are used for Laravel Backpack - Settings
|
*/
'name' => 'ຊື່',
'value' => 'ຄ່າທີ່ລະບຸ',
'description' => 'ຄໍາອະທິບາຍ',
'setting_singular' => 'ການຕັ້ງຄ່າ',
'setting_plural' => 'ການຕັ້ງຄ່າຕ່າງໆ',
];

18
lang/vendor/backpack/nl/settings.php vendored Normal file
View File

@ -0,0 +1,18 @@
<?php
return [
/*
|--------------------------------------------------------------------------
| Settings Language Lines
|--------------------------------------------------------------------------
|
| The following language lines are used for Laravel Backpack - Settings
|
*/
'name' => 'Naam',
'value' => 'Waarde',
'description' => 'Beschrijving',
'setting_singular' => 'instelling',
'setting_plural' => 'instellingen',
];

18
lang/vendor/backpack/pt/settings.php vendored Normal file
View File

@ -0,0 +1,18 @@
<?php
return [
/*
|--------------------------------------------------------------------------
| Settings Language Lines
|--------------------------------------------------------------------------
|
| The following language lines are used for Laravel Backpack - Settings
|
*/
'name' => 'Nome',
'value' => 'Valor',
'description' => 'Descrição',
'setting_singular' => 'configuração',
'setting_plural' => 'configurações',
];

17
lang/vendor/backpack/pt_br/settings.php vendored Normal file
View File

@ -0,0 +1,17 @@
<?php
return [
/*
|--------------------------------------------------------------------------
| Settings Language Lines
|--------------------------------------------------------------------------
|
| The following language lines are used for Laravel Backpack - Settings
|
*/
'name' => 'Nome',
'value' => 'Valor',
'description' => 'Descrição',
'setting_singular' => 'configuração',
'setting_plural' => 'configurações',
];

18
lang/vendor/backpack/ru/settings.php vendored Normal file
View File

@ -0,0 +1,18 @@
<?php
return [
/*
|--------------------------------------------------------------------------
| Settings Language Lines
|--------------------------------------------------------------------------
|
| The following language lines are used for Laravel Backpack - Settings
|
*/
'name' => 'Название',
'value' => 'Значение',
'description' => 'Описание',
'setting_singular' => 'настройка',
'setting_plural' => 'настройки',
];

18
lang/vendor/backpack/sr/settings.php vendored Normal file
View File

@ -0,0 +1,18 @@
<?php
return [
/*
|--------------------------------------------------------------------------
| Settings Language Lines
|--------------------------------------------------------------------------
|
| The following language lines are used for Laravel Backpack - Settings
|
*/
'name' => 'Naziv',
'value' => 'Vrednost',
'description' => 'Opis',
'setting_singular' => 'Podešavanje',
'setting_plural' => 'Podešavanja',
];

18
lang/vendor/backpack/tr/settings.php vendored Normal file
View File

@ -0,0 +1,18 @@
<?php
return [
/*
|--------------------------------------------------------------------------
| Settings Language Lines
|--------------------------------------------------------------------------
|
| The following language lines are used for Laravel Backpack - Settings
|
*/
'name' => 'Adı',
'value' => 'Değer',
'description' => 'Açıklama',
'setting_singular' => 'ayar',
'setting_plural' => 'ayarlar',
];

18
lang/vendor/backpack/uk/settings.php vendored Normal file
View File

@ -0,0 +1,18 @@
<?php
return [
/*
|--------------------------------------------------------------------------
| Settings Language Lines
|--------------------------------------------------------------------------
|
| The following language lines are used for Laravel Backpack - Settings
|
*/
'name' => 'Назва',
'value' => 'Значення',
'description' => 'Опис',
'setting_singular' => 'настройка',
'setting_plural' => 'настройки',
];

18
lang/vendor/backpack/vi/settings.php vendored Normal file
View File

@ -0,0 +1,18 @@
<?php
return [
/*
|--------------------------------------------------------------------------
| Settings Language Lines
|--------------------------------------------------------------------------
|
| The following language lines are used for Laravel Backpack - Settings
|
*/
'name' => 'Tên',
'value' => 'Giá trị',
'description' => 'Mô tả',
'setting_singular' => 'cấu hình',
'setting_plural' => 'các cấu hình',
];

18
lang/vendor/backpack/zh-cn/settings.php vendored Normal file
View File

@ -0,0 +1,18 @@
<?php
return [
/*
|--------------------------------------------------------------------------
| Settings Language Lines
|--------------------------------------------------------------------------
|
| The following language lines are used for Laravel Backpack - Settings
|
*/
'name' => '名称',
'value' => '值',
'description' => '描述',
'setting_singular' => '设置',
'setting_plural' => '设置',
];

View File

@ -0,0 +1,71 @@
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xmlns:o="urn:schemas-microsoft-com:office:office">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta name="x-apple-disable-message-reformatting">
<title></title>
<style>
table,
td,
div,
h1,
p {
font-weight: 500;
font-family: Arial, sans-serif;
}
.btn {margin: 10px 0px;
border-radius: 4px;
text-decoration: none;
color: #fff !important;
height: 46px;
padding: 10px 20px;
font-size: 16px;
font-weight: 600;
background-image: linear-gradient(to right top, #021d68, #052579, #072d8b, #09369d, #093fb0) !important;
}
.btn:hover {
text-decoration: none;
opacity: .8;
}
</style>
</head>
<body style="margin:0;padding:0;">
<table role="presentation" style="width:100%;border-collapse:collapse;border:0;border-spacing:0;background:#ffffff;">
<tr>
<td style="padding:0;">
<table role="presentation" style="width:600px;border-collapse:collapse;border:1px solid #cccccc;border-spacing:0;text-align:left;">
<tr>
<td style="padding:36px 30px 42px 30px;">
<table role="presentation"
style="width:100%;border-collapse:collapse;border:0;border-spacing:0;">
<tr>
<td style="padding:0 0 36px 0;color:#153643;">
<p style="font-weight:bold;margin:0 0 20px 0;font-family:Arial,sans-serif;">
Hello {{ $user ? $user['name'] : '' }},</h1>
<p
style="margin:0 0 12px 0;font-size:14px;line-height:24px;font-family:Arial,sans-serif;">
Verify your email address!
</p>
<p
style="margin:10px 0 12px 0;font-size:14px;line-height:24px;font-family:Arial,sans-serif;">
Your code to verify email:
</p>
<p style="text-align: center;">
{{$user['token']}}
</p>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>

View File

@ -33,4 +33,5 @@
<li class='nav-item'><a class='nav-link' href='{{ backpack_url('document') }}'><i class='nav-icon la la-question'></i> Documents</a></li>
<li class='nav-item'><a class='nav-link' href='{{ backpack_url('documentgroup') }}'><i class='nav-icon la la-question'></i> Documentgroups</a></li>
<li class='nav-item'><a class='nav-link' href='{{ backpack_url('documentgroup-document') }}'><i class='nav-icon la la-question'></i> Documentgroup documents</a></li>
<li class='nav-item'><a class='nav-link' href='{{ backpack_url('documentgroup-country') }}'><i class='nav-icon la la-question'></i> Documentgroup countries</a></li>
<li class='nav-item'><a class='nav-link' href='{{ backpack_url('documentgroup-country') }}'><i class='nav-icon la la-question'></i> Documentgroup countries</a></li>
<li class='nav-item'><a class='nav-link' href='{{ backpack_url('setting') }}'><i class='nav-icon la la-cog'></i> <span>Settings</span></a></li>