Typecho前台登录

前言

前台登录是个很方便的功能,无论是作为个人博客还是多人博客,前台登录都会节省用户时间。

代码

<form action="<?php $this->options->loginAction()?>" method="post" name="login" rold="form">
<input type="hidden" name="referer" value="<?php $this->options->siteUrl(); ?>">
<input type="text" name="name" autocomplete="username" placeholder="请输入用户名" required/>
<input type="password" name="password" autocomplete="current-password" placeholder="请输入密码" required/>
<button type="submit">登录</button>
</form>

其中 referer 这个input就指明了登录成功后的跳转位置,现在默认的首页,可以修改value的值来自行定义登录成功跳转得地址。

Typecho前台注册

代码

<form action="<?php $this->options->registerAction();?>" method="post" name="register" role="form">
<input type="hidden" name="_" value="<?php echo $this->security->getToken($this->request->getRequestUrl());?>">
用户名<input type="text" name="name">
邮箱:<input type="email" id="mail" name="mail" >
<button type="submit" name="loginsubmit" value="true">注册</button>
</form>

说明

用户进入注册页面,只会要求用户填写用户名和邮箱,点击注册按钮后会跳转到程序后台,此时会提示被分配了个临时密码,同时提示用户修改默认密码,填写个人信息如昵称,个人主页等。

扩展

如果也想像前台登录一样,登陆后自定义跳转页面,需要修改/var/Widget/Register.php这个文件,倒数第三行左右的这个代码$this->response->redirect($this->options->adminUrl);换成如下代码

if (NULL != $this->request->referer) {
$this->response->redirect($this->request->referer);
} else{
$this->response->redirect($this->options->adminUrl);
}

这样在form里插入

<input type="hidden" name="referer" value="跳转地址">

即可。

版权属于:泽泽社长
本文链接:https://blog.zezeshe.com/archives/typecho-login-registration.html
本站未注明转载的文章均为原创,并采用 CC BY-NC-SA 4.0 授权协议,转载请注明来源,谢谢!