Skip to content

Commit

Permalink
fix: User and password operations
Browse files Browse the repository at this point in the history
  • Loading branch information
dogukanoksuz committed Oct 10, 2023
1 parent 32d02bd commit 488513f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
17 changes: 16 additions & 1 deletion app/Http/Controllers/API/AuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,14 @@ public function forceChangePassword(Request $request)
$validator = Validator::make($request->all(), [
'email' => 'required|email',
'password' => 'required|string',
'new_password' => [
'string',
'min:10',
'max:32',
'regex:/^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[\!\[\]\(\)\{\}\#\?\%\&\*\+\,\-\.\/\:\;\<\=\>\@\^\_\`\~]).{10,}$/',
],
], [
'new_password.regex' => 'Yeni parolanız en az 10 karakter uzunluğunda olmalı ve en az 1 sayı, özel karakter ve büyük harf içermelidir.',
]);

if ($validator->fails()) {
Expand All @@ -151,6 +159,11 @@ public function forceChangePassword(Request $request)
return response()->json(['message' => 'Kullanıcı adı veya şifreniz yanlış.'], 401);
}

// If new_password is same as password return error
if (Hash::check($request->new_password, auth('api')->user()->password)) {
return response()->json(['message' => 'Yeni şifreniz eski şifreniz ile aynı olamaz.'], 405);
}

$user = auth('api')->user();
$user->forceChange = false;
$user->password = bcrypt($request->new_password);
Expand Down Expand Up @@ -421,13 +434,15 @@ protected function createNewToken($token, Request $request = null)
'expired_at' => (auth('api')->factory()->getTTL() * 60 + time()) * 1000,
'user' => [
...User::find(auth('api')->user()->id)->toArray(),
'last_login_at' => Carbon::now()->toDateTimeString(),
'last_login_ip' => $request->ip(),
'permissions' => [
'server_details' => Permission::can(auth('api')->user()->id, 'liman', 'id', 'server_details'),
'server_services' => Permission::can(auth('api')->user()->id, 'liman', 'id', 'server_services'),
'add_server' => Permission::can(auth('api')->user()->id, 'liman', 'id', 'add_server'),
'update_server' => Permission::can(auth('api')->user()->id, 'liman', 'id', 'update_server'),
'view_logs' => Permission::can(auth('api')->user()->id, 'liman', 'id', 'view_logs'),
]
],
],
]);
}
Expand Down
4 changes: 3 additions & 1 deletion app/Http/Controllers/API/Settings/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Http\Controllers\Controller;
use App\Models\AuditLog;
use App\Models\AuthLog;
use App\Models\Notification;
use App\Models\Permission;
use App\Models\RoleUser;
use App\User;
Expand Down Expand Up @@ -90,7 +91,8 @@ public function delete(Request $request)
RoleUser::where('user_id', $request->user_id)->delete();

// Delete User
$user = User::where('id', $request->user_id)->delete();
$user = User::where('id', $request->user_id)->first();
$user->delete();

AuditLog::write(
'user',
Expand Down

0 comments on commit 488513f

Please sign in to comment.