login automatically after registeration
This commit is contained in:
parent
90675e7aeb
commit
b5e339cc0e
|
|
@ -85,7 +85,12 @@ class AuthController extends BaseController
|
||||||
// use once md5 to encrypt password
|
// use once md5 to encrypt password
|
||||||
$user = $user->register($_POST['password'], \Http::getRealIP());
|
$user = $user->register($_POST['password'], \Http::getRealIP());
|
||||||
$user->setNickName($_POST['nickname']);
|
$user->setNickName($_POST['nickname']);
|
||||||
View::json('注册成功~', 0);
|
|
||||||
|
echo json_encode([
|
||||||
|
'errno' => 0,
|
||||||
|
'msg' => '注册成功,正在跳转~',
|
||||||
|
'token' => $user->getToken()
|
||||||
|
]);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
View::json('你最多只能注册 '.Option::get('regs_per_ip').' 个账户哦', 7);
|
View::json('你最多只能注册 '.Option::get('regs_per_ip').' 个账户哦', 7);
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ namespace App\Middlewares;
|
||||||
use \Pecee\Http\Middleware\IMiddleware;
|
use \Pecee\Http\Middleware\IMiddleware;
|
||||||
use \Pecee\Http\Request;
|
use \Pecee\Http\Request;
|
||||||
use App\Exceptions\E;
|
use App\Exceptions\E;
|
||||||
|
use View;
|
||||||
|
|
||||||
class CheckPostMiddleware implements IMiddleware
|
class CheckPostMiddleware implements IMiddleware
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -52,7 +52,7 @@ class User
|
||||||
$this->uid = $this->eloquent_model->uid;
|
$this->uid = $this->eloquent_model->uid;
|
||||||
$this->email = $this->eloquent_model->email;
|
$this->email = $this->eloquent_model->email;
|
||||||
$this->password = $this->eloquent_model->password;
|
$this->password = $this->eloquent_model->password;
|
||||||
$this->token = md5($this->email . $this->password . SALT);
|
$this->token = md5($this->email . $this->password . $_ENV['SALT']);
|
||||||
$this->closet = new Closet($this->uid);
|
$this->closet = new Closet($this->uid);
|
||||||
$this->is_admin = ($this->eloquent_model->permission == 1);
|
$this->is_admin = ($this->eloquent_model->permission == 1);
|
||||||
}
|
}
|
||||||
|
|
@ -109,6 +109,8 @@ class User
|
||||||
|
|
||||||
public function getToken()
|
public function getToken()
|
||||||
{
|
{
|
||||||
|
if ($this->token === "")
|
||||||
|
$this->token = md5($this->eloquent_model->email . $this->eloquent_model->password . $_ENV['SALT']);
|
||||||
return $this->token;
|
return $this->token;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
* @Author: printempw
|
* @Author: printempw
|
||||||
* @Date: 2016-07-17 10:54:22
|
* @Date: 2016-07-17 10:54:22
|
||||||
* @Last Modified by: printempw
|
* @Last Modified by: printempw
|
||||||
* @Last Modified time: 2016-07-23 15:26:48
|
* @Last Modified time: 2016-07-27 18:18:16
|
||||||
*/
|
*/
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
@ -13,6 +13,11 @@ $(document).ready(function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function freshCaptcha() {
|
||||||
|
$('.captcha').attr('src', './captcha?' + new Date().getTime());
|
||||||
|
$('#captcha').val('');
|
||||||
|
}
|
||||||
|
|
||||||
var login_fails = 0;
|
var login_fails = 0;
|
||||||
|
|
||||||
$('#login-button').click(function() {
|
$('#login-button').click(function() {
|
||||||
|
|
@ -63,8 +68,7 @@ $('#login-button').click(function() {
|
||||||
if (json.login_fails > 3) {
|
if (json.login_fails > 3) {
|
||||||
$('#captcha-form').show();
|
$('#captcha-form').show();
|
||||||
toastr.warning('你尝试的次数太多啦,请输入验证码');
|
toastr.warning('你尝试的次数太多啦,请输入验证码');
|
||||||
// fresh captcha
|
freshCaptcha();
|
||||||
$('.captcha').attr('src', './captcha?' + new Date().getTime());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
showMsg(json.msg, 'warning');
|
showMsg(json.msg, 'warning');
|
||||||
|
|
@ -127,10 +131,15 @@ $('#register-button').click(function() {
|
||||||
},
|
},
|
||||||
success: function(json) {
|
success: function(json) {
|
||||||
if (json.errno == 0) {
|
if (json.errno == 0) {
|
||||||
showMsg('注册成功,请登录~', 'success');
|
// login automatically
|
||||||
window.setTimeout('window.location = "./login"', 1000);
|
docCookies.setItem('email', email, null, '/');
|
||||||
|
docCookies.setItem('token', json.token, null, '/');
|
||||||
|
|
||||||
|
showMsg(json.msg, 'success');
|
||||||
|
window.setTimeout('window.location = "../user"', 1000);
|
||||||
} else {
|
} else {
|
||||||
showMsg(json.msg, 'warning');
|
showMsg(json.msg, 'warning');
|
||||||
|
freshCaptcha();
|
||||||
$('#register-button').html('注册').prop('disabled', '');
|
$('#register-button').html('注册').prop('disabled', '');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@
|
||||||
|
|
||||||
@if (isset($_SESSION['msg']))
|
@if (isset($_SESSION['msg']))
|
||||||
<script>
|
<script>
|
||||||
toastr.info('{{ $_SESSION['msg'] }}'); <?php unset($_SESSION['msg']) ?>
|
toastr.info('{{ $_SESSION['msg'] }}'); <?php unset($_SESSION['msg']); ?>
|
||||||
</script>
|
</script>
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user