Compare commits
2 Commits
73f7072b7f
...
6722c9a75d
Author | SHA1 | Date |
---|---|---|
b1ek | 6722c9a75d | |
b1ek | e28348cfbf |
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Requests\RegisterRequest;
|
||||
use App\Models\User;
|
||||
use Hash;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
@ -10,9 +11,9 @@ use Validator;
|
|||
|
||||
class PublicUserController extends Controller
|
||||
{
|
||||
public function register(Request $request)
|
||||
public function register(RegisterRequest $request)
|
||||
{
|
||||
$data = $request->all()['user'];
|
||||
$data = $request->all();
|
||||
if (User::where([ 'email' => $data['email'] ])->count() != 0) {
|
||||
return response()
|
||||
->json('email_taken', 400);
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
<?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 ])],
|
||||
];
|
||||
}
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
<?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));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
<?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!');
|
||||
}
|
||||
}
|
||||
}
|
|
@ -6,6 +6,8 @@
|
|||
"license": "MIT",
|
||||
"require": {
|
||||
"php": "^8.2",
|
||||
"bjeavons/zxcvbn-php": "^1.3",
|
||||
"egulias/email-validator": "^4.0",
|
||||
"laravel/framework": "^11.9",
|
||||
"laravel/tinker": "^2.9"
|
||||
},
|
||||
|
|
|
@ -4,8 +4,63 @@
|
|||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "7e8c3c14ff33b199b4a0838993eb8423",
|
||||
"content-hash": "847793c6725e2d2fecbf33402e6d4c4d",
|
||||
"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",
|
||||
|
|
|
@ -18,19 +18,16 @@ paths:
|
|||
schema:
|
||||
type: object
|
||||
properties:
|
||||
user:
|
||||
type: object
|
||||
properties:
|
||||
last_name:
|
||||
type: string
|
||||
name:
|
||||
type: string
|
||||
middle_name:
|
||||
type: string
|
||||
email:
|
||||
type: string
|
||||
phone:
|
||||
type: string
|
||||
last_name:
|
||||
type: string
|
||||
name:
|
||||
type: string
|
||||
middle_name:
|
||||
type: string
|
||||
email:
|
||||
type: string
|
||||
phone:
|
||||
type: string
|
||||
password:
|
||||
type: string
|
||||
example: 'strong_password123'
|
||||
|
@ -56,6 +53,12 @@ paths:
|
|||
schema:
|
||||
type: string
|
||||
example: 'bad_password'
|
||||
422:
|
||||
description: Validation error
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/ValidationError'
|
||||
/api/users/login:
|
||||
post:
|
||||
tags:
|
||||
|
@ -86,10 +89,13 @@ 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 |
|
||||
|
||||
This error also might be sent by laravel if your body is corrupted
|
||||
422:
|
||||
description: Validation error
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/ValidationError'
|
||||
/api/users/reset:
|
||||
post:
|
||||
tags:
|
||||
|
@ -112,6 +118,12 @@ paths:
|
|||
200:
|
||||
description: |-
|
||||
The password is reset
|
||||
422:
|
||||
description: Validation error
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/ValidationError'
|
||||
|
||||
/api/users/private/list:
|
||||
get:
|
||||
|
@ -147,8 +159,12 @@ paths:
|
|||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/User'
|
||||
400:
|
||||
description: Invalid ID
|
||||
422:
|
||||
description: Validation error
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/ValidationError'
|
||||
404:
|
||||
description: User not found
|
||||
/api/users/private/edit/{id}:
|
||||
|
@ -166,6 +182,12 @@ 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
|
||||
|
@ -209,6 +231,12 @@ 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:
|
||||
|
@ -237,6 +265,12 @@ 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
|
||||
|
@ -262,6 +296,12 @@ 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
|
||||
|
@ -319,6 +359,14 @@ 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
|
||||
|
|
Loading…
Reference in New Issue