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; namespace App\Http\Controllers;
use App\Http\Requests\RegisterRequest;
use App\Models\User; use App\Models\User;
use Hash; use Hash;
use Illuminate\Validation\ValidationException; use Illuminate\Validation\ValidationException;
@ -11,9 +10,9 @@ use Validator;
class PublicUserController extends Controller 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) { if (User::where([ 'email' => $data['email'] ])->count() != 0) {
return response() return response()
->json('email_taken', 400); ->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", "license": "MIT",
"require": { "require": {
"php": "^8.2", "php": "^8.2",
"bjeavons/zxcvbn-php": "^1.3",
"egulias/email-validator": "^4.0",
"laravel/framework": "^11.9", "laravel/framework": "^11.9",
"laravel/tinker": "^2.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", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "847793c6725e2d2fecbf33402e6d4c4d", "content-hash": "7e8c3c14ff33b199b4a0838993eb8423",
"packages": [ "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", "name": "brick/math",
"version": "0.12.1", "version": "0.12.1",

View File

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