• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

visavi / rotor / 28410244511

29 Jun 2026 11:47PM UTC coverage: 16.561%. Remained the same
28410244511

push

github

visavi
Carbon на Datetime

0 of 2 new or added lines in 2 files covered. (0.0%)

989 of 5972 relevant lines covered (16.56%)

2.44 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/app/Http/Controllers/Admin/BanController.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace App\Http\Controllers\Admin;
6

7
use App\Classes\Validator;
8
use App\Models\Banhist;
9
use App\Models\User;
10
use Illuminate\Http\RedirectResponse;
11
use Illuminate\Http\Request;
12
use Illuminate\Support\Facades\Date;
13
use Illuminate\View\View;
14

15
class BanController extends AdminController
16
{
17
    /**
18
     * Главная страница
19
     */
20
    public function index(): View
×
21
    {
22
        return view('admin/bans/index');
×
23
    }
24

25
    /**
26
     * Бан пользователя
27
     */
28
    public function edit(Request $request, Validator $validator): View|RedirectResponse
×
29
    {
30
        $user = User::query()->where('login', $request->input('user'))->with('lastBan')->first();
×
31

32
        if (! $user) {
×
33
            abort(404, __('validator.user'));
×
34
        }
35

36
        if (in_array($user->level, User::ADMIN_GROUPS, true)) {
×
37
            abort(200, __('admin.bans.forbidden_ban'));
×
38
        }
39

40
        if ($request->isMethod('post')) {
×
41
            $time = int($request->input('time'));
×
42
            $type = $request->input('type');
×
43
            $reason = $request->input('reason');
×
44
            $validator
×
45
                ->false($user->level === User::BANNED && $user->timeban?->isFuture(), __('admin.bans.user_banned'))
×
46
                ->gt($time, 0, ['time' => __('admin.bans.time_not_indicated')])
×
47
                ->in($type, ['minutes', 'hours', 'days'], ['type' => __('admin.bans.time_not_selected')])
×
48
                ->length($reason, 5, 1000, ['reason' => __('validator.text')]);
×
49

50
            if ($validator->isValid()) {
×
51
                if ($type === 'days') {
×
52
                    $time *= 86400;
×
53
                } elseif ($type === 'hours') {
×
54
                    $time *= 3600;
×
55
                } else {
56
                    $time *= 60;
×
57
                }
58

59
                $user->update([
×
60
                    'level'   => User::BANNED,
×
61
                    'timeban' => now()->addSeconds($time),
×
62
                ]);
×
63

64
                Banhist::query()->create([
×
65
                    'user_id'      => $user->id,
×
66
                    'send_user_id' => getUser('id'),
×
67
                    'type'         => Banhist::BAN,
×
68
                    'reason'       => $reason,
×
69
                    'term'         => $time,
×
70
                ]);
×
71

72
                setFlash('success', __('admin.bans.success_banned'));
×
73

74
                return redirect('admin/bans/edit?user=' . $user->login);
×
75
            }
76

77
            setInput($request->all());
×
78
            setFlash('danger', $validator->getErrors());
×
79
        }
80

81
        return view('admin/bans/edit', compact('user'));
×
82
    }
83

84
    /**
85
     * Изменение бана
86
     */
87
    public function change(Request $request, Validator $validator): View|RedirectResponse
×
88
    {
89
        $user = User::query()->where('login', $request->input('user'))->with('lastBan')->first();
×
90

91
        if (! $user) {
×
92
            abort(404, __('validator.user'));
×
93
        }
94

95
        if ($user->level !== User::BANNED || ! $user->timeban || $user->timeban->isPast()) {
×
96
            abort(200, __('admin.bans.user_not_banned'));
×
97
        }
98

99
        if ($request->isMethod('post')) {
×
100
            $reason = $request->input('reason');
×
101

NEW
102
            $timeban = Date::parse($request->input('timeban'));
×
103
            $term = $timeban->timestamp - now()->timestamp;
×
104

105
            $validator
×
106
                ->gt($term, 0, ['timeban' => __('admin.bans.time_empty')])
×
107
                ->length($reason, 5, 1000, ['reason' => __('validator.text')]);
×
108

109
            if ($validator->isValid()) {
×
110
                $user->update([
×
111
                    'level'   => User::BANNED,
×
112
                    'timeban' => $timeban,
×
113
                ]);
×
114

115
                Banhist::query()->create([
×
116
                    'user_id'      => $user->id,
×
117
                    'send_user_id' => getUser('id'),
×
118
                    'type'         => Banhist::CHANGE,
×
119
                    'reason'       => $reason,
×
120
                    'term'         => $term,
×
121
                ]);
×
122

123
                setFlash('success', __('main.record_changed_success'));
×
124

125
                return redirect('admin/bans/edit?user=' . $user->login);
×
126
            }
127

128
            setInput($request->all());
×
129
            setFlash('danger', $validator->getErrors());
×
130
        }
131

132
        return view('admin/bans/change', compact('user'));
×
133
    }
134

135
    /**
136
     * Снятие бана
137
     */
138
    public function unban(Request $request): RedirectResponse
×
139
    {
140
        $user = User::query()->where('login', $request->input('user'))->with('lastBan')->first();
×
141

142
        if (! $user) {
×
143
            abort(404, __('validator.user'));
×
144
        }
145

146
        if ($user->level !== User::BANNED || ! $user->timeban || $user->timeban->isPast()) {
×
147
            abort(200, __('admin.bans.user_not_banned'));
×
148
        }
149

150
        $user->update([
×
151
            'level'   => User::USER,
×
152
            'timeban' => null,
×
153
        ]);
×
154

155
        Banhist::query()->create([
×
156
            'user_id'      => $user->id,
×
157
            'send_user_id' => getUser('id'),
×
158
            'type'         => Banhist::UNBAN,
×
159
        ]);
×
160

161
        setFlash('success', __('admin.bans.success_unbanned'));
×
162

163
        return redirect('admin/bans/edit?user=' . $user->login);
×
164
    }
165
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc