fix minimal length of password
This commit is contained in:
parent
5efd875b06
commit
f0532dcc6c
@ -22,23 +22,16 @@ class AuthController extends Controller
|
||||
public function handleLogin(Request $request)
|
||||
{
|
||||
$this->validate($request, [
|
||||
'email' => 'sometimes|required|email',
|
||||
'username' => 'sometimes|required|username',
|
||||
'password' => 'required|min:8|max:16'
|
||||
'identification' => 'required',
|
||||
'password' => 'required|min:6|max:16'
|
||||
]);
|
||||
|
||||
if ($request->has('email')) {
|
||||
$auth_type = "email";
|
||||
} elseif ($request->has('username')) {
|
||||
$auth_type = "username";
|
||||
} else {
|
||||
return json(trans('auth.validation.identification'), 3);
|
||||
}
|
||||
$identification = $request->input('identification');
|
||||
|
||||
$auth_type = (validate($request->input('identification'), 'email')) ? "email" : "username";
|
||||
|
||||
// instantiate user
|
||||
$user = ($auth_type == 'email') ?
|
||||
new User(null, ['email' => $request->input('email')]) :
|
||||
new User(null, ['username' => $request->input('username')]);
|
||||
$user = new User(null, [$auth_type => $identification]);
|
||||
|
||||
if (session('login_fails', 0) > 3) {
|
||||
if (strtolower($request->input('captcha')) != strtolower(session('phrase')))
|
||||
@ -59,18 +52,13 @@ class AuthController extends Controller
|
||||
setcookie('uid', $user->uid, time()+$time, '/');
|
||||
setcookie('token', $user->getToken(), time()+$time, '/');
|
||||
|
||||
return json([
|
||||
'errno' => 0,
|
||||
'msg' => trans('auth.login.success'),
|
||||
return json(trans('auth.login.success'), 0, [
|
||||
'token' => $user->getToken()
|
||||
]);
|
||||
} else {
|
||||
$fails = session('login_fails', 0);
|
||||
Session::put('login_fails', $fails + 1);
|
||||
Session::put('login_fails', session('login_fails', 0) + 1);
|
||||
|
||||
return json([
|
||||
'errno' => 1,
|
||||
'msg' => trans('auth.validation.password'),
|
||||
return json(trans('auth.validation.password'), 1, [
|
||||
'login_fails' => session('login_fails')
|
||||
]);
|
||||
}
|
||||
|
@ -232,3 +232,19 @@ if (! function_exists('menv')) {
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('validate')) {
|
||||
|
||||
function validate($value, $type)
|
||||
{
|
||||
switch ($type) {
|
||||
case 'email':
|
||||
return (bool) filter_var($value, FILTER_VALIDATE_EMAIL);
|
||||
break;
|
||||
|
||||
default:
|
||||
# code...
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
/*
|
||||
* @Author: printempw
|
||||
* @Date: 2016-07-17 10:54:22
|
||||
* @Last Modified by: printempw
|
||||
* @Last Modified time: 2016-09-15 10:09:52
|
||||
* @Last Modified by: prpr
|
||||
* @Last Modified time: 2016-10-02 20:27:13
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
@ -21,22 +21,15 @@ function freshCaptcha() {
|
||||
var login_fails = 0;
|
||||
|
||||
$('#login-button').click(function() {
|
||||
var data = new Object();
|
||||
var email_or_uname = $('#email_or_username').val();
|
||||
|
||||
if (/\S+@\S+\.\S+/.test($('#email_or_username').val())) {
|
||||
data.email = email_or_uname;
|
||||
} else {
|
||||
data.username = email_or_uname;
|
||||
}
|
||||
var data = new Object();
|
||||
|
||||
data.identification = $('#identification').val();
|
||||
data.password = $('#password').val();
|
||||
data.keep = $('#keep').prop('checked') ? true : false;
|
||||
|
||||
if (email_or_uname == "") {
|
||||
if (data.identification == "") {
|
||||
showMsg(trans('auth.emptyIdentification'));
|
||||
$('#email_or_username').focus();
|
||||
// check valid email address
|
||||
$('#identification').focus();
|
||||
} else if (data.password == "") {
|
||||
showMsg(trans('auth.emptyPassword'));
|
||||
$('#password').focus();
|
||||
|
@ -1,6 +1,6 @@
|
||||
general:
|
||||
filter: Filter
|
||||
my-upload: My Uploaded
|
||||
my-upload: Uploaded by Me
|
||||
sort: Sort
|
||||
search-textures: Search For Textures
|
||||
upload-new-skin: Upload New Skin
|
||||
|
@ -75,10 +75,13 @@ url: ':attribute 格式不正确。'
|
||||
|
||||
custom:
|
||||
attribute-name: { rule-name: custom-message }
|
||||
identification:
|
||||
required: 邮箱或角色名格式错误
|
||||
|
||||
attributes:
|
||||
name: 名称
|
||||
username: 用户名
|
||||
identification: 邮箱或角色名
|
||||
nickname: 昵称
|
||||
player_name: 角色名
|
||||
email: 邮箱
|
||||
|
@ -14,7 +14,7 @@
|
||||
|
||||
<form id="login-form">
|
||||
<div class="form-group has-feedback">
|
||||
<input id="email_or_username" type="email" class="form-control" placeholder="{{ trans('auth.identification') }}">
|
||||
<input id="identification" type="email" class="form-control" placeholder="{{ trans('auth.identification') }}">
|
||||
<span class="glyphicon glyphicon-envelope form-control-feedback"></span>
|
||||
</div>
|
||||
<div class="form-group has-feedback">
|
||||
|
@ -37,7 +37,7 @@ switch ($step) {
|
||||
$password = $_POST['password'];
|
||||
$sitename = isset($_POST['sitename']) ? $_POST['sitename'] : "Blessing Skin Server";
|
||||
|
||||
if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
|
||||
if (validate($email, 'email')) {
|
||||
if (!check_password($password)) {
|
||||
redirect_to('index.php?step=2', '无效的密码。密码长度应该大于 8 并小于 16。');
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user