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