fix bug of register and deleting account
This commit is contained in:
parent
dddd66d49e
commit
56bfcd0b67
@ -66,10 +66,8 @@ class AuthController extends BaseController
|
||||
public function logout()
|
||||
{
|
||||
if (isset($_SESSION['token'])) {
|
||||
$user = new User($_SESSION['uid']);
|
||||
|
||||
setcookie('uid', $user->uid, time()-3600, '/');
|
||||
setcookie('token', $user->getToken(), time()-3600, '/');
|
||||
setcookie('uid', '', time() - 3600, '/');
|
||||
setcookie('token', '', time() - 3600, '/');
|
||||
|
||||
session_destroy();
|
||||
|
||||
@ -109,6 +107,10 @@ class AuthController extends BaseController
|
||||
$user = $user->register($_POST['password'], Http::getRealIP());
|
||||
$user->setNickName($_POST['nickname']);
|
||||
|
||||
// set cookies
|
||||
setcookie('uid', $user->uid, time() + 3600, '/');
|
||||
setcookie('token', $user->getToken(), time() + 3600, '/');
|
||||
|
||||
View::json([
|
||||
'errno' => 0,
|
||||
'msg' => '注册成功,正在跳转~',
|
||||
|
@ -89,9 +89,13 @@ class UserController extends BaseController
|
||||
if (!$this->user->checkPasswd($_POST['password']))
|
||||
View::json('密码错误', 1);
|
||||
|
||||
if ($this->user->delete())
|
||||
View::json('账号已被成功删除', 0);
|
||||
if ($this->user->delete()) {
|
||||
setcookie('uid', '', time() - 3600, '/');
|
||||
setcookie('token', '', time() - 3600, '/');
|
||||
session_destroy();
|
||||
|
||||
View::json('账号已被成功删除', 0);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -132,8 +132,10 @@ class User
|
||||
|
||||
public function getToken($refresh = false)
|
||||
{
|
||||
if ($this->token === "" || $refresh)
|
||||
if ($this->is_registered && ($this->token === "" || $refresh)) {
|
||||
$this->token = md5($this->model->email . $this->model->password . $_ENV['SALT']);
|
||||
}
|
||||
|
||||
return $this->token;
|
||||
}
|
||||
|
||||
@ -231,7 +233,10 @@ class User
|
||||
$closet->textures = "";
|
||||
$closet->save();
|
||||
|
||||
$this->model = $user;
|
||||
$this->model = $user;
|
||||
$this->uid = $user->uid;
|
||||
$this->is_registered = true;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
* @Author: printempw
|
||||
* @Date: 2016-07-17 10:54:22
|
||||
* @Last Modified by: printempw
|
||||
* @Last Modified time: 2016-08-16 22:23:42
|
||||
* @Last Modified time: 2016-08-26 13:05:14
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
@ -140,10 +140,6 @@ $('#register-button').click(function() {
|
||||
},
|
||||
success: function(json) {
|
||||
if (json.errno == 0) {
|
||||
// login automatically
|
||||
docCookies.setItem('email', email, null, '/');
|
||||
docCookies.setItem('token', json.token, null, '/');
|
||||
|
||||
swal({
|
||||
type: 'success',
|
||||
html: json.msg
|
||||
|
@ -2,7 +2,7 @@
|
||||
* @Author: printempw
|
||||
* @Date: 2016-07-16 10:02:24
|
||||
* @Last Modified by: printempw
|
||||
* @Last Modified time: 2016-08-16 22:13:55
|
||||
* @Last Modified time: 2016-08-26 13:21:23
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
@ -563,9 +563,7 @@ function deleteAccount() {
|
||||
type: 'success',
|
||||
html: json.msg
|
||||
}).then(function() {
|
||||
logout(true, function() {
|
||||
window.location = "../auth/login";
|
||||
});
|
||||
window.location = "../auth/login";
|
||||
});
|
||||
} else {
|
||||
swal({
|
||||
|
Loading…
Reference in New Issue
Block a user