2022-06-24 11:56:01 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
|
2022-07-06 12:38:03 +00:00
|
|
|
use App\Mail\EmailVerification;
|
2022-06-30 14:55:51 +00:00
|
|
|
use App\Mail\ResetPassword;
|
2022-06-24 11:56:01 +00:00
|
|
|
use App\Models\Client;
|
2022-07-04 06:51:55 +00:00
|
|
|
use App\Models\User;
|
2022-07-06 12:38:03 +00:00
|
|
|
use Exception;
|
2022-06-24 11:56:01 +00:00
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
|
use Illuminate\Support\Facades\Hash;
|
2022-06-30 14:55:51 +00:00
|
|
|
use Illuminate\Support\Facades\Mail;
|
|
|
|
|
use Illuminate\Support\Str;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
use Illuminate\Support\Facades\Password;
|
|
|
|
|
use Illuminate\Support\Facades\Validator;
|
|
|
|
|
use Illuminate\Auth\Events\PasswordReset;
|
2022-07-06 12:38:03 +00:00
|
|
|
use Illuminate\Support\Facades\Config;
|
2022-06-30 14:55:51 +00:00
|
|
|
use Illuminate\Validation\ValidationException;
|
2022-06-24 11:56:01 +00:00
|
|
|
|
2022-06-27 06:32:28 +00:00
|
|
|
/**
|
|
|
|
|
* @OA\Info(
|
2022-07-01 06:05:41 +00:00
|
|
|
* title="Legalization API",
|
2022-06-27 06:32:28 +00:00
|
|
|
* version="1.0.1"
|
|
|
|
|
* )
|
2022-06-30 14:55:51 +00:00
|
|
|
* @OA\SecurityScheme(
|
|
|
|
|
* securityScheme="bearerAuth",
|
|
|
|
|
* in="header",
|
|
|
|
|
* name="bearerAuth",
|
|
|
|
|
* type="http",
|
|
|
|
|
* scheme="bearer",
|
|
|
|
|
* bearerFormat="JWT",
|
|
|
|
|
* ),
|
2022-06-27 06:32:28 +00:00
|
|
|
*/
|
2022-06-24 11:56:01 +00:00
|
|
|
|
2022-06-30 14:55:51 +00:00
|
|
|
|
2022-06-24 11:56:01 +00:00
|
|
|
//controller where all auth process for client happens
|
|
|
|
|
class AuthController extends Controller
|
|
|
|
|
{
|
|
|
|
|
|
2022-06-27 06:32:28 +00:00
|
|
|
/**
|
|
|
|
|
* @OA\POST(
|
|
|
|
|
* path="/api/login",
|
|
|
|
|
* summary=" - Login user",
|
2022-06-30 14:55:51 +00:00
|
|
|
* tags = {"Authorization"},
|
2022-06-27 06:32:28 +00:00
|
|
|
* @OA\RequestBody(
|
|
|
|
|
* @OA\MediaType(
|
|
|
|
|
* mediaType="application/json",
|
|
|
|
|
* @OA\Schema(
|
|
|
|
|
* @OA\Property(
|
|
|
|
|
* property="email",
|
|
|
|
|
* type="string",
|
|
|
|
|
* ),
|
|
|
|
|
* @OA\Property(
|
|
|
|
|
* property="password",
|
|
|
|
|
* type="string",
|
|
|
|
|
* ),
|
2022-06-30 14:55:51 +00:00
|
|
|
* example={"email": "ilmedovamahri@gmail.com", "password": 12345678}
|
2022-06-27 06:32:28 +00:00
|
|
|
* )
|
|
|
|
|
* )
|
|
|
|
|
* ),
|
|
|
|
|
* @OA\Response(
|
|
|
|
|
* response="200",
|
2022-06-30 14:55:51 +00:00
|
|
|
* description="OK"
|
2022-06-27 06:32:28 +00:00
|
|
|
* ),
|
|
|
|
|
* @OA\Response(
|
|
|
|
|
* response="401",
|
|
|
|
|
* description="Unauthorized"
|
|
|
|
|
* )
|
|
|
|
|
* )
|
|
|
|
|
*/
|
2022-06-30 14:55:51 +00:00
|
|
|
public function login(Request $request){
|
2022-07-06 12:38:03 +00:00
|
|
|
if($request->email == null || $request->password == null){
|
2022-06-24 11:56:01 +00:00
|
|
|
|
2022-07-06 12:38:03 +00:00
|
|
|
// get user object
|
|
|
|
|
$client = Client::where('email', request()->email)->first();
|
2022-06-24 11:56:01 +00:00
|
|
|
|
2022-07-06 12:38:03 +00:00
|
|
|
if($client){
|
|
|
|
|
// do the passwords match?
|
|
|
|
|
if (!Hash::check(request()->password, $client->password)){
|
|
|
|
|
// no they don't
|
|
|
|
|
return response()->json(['error' => 'Unauthorized'], 401);
|
|
|
|
|
}
|
2022-06-24 11:56:01 +00:00
|
|
|
|
2022-07-06 12:38:03 +00:00
|
|
|
Auth::login($client);
|
2022-06-24 11:56:01 +00:00
|
|
|
|
2022-07-06 12:38:03 +00:00
|
|
|
// get new token
|
|
|
|
|
$tokenResult = $client->createToken('auth_token');
|
2022-06-24 11:56:01 +00:00
|
|
|
|
2022-07-06 12:38:03 +00:00
|
|
|
// 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);
|
2022-07-05 12:36:10 +00:00
|
|
|
}
|
2022-06-24 11:56:01 +00:00
|
|
|
}
|
|
|
|
|
|
2022-06-27 06:32:28 +00:00
|
|
|
/**
|
|
|
|
|
* @OA\POST(
|
|
|
|
|
* path="/api/register",
|
|
|
|
|
* summary=" - Register user",
|
2022-06-30 14:55:51 +00:00
|
|
|
* tags = {"Authorization"},
|
2022-06-27 06:32:28 +00:00
|
|
|
* @OA\RequestBody(
|
|
|
|
|
* @OA\MediaType(
|
|
|
|
|
* mediaType="application/json",
|
|
|
|
|
* @OA\Schema(
|
|
|
|
|
* @OA\Property(
|
|
|
|
|
* property="firstname",
|
|
|
|
|
* type="string",
|
|
|
|
|
* ),
|
|
|
|
|
* @OA\Property(
|
|
|
|
|
* property="lastname",
|
|
|
|
|
* type="string",
|
|
|
|
|
* ),
|
|
|
|
|
* @OA\Property(
|
|
|
|
|
* property="email",
|
|
|
|
|
* type="string",
|
|
|
|
|
* ),
|
|
|
|
|
* @OA\Property(
|
|
|
|
|
* property="password",
|
|
|
|
|
* type="string",
|
|
|
|
|
* ),
|
|
|
|
|
* example={"firstname":"Mahri", "lastname":"Ilmedova" ,"email": "ilmedovamahri@gmail.com", "password": 12345678}
|
|
|
|
|
* )
|
|
|
|
|
* )
|
|
|
|
|
* ),
|
|
|
|
|
* @OA\Response(
|
|
|
|
|
* response="200",
|
2022-06-30 14:55:51 +00:00
|
|
|
* description="OK"
|
2022-06-27 06:32:28 +00:00
|
|
|
* ),
|
|
|
|
|
* @OA\Response(
|
|
|
|
|
* response="401",
|
|
|
|
|
* description="Unauthorized"
|
|
|
|
|
* )
|
|
|
|
|
* )
|
|
|
|
|
*/
|
2022-06-30 14:55:51 +00:00
|
|
|
public function register(Request $request){
|
2022-07-06 12:38:03 +00:00
|
|
|
$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);
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-24 11:56:01 +00:00
|
|
|
$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']);
|
|
|
|
|
|
|
|
|
|
// set client's status to false (Admin will set the client's status from Admin Panel)
|
|
|
|
|
$data['status'] = false;
|
|
|
|
|
|
2022-06-27 06:32:28 +00:00
|
|
|
$client = Client::where('email', $data['email'])->first();
|
|
|
|
|
if($client){
|
|
|
|
|
return response()->json([
|
|
|
|
|
'error' => 'This email is already used'
|
|
|
|
|
], 401);
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-24 11:56:01 +00:00
|
|
|
$client = Client::create($data);
|
|
|
|
|
|
|
|
|
|
Auth::login($client);
|
|
|
|
|
|
|
|
|
|
// get new token
|
|
|
|
|
$tokenResult = $client->createToken('auth_token');
|
|
|
|
|
|
|
|
|
|
// return token in json response
|
2022-07-06 13:37:51 +00:00
|
|
|
return response()->json(['success' => ['token' => $tokenResult, 'client' => $client]], 200);
|
2022-06-24 11:56:01 +00:00
|
|
|
}
|
|
|
|
|
|
2022-07-06 13:37:51 +00:00
|
|
|
/**
|
|
|
|
|
* @OA\POST(
|
|
|
|
|
* path="/api/verify-email",
|
|
|
|
|
* summary=" - Verify email of client",
|
|
|
|
|
* tags = {"Authorization"},
|
|
|
|
|
* @OA\RequestBody(
|
|
|
|
|
* @OA\MediaType(
|
|
|
|
|
* mediaType="application/json",
|
|
|
|
|
* @OA\Schema(
|
|
|
|
|
* @OA\Property(
|
|
|
|
|
* property="email",
|
|
|
|
|
* type="string",
|
|
|
|
|
* ),
|
|
|
|
|
* @OA\Property(
|
|
|
|
|
* property="token",
|
|
|
|
|
* type="string",
|
|
|
|
|
* ),
|
|
|
|
|
* example={"email": "ilmedovamahri@gmail.com", "token": "4515"}
|
|
|
|
|
* )
|
|
|
|
|
* )
|
|
|
|
|
* ),
|
|
|
|
|
* @OA\Response(
|
|
|
|
|
* response="200",
|
|
|
|
|
* description="OK"
|
|
|
|
|
* ),
|
|
|
|
|
* @OA\Response(
|
|
|
|
|
* response="400",
|
|
|
|
|
* description="Missing fields (email or token)"
|
|
|
|
|
* ),
|
|
|
|
|
* @OA\Response(
|
|
|
|
|
* response="404",
|
|
|
|
|
* description="Client not found"
|
|
|
|
|
* ),
|
|
|
|
|
* @OA\Response(
|
|
|
|
|
* response="401",
|
|
|
|
|
* description="Unauthorised. Tokens do not match"
|
|
|
|
|
* )
|
|
|
|
|
* )
|
|
|
|
|
*/
|
2022-07-06 12:38:03 +00:00
|
|
|
public function verifyEmail(Request $request){
|
|
|
|
|
$data = $request->all();
|
|
|
|
|
if(count($data) < 2){
|
|
|
|
|
return response()->json([
|
|
|
|
|
'message' => 'Oops! Email or code missing'
|
|
|
|
|
],400);
|
|
|
|
|
}
|
2022-07-06 13:37:51 +00:00
|
|
|
$client = Client::where('email', $data['email'])->first();
|
|
|
|
|
|
|
|
|
|
if($client){
|
|
|
|
|
if($client->token == $data['token']){
|
|
|
|
|
Auth::login($client);
|
|
|
|
|
|
|
|
|
|
// get new token
|
|
|
|
|
$tokenResult = $client->createToken('auth_token');
|
2022-07-06 12:38:03 +00:00
|
|
|
|
2022-07-06 13:37:51 +00:00
|
|
|
// return token in json response
|
|
|
|
|
return response()->json(['success' => ['token' => $tokenResult, 'client' => $client]], 200);
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
return response()->json(['error' => ['message' => 'tokens don\'t match']], 401);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
return response()->json(['error' => ['message' => 'no such client']], 404);
|
|
|
|
|
}
|
2022-07-06 12:38:03 +00:00
|
|
|
}
|
|
|
|
|
|
2022-06-30 14:55:51 +00:00
|
|
|
/**
|
|
|
|
|
* @OA\GET(
|
|
|
|
|
* path="/api/client",
|
|
|
|
|
* summary=" - Get user",
|
|
|
|
|
* tags = {"Authorization"},
|
|
|
|
|
* security={
|
|
|
|
|
* {"bearerAuth": {}}
|
|
|
|
|
* },
|
|
|
|
|
* @OA\Response(
|
|
|
|
|
* response="200",
|
|
|
|
|
* description="OK"
|
|
|
|
|
* ),
|
|
|
|
|
* @OA\Response(
|
|
|
|
|
* response="401",
|
|
|
|
|
* description="Unauthorized"
|
|
|
|
|
* )
|
|
|
|
|
* )
|
|
|
|
|
*/
|
|
|
|
|
public function client(Request $request) {
|
|
|
|
|
$user = $request->user();
|
|
|
|
|
if($user){
|
|
|
|
|
return response()->json($request->user(),200);
|
|
|
|
|
}
|
|
|
|
|
return response()->json([
|
|
|
|
|
'message' => 'token_expired'
|
|
|
|
|
], 401);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @OA\POST(
|
|
|
|
|
* path="/api/logout",
|
|
|
|
|
* summary=" - Logout user",
|
|
|
|
|
* tags = {"Authorization"},
|
|
|
|
|
* security={
|
|
|
|
|
* {"bearerAuth": {}}
|
|
|
|
|
* },
|
|
|
|
|
* @OA\Response(
|
|
|
|
|
* response="200",
|
|
|
|
|
* description="OK"
|
|
|
|
|
* ),
|
|
|
|
|
* @OA\Response(
|
|
|
|
|
* response="401",
|
|
|
|
|
* description="Unauthorized"
|
|
|
|
|
* )
|
|
|
|
|
* )
|
|
|
|
|
*/
|
|
|
|
|
public function logout(Request $request) {
|
|
|
|
|
// Revoke the token that was used to authenticate the current request
|
|
|
|
|
$request->user()->currentAccessToken()->delete();
|
|
|
|
|
//$request->user->tokens()->delete(); // use this to revoke all tokens (logout from all devices)
|
|
|
|
|
return response()->json([
|
|
|
|
|
'message' => 'ok'
|
|
|
|
|
], 200);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @OA\POST(
|
|
|
|
|
* path="/api/forgot-password",
|
|
|
|
|
* summary=" - Send a user password reset link",
|
|
|
|
|
* tags = {"Authorization"},
|
|
|
|
|
* @OA\RequestBody(
|
|
|
|
|
* @OA\MediaType(
|
|
|
|
|
* mediaType="application/json",
|
|
|
|
|
* @OA\Schema(
|
|
|
|
|
* @OA\Property(
|
|
|
|
|
* property="email",
|
|
|
|
|
* type="string",
|
|
|
|
|
* ),
|
|
|
|
|
* example={"email": "ilmedovamahri@gmail.com"}
|
|
|
|
|
* )
|
|
|
|
|
* )
|
|
|
|
|
* ),
|
|
|
|
|
* @OA\Response(
|
|
|
|
|
* response="200",
|
|
|
|
|
* description="OK"
|
|
|
|
|
* )
|
|
|
|
|
* )
|
|
|
|
|
*/
|
|
|
|
|
public function sendPasswordResetLinkEmail(Request $request) {
|
|
|
|
|
$request->validate(['email' => 'required|email']);
|
|
|
|
|
|
|
|
|
|
$user = Client::where('email', $request->email)->first();
|
|
|
|
|
if (!$user) {
|
|
|
|
|
return back()->with('failed', 'Failed! email is not registered.');
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-04 06:51:55 +00:00
|
|
|
$token = rand(1000, 9999);
|
2022-06-30 14:55:51 +00:00
|
|
|
|
|
|
|
|
$user['token'] = $token;
|
|
|
|
|
$user['is_verified'] = 0;
|
|
|
|
|
$user->save();
|
|
|
|
|
|
2022-07-06 12:38:03 +00:00
|
|
|
Mail::to($request->email)->send(new ResetPassword($user->firstname, $token));
|
2022-06-30 14:55:51 +00:00
|
|
|
|
|
|
|
|
return response()->json([
|
|
|
|
|
'message' => 'OK'
|
|
|
|
|
], 200);
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-04 06:51:55 +00:00
|
|
|
/**
|
|
|
|
|
* @OA\POST(
|
|
|
|
|
* path="/api/reset-password",
|
|
|
|
|
* summary=" - Reset client password and enter new",
|
|
|
|
|
* tags = {"Authorization"},
|
|
|
|
|
* @OA\RequestBody(
|
|
|
|
|
* @OA\MediaType(
|
|
|
|
|
* mediaType="application/json",
|
|
|
|
|
* @OA\Schema(
|
|
|
|
|
* @OA\Property(
|
|
|
|
|
* property="email",
|
|
|
|
|
* type="string",
|
|
|
|
|
* ),
|
|
|
|
|
* @OA\Property(
|
|
|
|
|
* property="token",
|
|
|
|
|
* type="string",
|
|
|
|
|
* ),
|
|
|
|
|
* @OA\Property(
|
|
|
|
|
* property="password",
|
|
|
|
|
* type="string",
|
|
|
|
|
* ),
|
|
|
|
|
* @OA\Property(
|
|
|
|
|
* property="confirm_password",
|
|
|
|
|
* type="string",
|
|
|
|
|
* ),
|
|
|
|
|
* example={"email": "ilmedovamahri@gmail.com", "token":"2546", "password":"Hello001!", "confirm_password":"Hello001!"}
|
|
|
|
|
* )
|
|
|
|
|
* )
|
|
|
|
|
* ),
|
|
|
|
|
* @OA\Response(
|
|
|
|
|
* response="200",
|
|
|
|
|
* description="OK"
|
|
|
|
|
* )
|
|
|
|
|
* )
|
|
|
|
|
*/
|
2022-06-30 14:55:51 +00:00
|
|
|
public function updatePassword(Request $request) {
|
|
|
|
|
$this->validate($request, [
|
2022-07-04 06:51:55 +00:00
|
|
|
'token' => 'required',
|
2022-06-30 14:55:51 +00:00
|
|
|
'email' => 'required',
|
2022-07-04 06:51:55 +00:00
|
|
|
'password' => 'required',
|
2022-06-30 14:55:51 +00:00
|
|
|
'confirm_password' => 'required|same:password'
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$user = Client::where('email', $request->email)->first();
|
2022-07-04 06:51:55 +00:00
|
|
|
if($user && $request->token == $user->token){
|
2022-06-30 14:55:51 +00:00
|
|
|
$user['is_verified'] = 0;
|
|
|
|
|
$user['password'] = Hash::make($request->password);
|
|
|
|
|
$user->save();
|
|
|
|
|
return response()->json([
|
|
|
|
|
'message' => 'OK'
|
|
|
|
|
], 200);
|
|
|
|
|
}
|
2022-07-04 06:51:55 +00:00
|
|
|
|
2022-06-30 14:55:51 +00:00
|
|
|
return response()->json([
|
|
|
|
|
'message' => 'not_found'
|
|
|
|
|
], 404);
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-04 06:51:55 +00:00
|
|
|
/**
|
|
|
|
|
* @OA\POST(
|
|
|
|
|
* path="/api/update-account",
|
|
|
|
|
* summary=" - Update client account",
|
|
|
|
|
* tags = {"Authorization"},
|
2022-07-04 10:01:39 +00:00
|
|
|
* description = "All the fields are optional (if password field is being updated then confirm_password is required)",
|
2022-07-04 06:51:55 +00:00
|
|
|
* security={
|
|
|
|
|
* {"bearerAuth": {}}
|
|
|
|
|
* },
|
|
|
|
|
* @OA\RequestBody(
|
|
|
|
|
* @OA\MediaType(
|
|
|
|
|
* mediaType="application/json",
|
|
|
|
|
* @OA\Schema(
|
|
|
|
|
* @OA\Property(
|
|
|
|
|
* property="firstname",
|
|
|
|
|
* type="string",
|
|
|
|
|
* ),
|
|
|
|
|
* @OA\Property(
|
|
|
|
|
* property="lastname",
|
|
|
|
|
* type="string",
|
|
|
|
|
* ),
|
|
|
|
|
* @OA\Property(
|
|
|
|
|
* property="email",
|
|
|
|
|
* type="string",
|
|
|
|
|
* ),
|
|
|
|
|
* @OA\Property(
|
|
|
|
|
* property="password",
|
|
|
|
|
* type="string",
|
|
|
|
|
* ),
|
|
|
|
|
* @OA\Property(
|
|
|
|
|
* property="confirm_password",
|
|
|
|
|
* type="string",
|
|
|
|
|
* ),
|
|
|
|
|
* example={"firstname":"Mahri","lastname":"Ilmedova","email": "ilmedovamahri@gmail.com", "password":"Hello001!", "confirm_password":"Hello001!"}
|
|
|
|
|
* )
|
|
|
|
|
* )
|
|
|
|
|
* ),
|
|
|
|
|
* @OA\Response(
|
|
|
|
|
* response="200",
|
|
|
|
|
* description="OK"
|
|
|
|
|
* )
|
|
|
|
|
* )
|
|
|
|
|
*/
|
|
|
|
|
public function updateClient(Request $request){
|
|
|
|
|
$user = $request->user();
|
|
|
|
|
$client = Client::find($user->id);
|
|
|
|
|
$data = $request->all();
|
|
|
|
|
if($client){
|
|
|
|
|
if(count($data) > 0){
|
|
|
|
|
if(isset($data['firstname'])){
|
|
|
|
|
$client['firstname'] = $data['firstname'];
|
|
|
|
|
}
|
|
|
|
|
if(isset($data['lastname'])){
|
|
|
|
|
$client['lastname'] = $data['lastname'];
|
|
|
|
|
}
|
|
|
|
|
if(isset($data['email'])){
|
|
|
|
|
$client['email'] = $data['email'];
|
|
|
|
|
}
|
|
|
|
|
if(isset($data['password'])){
|
2022-07-05 12:48:06 +00:00
|
|
|
if(isset($data['confirm_password'])){
|
|
|
|
|
$this->validate($request, [
|
|
|
|
|
'password' => 'required',
|
|
|
|
|
'confirm_password' => 'required|same:password'
|
|
|
|
|
]);
|
|
|
|
|
$client['password'] = Hash::make($request->password);
|
|
|
|
|
}
|
|
|
|
|
return response()->json([
|
|
|
|
|
'error' => 'confirm_password missing'
|
|
|
|
|
], 400);
|
2022-07-04 06:51:55 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
$client->save();
|
|
|
|
|
return response()->json($client, 200);
|
|
|
|
|
}
|
|
|
|
|
return response()->json([
|
|
|
|
|
'error' => 'unauthorised'
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-24 11:56:01 +00:00
|
|
|
}
|