Compare commits

..

No commits in common. "6722c9a75d5fd598d51e269201336d6099af337a" and "73f7072b7f6f6c7d9d0726a5cfd21f66a2ed914b" have entirely different histories.

7 changed files with 21 additions and 203 deletions

View File

@ -2,7 +2,6 @@
namespace App\Http\Controllers;
use App\Http\Requests\RegisterRequest;
use App\Models\User;
use Hash;
use Illuminate\Validation\ValidationException;
@ -11,9 +10,9 @@ use Validator;
class PublicUserController extends Controller
{
public function register(RegisterRequest $request)
public function register(Request $request)
{
$data = $request->all();
$data = $request->all()['user'];
if (User::where([ 'email' => $data['email'] ])->count() != 0) {
return response()
->json('email_taken', 400);

View File

@ -1,35 +0,0 @@
<?php
namespace App\Http\Requests;
use App\Rules\ZxcvbnRule;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rules\Password;
class RegisterRequest extends RestRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
*/
public function rules(): array
{
return [
'last_name' => ['required', 'string'],
'name' => ['required', 'string'],
'middle_name' => ['required', 'string'],
'email' => ['required', 'email'],
'phone' => ['required', 'regex:/^\+\d+$/'],
'password' => ['required', Password::min(1)->rules([ new ZxcvbnRule ])],
];
}
}

View File

@ -1,17 +0,0 @@
<?php
namespace App\Http\Requests;
use Illuminate\Contracts\Validation\Validator;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Http\Exceptions\HttpResponseException;
class RestRequest extends FormRequest
{
protected function failedValidation(Validator $validator)
{
$exception = $validator->getException();
throw new HttpResponseException(response()->json($validator->errors(), 422));
}
}

View File

@ -1,24 +0,0 @@
<?php
namespace App\Rules;
use Closure;
use Illuminate\Contracts\Validation\ValidationRule;
use ZxcvbnPhp\Zxcvbn;
class ZxcvbnRule implements ValidationRule
{
/**
* Run the validation rule.
*
* @param \Closure(string): \Illuminate\Translation\PotentiallyTranslatedString $fail
*/
public function validate(string $attribute, mixed $value, Closure $fail): void
{
$value = (string) $value;
$zxcvbn = new Zxcvbn();
if ($zxcvbn->passwordStrength($value)['score'] < 3) {
$fail('Password is not secure enough!');
}
}
}

View File

@ -6,8 +6,6 @@
"license": "MIT",
"require": {
"php": "^8.2",
"bjeavons/zxcvbn-php": "^1.3",
"egulias/email-validator": "^4.0",
"laravel/framework": "^11.9",
"laravel/tinker": "^2.9"
},

57
composer.lock generated
View File

@ -4,63 +4,8 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "847793c6725e2d2fecbf33402e6d4c4d",
"content-hash": "7e8c3c14ff33b199b4a0838993eb8423",
"packages": [
{
"name": "bjeavons/zxcvbn-php",
"version": "1.3.1",
"source": {
"type": "git",
"url": "https://github.com/bjeavons/zxcvbn-php.git",
"reference": "994928ae5b17ecff8baa2406832d37bdf01116c0"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/bjeavons/zxcvbn-php/zipball/994928ae5b17ecff8baa2406832d37bdf01116c0",
"reference": "994928ae5b17ecff8baa2406832d37bdf01116c0",
"shasum": ""
},
"require": {
"ext-json": "*",
"php": "^7.2 | ^8.0 | ^8.1",
"symfony/polyfill-mbstring": ">=1.3.1"
},
"require-dev": {
"php-coveralls/php-coveralls": "*",
"phpunit/phpunit": "^8.5",
"squizlabs/php_codesniffer": "3.*"
},
"suggest": {
"ext-gmp": "Required for optimized binomial calculations (also requires PHP >= 7.3)"
},
"type": "library",
"autoload": {
"psr-4": {
"ZxcvbnPhp\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "See contributors",
"homepage": "https://github.com/bjeavons/zxcvbn-php"
}
],
"description": "Realistic password strength estimation PHP library based on Zxcvbn JS",
"homepage": "https://github.com/bjeavons/zxcvbn-php",
"keywords": [
"password",
"zxcvbn"
],
"support": {
"issues": "https://github.com/bjeavons/zxcvbn-php/issues",
"source": "https://github.com/bjeavons/zxcvbn-php/tree/1.3.1"
},
"time": "2021-12-21T18:37:02+00:00"
},
{
"name": "brick/math",
"version": "0.12.1",

View File

@ -18,16 +18,19 @@ paths:
schema:
type: object
properties:
last_name:
type: string
name:
type: string
middle_name:
type: string
email:
type: string
phone:
type: string
user:
type: object
properties:
last_name:
type: string
name:
type: string
middle_name:
type: string
email:
type: string
phone:
type: string
password:
type: string
example: 'strong_password123'
@ -53,12 +56,6 @@ paths:
schema:
type: string
example: 'bad_password'
422:
description: Validation error
content:
application/json:
schema:
$ref: '#/components/schemas/ValidationError'
/api/users/login:
post:
tags:
@ -89,13 +86,10 @@ paths:
| key | val |
| --- | --- |
| `bad_email` | email is not a valid email |
| `bad_password` | authentication unsuccessful; this means that there is either no user with this email, or password doesn't match |
422:
description: Validation error
content:
application/json:
schema:
$ref: '#/components/schemas/ValidationError'
This error also might be sent by laravel if your body is corrupted
/api/users/reset:
post:
tags:
@ -118,12 +112,6 @@ paths:
200:
description: |-
The password is reset
422:
description: Validation error
content:
application/json:
schema:
$ref: '#/components/schemas/ValidationError'
/api/users/private/list:
get:
@ -159,12 +147,8 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/User'
422:
description: Validation error
content:
application/json:
schema:
$ref: '#/components/schemas/ValidationError'
400:
description: Invalid ID
404:
description: User not found
/api/users/private/edit/{id}:
@ -182,12 +166,6 @@ paths:
responses:
200:
description: OK
422:
description: Validation error
content:
application/json:
schema:
$ref: '#/components/schemas/ValidationError'
requestBody:
description: |-
All fields of `user` are required. The whole record will be updated with exactly what you provide here. It is assumed that you already have all information about the user beforehand
@ -231,12 +209,6 @@ paths:
items:
type: string
example: 'userid'
422:
description: Validation error
content:
application/json:
schema:
$ref: '#/components/schemas/ValidationError'
delete:
summary: Remove user(s) from trash
tags:
@ -265,12 +237,6 @@ paths:
items:
type: string
example: 'userid'
422:
description: Validation error
content:
application/json:
schema:
$ref: '#/components/schemas/ValidationError'
/api/users/private/trash/clean:
delete:
summary: Delete user(s) for good from trash
@ -296,12 +262,6 @@ paths:
type: array
items:
type: string
422:
description: Validation error
content:
application/json:
schema:
$ref: '#/components/schemas/ValidationError'
/api/users/private/trash/list:
get:
summary: List users in trash
@ -359,14 +319,6 @@ components:
password:
type: string
example: 'argon2-hash-here'
ValidationError:
type: object
properties:
field_name:
type: array
items:
type: string
example: 'This field is invalid!'
securitySchemes:
session:
type: http