Skip to content

Commit

Permalink
fix #1201
Browse files Browse the repository at this point in the history
  • Loading branch information
joyqi committed Oct 21, 2021
1 parent d174cc5 commit cb4457a
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 12 deletions.
4 changes: 3 additions & 1 deletion admin/login.php
Expand Up @@ -28,7 +28,9 @@
<input type="hidden" name="referer" value="<?php echo htmlspecialchars($request->get('referer')); ?>" />
</p>
<p>
<label for="remember"><input type="checkbox" name="remember" class="checkbox" value="1" id="remember" /> <?php _e('下次自动登录'); ?></label>
<label for="remember">
<input<?php if(\Typecho\Cookie::get('__typecho_remember_remember')): ?> checked<?php endif; ?> type="checkbox" name="remember" class="checkbox" value="1" id="remember" /> <?php _e('下次自动登录'); ?>
</label>
</p>
</form>

Expand Down
3 changes: 2 additions & 1 deletion var/Typecho/Response.php
Expand Up @@ -203,7 +203,8 @@ public function sendHeaders()
[$key, $value, $timeout, $path, $domain] = $cookie;

if ($timeout > 0) {
$timeout += time();
$now = time();
$timeout += $timeout > $now - 86400 ? 0 : $now;
} elseif ($timeout < 0) {
$timeout = 1;
}
Expand Down
3 changes: 1 addition & 2 deletions var/Widget/Archive.php
Expand Up @@ -1749,8 +1749,7 @@ private function singleHandle(Query $select, bool &$hasPushed)
$this->security->protect();
Cookie::set(
'protectPassword_' . $this->request->filter('int')->protectCID,
$this->request->protectPassword,
0
$this->request->protectPassword
);

$isPasswordPosted = true;
Expand Down
2 changes: 1 addition & 1 deletion var/Widget/Feedback.php
Expand Up @@ -216,7 +216,7 @@ private function comment()
}
}

$expire = $this->options->time + $this->options->timezone + 30 * 24 * 3600;
$expire = 30 * 24 * 3600;
Cookie::set('__typecho_remember_author', $comment['author'], $expire);
Cookie::set('__typecho_remember_mail', $comment['mail'], $expire);
Cookie::set('__typecho_remember_url', $comment['url'], $expire);
Expand Down
10 changes: 9 additions & 1 deletion var/Widget/Login.php
Expand Up @@ -41,6 +41,14 @@ public function action()
$validator = new Validate();
$validator->addRule('name', 'required', _t('请输入用户名'));
$validator->addRule('password', 'required', _t('请输入密码'));
$expire = 30 * 24 * 3600;

/** 记住密码状态 */
if ($this->request->remember) {
Cookie::set('__typecho_remember_remember', 1, $expire);
} elseif (Cookie::get('__typecho_remember_remember')) {
Cookie::delete('__typecho_remember_remember');
}

/** 截获验证异常 */
if ($error = $validator->run($this->request->from('name', 'password'))) {
Expand All @@ -56,7 +64,7 @@ public function action()
$this->request->name,
$this->request->password,
false,
1 == $this->request->remember ? $this->options->time + $this->options->timezone + 30 * 24 * 3600 : 0
1 == $this->request->remember ? $expire : 0
);

/** 比对密码 */
Expand Down
9 changes: 3 additions & 6 deletions var/Widget/Notice.php
Expand Up @@ -33,8 +33,7 @@ public function highlight(string $theId)
$this->highlight = $theId;
Cookie::set(
'__typecho_notice_highlight',
$theId,
Options::alloc()->time + Options::alloc()->timezone + 86400
$theId
);
}

Expand Down Expand Up @@ -64,13 +63,11 @@ public function set($value, ?string $type = 'notice', string $typeFix = 'notice'

Cookie::set(
'__typecho_notice',
json_encode($notice),
Options::alloc()->time + Options::alloc()->timezone + 86400
json_encode($notice)
);
Cookie::set(
'__typecho_notice_type',
$type,
Options::alloc()->time + Options::alloc()->timezone + 86400
$type
);
}
}

0 comments on commit cb4457a

Please sign in to comment.