update-profile added, password-reset fixed
This commit is contained in:
parent
96b946e3c5
commit
2b9aa91ef7
|
|
@ -40,17 +40,6 @@ public function setup()
|
|||
*/
|
||||
protected function setupListOperation()
|
||||
{
|
||||
CRUD::addColumn([
|
||||
'name' => 'contacts',
|
||||
'type' => 'json',
|
||||
'label' => 'Contacts'
|
||||
]);
|
||||
CRUD::addColumn([
|
||||
'name' => 'bank',
|
||||
'type' => 'json',
|
||||
'label' => 'Bank'
|
||||
]);
|
||||
//CRUD::column('profileable_id');
|
||||
CRUD::addColumn([
|
||||
// 1-n relationship
|
||||
'label' => 'Profile ID', // Table column heading
|
||||
|
|
@ -167,8 +156,6 @@ protected function setupCreateOperation()
|
|||
]
|
||||
]);
|
||||
|
||||
CRUD::field('profileable_id');
|
||||
CRUD::field('profileable_type');
|
||||
CRUD::field('vat');
|
||||
CRUD::field('country_id');
|
||||
CRUD::field('legalization_number');
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
use App\Mail\ResetPassword;
|
||||
use App\Models\Client;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
|
|
@ -250,7 +251,7 @@ public function sendPasswordResetLinkEmail(Request $request) {
|
|||
return back()->with('failed', 'Failed! email is not registered.');
|
||||
}
|
||||
|
||||
$token = Str::random(60);
|
||||
$token = rand(1000, 9999);
|
||||
|
||||
$user['token'] = $token;
|
||||
$user['is_verified'] = 0;
|
||||
|
|
@ -263,39 +264,135 @@ public function sendPasswordResetLinkEmail(Request $request) {
|
|||
], 200);
|
||||
}
|
||||
|
||||
//password reset link redirection from email
|
||||
public function forgotPasswordValidate($token){
|
||||
$user = Client::where('token', $token)->where('is_verified', 0)->first();
|
||||
if ($user) {
|
||||
$email = $user->email;
|
||||
return view('auth.change-password', compact('email'));
|
||||
}
|
||||
return response()->json([
|
||||
'message' => 'token_expired'
|
||||
], 419);
|
||||
}
|
||||
|
||||
//update password - WEB
|
||||
/**
|
||||
* @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"
|
||||
* )
|
||||
* )
|
||||
*/
|
||||
public function updatePassword(Request $request) {
|
||||
$this->validate($request, [
|
||||
'token' => 'required',
|
||||
'email' => 'required',
|
||||
'password' => 'required|min:6',
|
||||
'password' => 'required',
|
||||
'confirm_password' => 'required|same:password'
|
||||
]);
|
||||
|
||||
$user = Client::where('email', $request->email)->first();
|
||||
if ($user) {
|
||||
if($user && $request->token == $user->token){
|
||||
$user['is_verified'] = 0;
|
||||
$user['token'] = '';
|
||||
$user['password'] = Hash::make($request->password);
|
||||
$user->save();
|
||||
return response()->json([
|
||||
'message' => 'OK'
|
||||
], 200);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'message' => 'not_found'
|
||||
], 404);
|
||||
}
|
||||
|
||||
/**
|
||||
* @OA\POST(
|
||||
* path="/api/update-account",
|
||||
* summary=" - Update client account",
|
||||
* tags = {"Authorization"},
|
||||
* 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'])){
|
||||
$this->validate($request, [
|
||||
'password' => 'required',
|
||||
'confirm_password' => 'required|same:password'
|
||||
]);
|
||||
$client['password'] = Hash::make($request->password);
|
||||
}
|
||||
}
|
||||
$client->save();
|
||||
return response()->json($client, 200);
|
||||
}
|
||||
return response()->json([
|
||||
'error' => 'unauthorised'
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ class CheckIfAdmin
|
|||
*/
|
||||
private function checkIfUserIsAdmin($user)
|
||||
{
|
||||
// return ($user->is_admin == 1);
|
||||
//return ($user->is_admin == 1);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -36,8 +36,8 @@ public function build()
|
|||
$user['name'] = $this->name;
|
||||
$user['token'] = $this->token;
|
||||
|
||||
return $this->from("milmedova96@gmail.com", "Mahri Ilmedova")
|
||||
->subject('Password Reset Link')
|
||||
return $this->from("milmedova96@gmail.com", "Birzha Legalizasiya")
|
||||
->subject('Password Reset Code')
|
||||
->view('emails.reset-password', ['user' => $user]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,17 +32,10 @@
|
|||
</style>
|
||||
</head>
|
||||
<body style="margin:0;padding:0;">
|
||||
<table role="presentation"
|
||||
style="width:100%;border-collapse:collapse;border:0;border-spacing:0;background:#ffffff;">
|
||||
<table role="presentation" style="width:100%;border-collapse:collapse;border:0;border-spacing:0;background:#ffffff;">
|
||||
<tr>
|
||||
<td align="center" style="padding:0;">
|
||||
<table role="presentation"
|
||||
style="width:600px;border-collapse:collapse;border:1px solid #cccccc;border-spacing:0;text-align:left;">
|
||||
<tr style="border-collapse:collapse;border:1px solid #cccccc;border-spacing:0;">
|
||||
<td align="left" style="padding:10px 25px;background:#fff; display: flex; align-items: center;">
|
||||
<span style="font-weight: bold; padding-top: 10px;"> Programming Fields </span>
|
||||
</td>
|
||||
</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"
|
||||
|
|
@ -57,19 +50,14 @@
|
|||
</p>
|
||||
<p
|
||||
style="margin:10px 0 12px 0;font-size:14px;line-height:24px;font-family:Arial,sans-serif;">
|
||||
You can reset your password by clicking the button below:
|
||||
Your code to reset:
|
||||
</p>
|
||||
|
||||
<p style="text-align: center;">
|
||||
<a href="{{'http://localhost:8000/forgot-password/'.$user['token']}}" class="btn">Reset your password</a>
|
||||
{{$user['token']}}
|
||||
</p>
|
||||
|
||||
|
||||
<p style="margin:100px 0 12px 0;font-size:14px;font-family:Arial,sans-serif;">
|
||||
Thank
|
||||
you, </p>
|
||||
<p style="margin:0 0 12px 0;font-size:14px;font-family:Arial,sans-serif;">
|
||||
Programming Fields </p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
|
|
|||
|
|
@ -23,10 +23,12 @@
|
|||
|
||||
Route::post('/register', [AuthController::class, 'register']);
|
||||
Route::post('/login', [AuthController::class, 'login']);
|
||||
Route::post('/forgot-password', [AuthController::class, 'sendPasswordResetLinkEmail'])->name('passwords.sent');
|
||||
Route::post('/reset-password', [AuthController::class, 'updatePassword']);
|
||||
Route::post('/forgot-password', [AuthController::class, 'sendPasswordResetLinkEmail']);
|
||||
Route::get('/users', [TestController::class, 'users']);
|
||||
|
||||
Route::middleware(['auth.client','auth:api'])->group(function () {
|
||||
Route::get('/client', [AuthController::class, 'client']);
|
||||
Route::post('/logout', [AuthController::class, 'logout']);
|
||||
Route::post('/update-account', [AuthController::class, 'updateClient']);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -163,6 +163,101 @@
|
|||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/api/reset-password": {
|
||||
"post": {
|
||||
"tags": [
|
||||
"Authorization"
|
||||
],
|
||||
"summary": " - Reset client password and enter new",
|
||||
"operationId": "4196e530fdb10fa91f253ae2ef237046",
|
||||
"requestBody": {
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"properties": {
|
||||
"email": {
|
||||
"type": "string"
|
||||
},
|
||||
"token": {
|
||||
"type": "string"
|
||||
},
|
||||
"password": {
|
||||
"type": "string"
|
||||
},
|
||||
"confirm_password": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"type": "object",
|
||||
"example": {
|
||||
"email": "ilmedovamahri@gmail.com",
|
||||
"token": "2546",
|
||||
"password": "Hello001!",
|
||||
"confirm_password": "Hello001!"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/api/update-account": {
|
||||
"post": {
|
||||
"tags": [
|
||||
"Authorization"
|
||||
],
|
||||
"summary": " - Update client account",
|
||||
"operationId": "0d22fd27cb66727b01ded3c5a4ac7b48",
|
||||
"requestBody": {
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"properties": {
|
||||
"firstname": {
|
||||
"type": "string"
|
||||
},
|
||||
"lastname": {
|
||||
"type": "string"
|
||||
},
|
||||
"email": {
|
||||
"type": "string"
|
||||
},
|
||||
"password": {
|
||||
"type": "string"
|
||||
},
|
||||
"confirm_password": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"type": "object",
|
||||
"example": {
|
||||
"firstname": "Mahri",
|
||||
"lastname": "Ilmedova",
|
||||
"email": "ilmedovamahri@gmail.com",
|
||||
"password": "Hello001!",
|
||||
"confirm_password": "Hello001!"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK"
|
||||
}
|
||||
},
|
||||
"security": [
|
||||
{
|
||||
"bearerAuth": []
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"components": {
|
||||
|
|
|
|||
Loading…
Reference in New Issue