Skip to content

Commit b281c64

Browse files
committed
添加中文包,添加用户表字段检测
1 parent 16d405f commit b281c64

File tree

9 files changed

+274
-20
lines changed

9 files changed

+274
-20
lines changed

app/Http/Controllers/Admin/UserController.php

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -78,17 +78,12 @@ public function create()
7878
* @param \Illuminate\Http\Request $request
7979
* @return \Illuminate\Http\Response
8080
*/
81-
public function store(Request $request)
81+
public function store(Requests\AdminUserCreateRequest $request)
8282
{
8383
$user = new User();
8484
foreach (array_keys($this->fields) as $field) {
8585
$user->$field = $request->get($field);
8686
}
87-
if ($request->get('password') != '' && $request->get('repassword') != '' && $request->get('password') == $request->get('repassword')) {
88-
$user->password = bcrypt($request->get('password'));
89-
} else {
90-
return redirect()->back()->withErrors('密码或确认密码不能为空!');
91-
}
9287
unset($user->roles);
9388
$user->save();
9489
if (is_array($request->get('roles'))) {
@@ -142,23 +137,14 @@ public function edit($id)
142137
* @param int $id
143138
* @return \Illuminate\Http\Response
144139
*/
145-
public function update(Request $request, $id)
140+
public function update(Requests\AdminUserUpdateRequest $request, $id)
146141
{
147-
148142
$user = User::find((int)$id);
149143
foreach (array_keys($this->fields) as $field) {
150144
$user->$field = $request->get($field);
151145
}
152-
if ($request->get('password') != '' || $request->get('repassword') != '') {
153-
if ($request->get('password') != '' && $request->get('repassword') != '' && $request->get('password') == $request->get('repassword')) {
154-
$user->password = bcrypt($request->get('password'));
155-
} else {
156-
return redirect()->back()->withErrors('修改密码时,密码或确认密码不能为空!');
157-
}
158-
}
159-
160146
unset($user->roles);
161-
147+
$user->save();
162148
$user->giveRoleTo($request->get('roles', []));
163149

164150
return redirect('/admin/user')->withSuccess('添加成功!');
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace App\Http\Requests;
4+
5+
use App\Http\Requests\Request;
6+
7+
class AdminUserCreateRequest extends Request
8+
{
9+
/**
10+
* Determine if the user is authorized to make this request.
11+
*
12+
* @return bool
13+
*/
14+
public function authorize()
15+
{
16+
return true;
17+
}
18+
19+
/**
20+
* Get the validation rules that apply to the request.
21+
*
22+
* @return array
23+
*/
24+
public function rules()
25+
{
26+
return [
27+
'name'=>'required|unique:admin_users|max:255',
28+
'email'=>'required|unique:admin_users|email|max:255',
29+
'password'=>'required|confirmed|min:6|max:50'
30+
];
31+
}
32+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace App\Http\Requests;
4+
5+
use App\Http\Requests\Request;
6+
7+
class AdminUserUpdateRequest extends Request
8+
{
9+
/**
10+
* Determine if the user is authorized to make this request.
11+
*
12+
* @return bool
13+
*/
14+
public function authorize()
15+
{
16+
return true;
17+
}
18+
19+
/**
20+
* Get the validation rules that apply to the request.
21+
*
22+
* @return array
23+
*/
24+
public function rules()
25+
{
26+
return [
27+
'name'=>'required|unique:admin_users,name,'.$this->get('id').'|max:255',
28+
'email'=>'required|email|unique:admin_users,email,'.$this->get('id').'|max:255',
29+
'password'=>'confirmed|min:6|max:50'
30+
];
31+
}
32+
}

config/app.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
|
6565
*/
6666

67-
'timezone' => 'UTC',
67+
'timezone' => 'Asia/Shanghai',
6868

6969
/*
7070
|--------------------------------------------------------------------------
@@ -77,7 +77,7 @@
7777
|
7878
*/
7979

80-
'locale' => 'en',
80+
'locale' => 'zh_cn',
8181

8282
/*
8383
|--------------------------------------------------------------------------

resources/lang/zh_cn/auth.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
return [
4+
5+
/*
6+
|--------------------------------------------------------------------------
7+
| Authentication Language Lines
8+
|--------------------------------------------------------------------------
9+
|
10+
| The following language lines are used during authentication for various
11+
| messages that we need to display to the user. You are free to modify
12+
| these language lines according to your application's requirements.
13+
|
14+
*/
15+
16+
'failed' => '用户名或密码错误。',
17+
'throttle' => '您的尝试登录次数过多. 请 :seconds 秒后再试。',
18+
19+
];
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
return [
4+
5+
/*
6+
|--------------------------------------------------------------------------
7+
| Pagination Language Lines
8+
|--------------------------------------------------------------------------
9+
|
10+
| The following language lines are used by the paginator library to build
11+
| the simple pagination links. You are free to change them to anything
12+
| you want to customize your views to better match your application.
13+
|
14+
*/
15+
16+
'previous' => '&laquo; 上一页',
17+
'next' => '下一页 &raquo;',
18+
19+
];

resources/lang/zh_cn/passwords.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
return [
4+
5+
/*
6+
|--------------------------------------------------------------------------
7+
| Password Reminder Language Lines
8+
|--------------------------------------------------------------------------
9+
|
10+
| The following language lines are the default lines which match reasons
11+
| that are given by the password broker for a password update attempt
12+
| has failed, such as for an invalid token or invalid new password.
13+
|
14+
*/
15+
16+
'password' => '密码至少是六位字符并且匹配。',
17+
'reset' => '密码重置成功!',
18+
'sent' => '密码重置邮件已发送!',
19+
'token' => '密码重置令牌无效。',
20+
'user' => '找不到该邮箱对应的用户。',
21+
22+
];
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
<?php
2+
3+
return [
4+
5+
/*
6+
|--------------------------------------------------------------------------
7+
| Validation Language Lines
8+
|--------------------------------------------------------------------------
9+
|
10+
| The following language lines contain the default error messages used by
11+
| the validator class. Some of these rules have multiple versions such
12+
| such as the size rules. Feel free to tweak each of these messages.
13+
|
14+
*/
15+
16+
'accepted' => ':attribute 必须接受。',
17+
'active_url' => ':attribute 不是一个有效的网址。',
18+
'after' => ':attribute 必须是一个在 :date 之后的日期。',
19+
'alpha' => ':attribute 只能由字母组成。',
20+
'alpha_dash' => ':attribute 只能由字母、数字和斜杠组成。',
21+
'alpha_num' => ':attribute 只能由字母和数字组成。',
22+
'array' => ':attribute 必须是一个数组。',
23+
'before' => ':attribute 必须是一个在 :date 之前的日期。',
24+
'between' => [
25+
'numeric' => ':attribute 必须介于 :min - :max 之间。',
26+
'file' => ':attribute 必须介于 :min - :max kb 之间。',
27+
'string' => ':attribute 必须介于 :min - :max 个字符之间。',
28+
'array' => ':attribute 必须只有 :min - :max 个单元。',
29+
],
30+
'boolean' => ':attribute 必须为布尔值。',
31+
'confirmed' => ':attribute 两次输入不一致。',
32+
'date' => ':attribute 不是一个有效的日期。',
33+
'date_format' => ':attribute 的格式必须为 :format。',
34+
'different' => ':attribute 和 :other 必须不同。',
35+
'digits' => ':attribute 必须是 :digits 位的数字。',
36+
'digits_between' => ':attribute 必须是介于 :min 和 :max 位的数字。',
37+
'dimensions' => 'The :attribute has invalid image dimensions.',
38+
'distinct' => ':attribute 已經存在。',
39+
'email' => ':attribute 不是一个合法的邮箱。',
40+
'exists' => ':attribute 不存在。',
41+
'filled' => ':attribute 不能为空。',
42+
'image' => ':attribute 必须是图片。',
43+
'in' => '已选的属性 :attribute 非法。',
44+
'in_array' => ':attribute 没有在 :other 中。',
45+
'integer' => ':attribute 必须是整数。',
46+
'ip' => ':attribute 必须是有效的 IP 地址。',
47+
'json' => ':attribute 必须是正确的 JSON 格式。',
48+
'max' => [
49+
'numeric' => ':attribute 不能大于 :max。',
50+
'file' => ':attribute 不能大于 :max kb。',
51+
'string' => ':attribute 不能大于 :max 个字符。',
52+
'array' => ':attribute 最多只有 :max 个单元。',
53+
],
54+
'mimes' => ':attribute 必须是一个 :values 类型的文件。',
55+
'min' => [
56+
'numeric' => ':attribute 必须大于等于 :min。',
57+
'file' => ':attribute 大小不能小于 :min kb。',
58+
'string' => ':attribute 至少为 :min 个字符。',
59+
'array' => ':attribute 至少有 :min 个单元。',
60+
],
61+
'not_in' => '已选的属性 :attribute 非法。',
62+
'numeric' => ':attribute 必须是一个数字。',
63+
'present' => ':attribute 必须存在。',
64+
'regex' => ':attribute 格式不正确。',
65+
'required' => ':attribute 不能为空。',
66+
'required_if' => '当 :other 为 :value 时 :attribute 不能为空。',
67+
'required_unless' => '当 :other 不为 :value 时 :attribute 不能为空。',
68+
'required_with' => '当 :values 存在时 :attribute 不能为空。',
69+
'required_with_all' => '当 :values 存在时 :attribute 不能为空。',
70+
'required_without' => '当 :values 不存在时 :attribute 不能为空。',
71+
'required_without_all' => '当 :values 都不存在时 :attribute 不能为空。',
72+
'same' => ':attribute 和 :other 必须相同。',
73+
'size' => [
74+
'numeric' => ':attribute 大小必须为 :size。',
75+
'file' => ':attribute 大小必须为 :size kb。',
76+
'string' => ':attribute 必须是 :size 个字符。',
77+
'array' => ':attribute 必须为 :size 个单元。',
78+
],
79+
'string' => ':attribute 必须是一个字符串。',
80+
'timezone' => ':attribute 必须是一个合法的时区值。',
81+
'unique' => ':attribute 已经存在。',
82+
'url' => ':attribute 格式不正确。',
83+
84+
/*
85+
|--------------------------------------------------------------------------
86+
| Custom Validation Language Lines
87+
|--------------------------------------------------------------------------
88+
|
89+
| Here you may specify custom validation messages for attributes using the
90+
| convention 'attribute.rule' to name the lines. This makes it quick to
91+
| specify a specific custom language line for a given attribute rule.
92+
|
93+
*/
94+
95+
'custom' => [
96+
'attribute-name' => [
97+
'rule-name' => 'custom-message',
98+
],
99+
],
100+
101+
/*
102+
|--------------------------------------------------------------------------
103+
| Custom Validation Attributes
104+
|--------------------------------------------------------------------------
105+
|
106+
| The following language lines are used to swap attribute place-holders
107+
| with something more reader friendly such as E-Mail Address instead
108+
| of 'email'. This simply helps us make messages a little cleaner.
109+
|
110+
*/
111+
112+
'attributes' => [
113+
'name' => '名称',
114+
'username' => '用户名',
115+
'email' => '邮箱',
116+
'first_name' => '',
117+
'last_name' => '',
118+
'password' => '密码',
119+
'password_confirmation' => '确认密码',
120+
'city' => '城市',
121+
'country' => '国家',
122+
'address' => '地址',
123+
'phone' => '电话',
124+
'mobile' => '手机',
125+
'age' => '年轻',
126+
'sex' => '性别',
127+
'gender' => '性别',
128+
'day' => '',
129+
'month' => '',
130+
'year' => '',
131+
'hour' => '',
132+
'minute' => '',
133+
'second' => '',
134+
'title' => '标题',
135+
'content' => '内容',
136+
'description' => '描述',
137+
'excerpt' => '摘要',
138+
'date' => '日期',
139+
'time' => '时间',
140+
'available' => '可用的',
141+
'size' => '大小',
142+
],
143+
144+
];

resources/views/admin/user/_form.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<div class="form-group">
2222
<label for="tag" class="col-md-3 control-label">密码确认</label>
2323
<div class="col-md-5">
24-
<input type="password" class="form-control" name="repassword" id="tag" value="" autofocus>
24+
<input type="password" class="form-control" name="password_confirmation" id="tag" value="" autofocus>
2525
</div>
2626
</div>
2727

0 commit comments

Comments
 (0)