Skip to content

Commit bccb1d4

Browse files
authored
Merge pull request #2014 from z-song/1.5
1.5
2 parents a0a22f1 + 8bc0da9 commit bccb1d4

File tree

8 files changed

+126
-28
lines changed

8 files changed

+126
-28
lines changed

resources/views/form/tags.blade.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77
@include('admin::form.error')
88

99
<select class="form-control {{$class}}" style="width: 100%;" name="{{$name}}[]" multiple="multiple" data-placeholder="{{ $placeholder }}" {!! $attributes !!} >
10-
@foreach($value as $select)
11-
<option value="{{$select}}" selected>{{$select}}</option>
10+
11+
@foreach($options as $option)
12+
<option value="{{$option}}" {{ in_array($option, $value) ? 'selected' : '' }}>{{$option}}</option>
1213
@endforeach
14+
1315
</select>
1416
<input type="hidden" name="{{$name}}[]" />
1517

src/Controllers/AuthController.php

Lines changed: 68 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,55 +16,59 @@
1616
class AuthController extends Controller
1717
{
1818
/**
19-
* Login page.
19+
* Show the login page.
2020
*
2121
* @return \Illuminate\Contracts\View\Factory|Redirect|\Illuminate\View\View
2222
*/
2323
public function getLogin()
2424
{
25-
if (!Auth::guard('admin')->guest()) {
26-
return redirect(config('admin.route.prefix'));
25+
if ($this->guard()->check()) {
26+
return redirect($this->redirectPath());
2727
}
2828

2929
return view('admin::login');
3030
}
3131

3232
/**
33+
* Handle a login request.
34+
*
3335
* @param Request $request
3436
*
3537
* @return mixed
3638
*/
3739
public function postLogin(Request $request)
3840
{
39-
$credentials = $request->only(['username', 'password']);
41+
$credentials = $request->only([$this->username(), 'password']);
4042

43+
/** @var \Illuminate\Validation\Validator $validator */
4144
$validator = Validator::make($credentials, [
42-
'username' => 'required', 'password' => 'required',
45+
$this->username() => 'required',
46+
'password' => 'required',
4347
]);
4448

4549
if ($validator->fails()) {
46-
return Redirect::back()->withInput()->withErrors($validator);
50+
return back()->withInput()->withErrors($validator);
4751
}
4852

49-
if (Auth::guard('admin')->attempt($credentials)) {
50-
admin_toastr(trans('admin.login_successful'));
51-
52-
return redirect()->intended(config('admin.route.prefix'));
53+
if ($this->guard()->attempt($credentials)) {
54+
return $this->sendLoginResponse($request);
5355
}
5456

55-
return Redirect::back()->withInput()->withErrors(['username' => $this->getFailedLoginMessage()]);
57+
return back()->withInput()->withErrors([
58+
$this->username() => $this->getFailedLoginMessage(),
59+
]);
5660
}
5761

5862
/**
5963
* User logout.
6064
*
6165
* @return Redirect
6266
*/
63-
public function getLogout()
67+
public function getLogout(Request $request)
6468
{
65-
Auth::guard('admin')->logout();
69+
$this->guard()->logout();
6670

67-
session()->forget('url.intented');
71+
$request->session()->invalidate();
6872

6973
return redirect(config('admin.route.prefix'));
7074
}
@@ -143,4 +147,54 @@ protected function getFailedLoginMessage()
143147
? trans('auth.failed')
144148
: 'These credentials do not match our records.';
145149
}
150+
151+
/**
152+
* Get the post login redirect path.
153+
*
154+
* @return string
155+
*/
156+
protected function redirectPath()
157+
{
158+
if (method_exists($this, 'redirectTo')) {
159+
return $this->redirectTo();
160+
}
161+
162+
return property_exists($this, 'redirectTo') ? $this->redirectTo : config('admin.route.prefix');
163+
}
164+
165+
/**
166+
* Send the response after the user was authenticated.
167+
*
168+
* @param \Illuminate\Http\Request $request
169+
*
170+
* @return \Illuminate\Http\Response
171+
*/
172+
protected function sendLoginResponse(Request $request)
173+
{
174+
admin_toastr(trans('admin.login_successful'));
175+
176+
$request->session()->regenerate();
177+
178+
return redirect()->intended($this->redirectPath());
179+
}
180+
181+
/**
182+
* Get the login username to be used by the controller.
183+
*
184+
* @return string
185+
*/
186+
protected function username()
187+
{
188+
return 'username';
189+
}
190+
191+
/**
192+
* Get the guard to be used during authentication.
193+
*
194+
* @return \Illuminate\Contracts\Auth\StatefulGuard
195+
*/
196+
protected function guard()
197+
{
198+
return Auth::guard('admin');
199+
}
146200
}

src/Form.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,6 +1111,20 @@ public function setView($view)
11111111
return $this;
11121112
}
11131113

1114+
/**
1115+
* Set title for form.
1116+
*
1117+
* @param string $title
1118+
*
1119+
* @return $this
1120+
*/
1121+
public function setTitle($title = '')
1122+
{
1123+
$this->builder()->setTitle($title);
1124+
1125+
return $this;
1126+
}
1127+
11141128
/**
11151129
* Add a row in form.
11161130
*

src/Form/Builder.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,13 @@ class Builder
8787
*/
8888
protected $view = 'admin::form';
8989

90+
/**
91+
* Form title.
92+
*
93+
* @var string
94+
*/
95+
protected $title;
96+
9097
/**
9198
* Builder constructor.
9299
*
@@ -230,6 +237,20 @@ public function setView($view)
230237
return $this;
231238
}
232239

240+
/**
241+
* Set title for form.
242+
*
243+
* @param string $title
244+
*
245+
* @return $this
246+
*/
247+
public function setTitle($title)
248+
{
249+
$this->title = $title;
250+
251+
return $this;
252+
}
253+
233254
/**
234255
* Get fields of this builder.
235256
*
@@ -332,6 +353,10 @@ public function option($option, $value = null)
332353
*/
333354
public function title()
334355
{
356+
if ($this->title) {
357+
return $this->title;
358+
}
359+
335360
if ($this->mode == static::MODE_CREATE) {
336361
return trans('admin.create');
337362
}

src/Form/Field/Tags.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function value($value = null)
6565
return empty($this->value) ? ($this->getDefault() ?? []) : $this->value;
6666
}
6767

68-
$this->value = $value;
68+
$this->value = (array) $value;
6969

7070
return $this;
7171
}
@@ -80,6 +80,8 @@ public function render()
8080
tokenSeparators: [',']
8181
});";
8282

83-
return parent::render();
83+
return parent::render()->with([
84+
'options' => array_unique(array_merge($this->value, $this->options)),
85+
]);
8486
}
8587
}

src/Grid/Displayers/RowSelector.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,16 @@ protected function script()
2525
$(this).closest('tr').css('background-color', '');
2626
}
2727
});
28+
29+
var selectedRows = function () {
30+
var selected = [];
31+
$('.grid-row-checkbox:checked').each(function(){
32+
selected.push($(this).data('id'));
33+
});
34+
35+
return selected;
36+
}
37+
2838
EOT;
2939
}
3040
}

src/Grid/Row.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class Row
99
*
1010
* @var
1111
*/
12-
protected $number;
12+
public $number;
1313

1414
/**
1515
* Row data.

src/Grid/Tools/BatchActions.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -104,15 +104,6 @@ protected function script()
104104
}
105105
});
106106

107-
var selectedRows = function () {
108-
var selected = [];
109-
$('.grid-row-checkbox:checked').each(function(){
110-
selected.push($(this).data('id'));
111-
});
112-
113-
return selected;
114-
}
115-
116107
EOT;
117108
}
118109

0 commit comments

Comments
 (0)