mirror of https://github.com/1099438829/apeblog
注册逻辑
This commit is contained in:
parent
4f23f09295
commit
cc6e85f5e0
|
|
@ -0,0 +1,81 @@
|
||||||
|
<?php
|
||||||
|
declare (strict_types=1);
|
||||||
|
|
||||||
|
namespace app\api\controller;
|
||||||
|
|
||||||
|
use app\BaseController;
|
||||||
|
use app\common\constant\Data;
|
||||||
|
use app\common\model\PvLog;
|
||||||
|
use app\common\model\UrlLog;
|
||||||
|
use think\facade\Session;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 控制器基础类
|
||||||
|
*/
|
||||||
|
class Base extends BaseController
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 当前登陆用户信息
|
||||||
|
* @var
|
||||||
|
*/
|
||||||
|
protected $userInfo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 当前登陆用户ID
|
||||||
|
* @var int
|
||||||
|
*/
|
||||||
|
protected $userId;
|
||||||
|
|
||||||
|
// 初始化
|
||||||
|
protected function initialize()
|
||||||
|
{
|
||||||
|
parent::initialize();
|
||||||
|
|
||||||
|
$this->userInfo = Session::get(Data::SESSION_KEY_USER_INFO);
|
||||||
|
$this->userId = Session::get(Data::SESSION_KEY_USER_ID);
|
||||||
|
|
||||||
|
if ($this->userId){
|
||||||
|
//模板兼容性标签
|
||||||
|
$this->assign('user_info', $this->userInfo);
|
||||||
|
$this->assign('user_id', $this->userId);
|
||||||
|
}
|
||||||
|
//判断是否关闭站点。
|
||||||
|
if (web_config('web_close')==1) {
|
||||||
|
$this->error('网站暂时关闭!', '', 'stop');
|
||||||
|
}
|
||||||
|
//判断后台统计配置是否开启 1 开启
|
||||||
|
if (web_config("web_statistics") == 1) {
|
||||||
|
//pv表 zz_pv_log 栏目存在 点击进入页面后
|
||||||
|
$pvLogModel = new PvLog();
|
||||||
|
$pvLogModel->set_view();
|
||||||
|
}
|
||||||
|
cache(Data::CURR_CATEGORY_PATENT_ID, false);
|
||||||
|
//模板兼容性标签
|
||||||
|
$this->assign('id', false);
|
||||||
|
$this->assign('cid', false);
|
||||||
|
|
||||||
|
//获取根域名
|
||||||
|
//判断是否开启了伪静态
|
||||||
|
// if (web_config('web_rewrite')=='0') {
|
||||||
|
// $this->request->setRoot('/?s=');
|
||||||
|
// } elseif(web_config('web_rewrite')=='1') {
|
||||||
|
// $this->request->setRoot('/');
|
||||||
|
// } else {
|
||||||
|
// $this->request->setRoot('/index.php');
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* url 统计
|
||||||
|
* @param $title
|
||||||
|
* @author 木子的忧伤
|
||||||
|
* @date 2021-05-09 23:44
|
||||||
|
*/
|
||||||
|
protected function urlrecord($title)
|
||||||
|
{
|
||||||
|
$urlLogModel = new UrlLog();
|
||||||
|
//获取url
|
||||||
|
$urlInfo = $this->request->url(true);
|
||||||
|
$urlLogModel->set_url($title, $urlInfo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -7,6 +7,7 @@ use app\common\constant\Data;
|
||||||
use think\db\exception\DataNotFoundException;
|
use think\db\exception\DataNotFoundException;
|
||||||
use think\db\exception\DbException;
|
use think\db\exception\DbException;
|
||||||
use think\db\exception\ModelNotFoundException;
|
use think\db\exception\ModelNotFoundException;
|
||||||
|
use think\facade\Request;
|
||||||
use think\facade\Session;
|
use think\facade\Session;
|
||||||
use mailer\Mailer;
|
use mailer\Mailer;
|
||||||
use think\Model;
|
use think\Model;
|
||||||
|
|
@ -70,15 +71,19 @@ class User extends BaseModel
|
||||||
if (!$res) {
|
if (!$res) {
|
||||||
return self::setErrorInfo("账号注册失败,请稍后再试");
|
return self::setErrorInfo("账号注册失败,请稍后再试");
|
||||||
} else {
|
} else {
|
||||||
//开始发送激活邮件,激活邮件处理
|
//生成密码重置key 设置有效时间 过期无效
|
||||||
|
$key = md5($info->email . rand(1000, 99999));
|
||||||
|
cache($key, $res, 24 * 60 * 60); //缓存1天过后则失效根据用户id设置用户激活
|
||||||
|
$host = Request::domain();
|
||||||
//TODO 这里暂时未完成 设计是 支持模板来配置这里的任务 后台可以编辑模板这样子
|
//TODO 这里暂时未完成 设计是 支持模板来配置这里的任务 后台可以编辑模板这样子
|
||||||
|
$content = "您已经成功在蓝米云注册会员,请点击以下链接完成账号激活:{$host}/forget?action=rested&key={$key}&id=20
|
||||||
|
请在24小时内完成激活,24小时后链接地址失效,如果通过点击以上链接无法访问,请将上面的地址复制到您使用的浏览器地址中进入,如果您并没有访问过蓝米云官网,或没有进行上述操作,请忽略这封邮件!此帐号将不会绑定您的邮箱。感谢您的访问,祝您使用愉快!";
|
||||||
$mailer = new Mailer();
|
$mailer = new Mailer();
|
||||||
$mailer->from('10086@qq.com')
|
$mailer->from(system_config('title'))
|
||||||
->to('10086@qq.com')
|
->to($info->email)
|
||||||
->subject('邮件主题')
|
->subject(system_config('title') . '注册激活邮件')
|
||||||
->text('邮件内容')
|
->text($content)
|
||||||
->send();
|
->send();
|
||||||
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
@ -193,9 +198,13 @@ class User extends BaseModel
|
||||||
* @throws DbException
|
* @throws DbException
|
||||||
* @throws ModelNotFoundException
|
* @throws ModelNotFoundException
|
||||||
*/
|
*/
|
||||||
public static function resetPassword(string $userid, $password)
|
public static function resetPassword($key, $password)
|
||||||
{
|
{
|
||||||
$info = self::where('id', '=', $userid)->find();
|
$username = cache($key); //缓存1天过后则失效
|
||||||
|
if (empty($username)){
|
||||||
|
return self::setErrorInfo("链接已失效或者用户不存在");
|
||||||
|
}
|
||||||
|
$info = self::where('username|email', '=', $username)->find();
|
||||||
if (!$info) return self::setErrorInfo("用户不存在");
|
if (!$info) return self::setErrorInfo("用户不存在");
|
||||||
$info['password'] = md5(md5($password));
|
$info['password'] = md5(md5($password));
|
||||||
$info['status'] = 2;
|
$info['status'] = 2;
|
||||||
|
|
@ -216,21 +225,21 @@ class User extends BaseModel
|
||||||
*/
|
*/
|
||||||
public static function lostPassword($username)
|
public static function lostPassword($username)
|
||||||
{
|
{
|
||||||
$model = new self;
|
|
||||||
$info = self::where('username|email', '=', $username)->find();
|
$info = self::where('username|email', '=', $username)->find();
|
||||||
if ($info) return self::setErrorInfo("账号或邮箱不存在,请检查后重试");
|
if ($info) return self::setErrorInfo("账号或邮箱不存在,请检查后重试");
|
||||||
//生成密码重置key 设置有效时间 过期无效
|
//生成密码重置key 设置有效时间 过期无效
|
||||||
$key = md5($info->email . rand(1000,99999));
|
$key = md5($info->email . rand(1000, 99999));
|
||||||
cache($key,"----",24*60*60); //缓存1天过后则失效
|
cache($key, $username, 24 * 60 * 60); //缓存1天过后则失效
|
||||||
//发送邮箱
|
$host = Request::domain();
|
||||||
|
//发送邮件
|
||||||
$content = "您好,您在本网站进行重置密码操作,请点击如下链接进入重置密码页面。【本链接24小时内容有效,如果不是您的操作,请忽略】
|
$content = "您好,您在本网站进行重置密码操作,请点击如下链接进入重置密码页面。【本链接24小时内容有效,如果不是您的操作,请忽略】
|
||||||
/forget?action=rested&key={$key}&id=20";
|
{$host}/forget?action=rested&key={$key}&id=20";
|
||||||
$mailer = new Mailer();
|
$mailer = new Mailer();
|
||||||
$mailer->from(system_config('title'))
|
$mailer->from(system_config('title'))
|
||||||
->to($info->email)
|
->to($info->email)
|
||||||
->subject(system_config('title').'重置密码验证')
|
->subject(system_config('title') . '重置密码验证')
|
||||||
->text($content)
|
->text($content)
|
||||||
->send();
|
->send();
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -11,5 +11,4 @@ class UvLog extends BaseModel
|
||||||
|
|
||||||
//自动时间戳
|
//自动时间戳
|
||||||
protected $autoWriteTimestamp = true;
|
protected $autoWriteTimestamp = true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -112,7 +112,7 @@ class User extends Base
|
||||||
switch ($action) {
|
switch ($action) {
|
||||||
case'rested':
|
case'rested':
|
||||||
//重置密码
|
//重置密码
|
||||||
if (!userModel::resetPassword($username, $password)) return app("json")->fail(userModel::getErrorInfo());
|
if (!userModel::resetPassword($key, $password)) return app("json")->fail(userModel::getErrorInfo());
|
||||||
return app("json")->success("密码重置成功!");
|
return app("json")->success("密码重置成功!");
|
||||||
case 'LastPass':
|
case 'LastPass':
|
||||||
// 验证码验证
|
// 验证码验证
|
||||||
|
|
|
||||||
|
|
@ -128,13 +128,13 @@
|
||||||
</a>
|
</a>
|
||||||
<ul class="user-sub-menu sub-menu">
|
<ul class="user-sub-menu sub-menu">
|
||||||
<li>
|
<li>
|
||||||
<a href="{:url('index/login/profile')}"><i class="fas fa-user-cog"></i> 账号设置</a>
|
<a href="{:url('index/user/profile')}"><i class="fas fa-user-cog"></i> 账号设置</a>
|
||||||
</li>
|
</li>
|
||||||
<!-- <li>-->
|
<!-- <li>-->
|
||||||
<!-- <a href="{:url('index/login/loginout')}"><i class="far fa-edit"></i>新建文章</a>-->
|
<!-- <a href="{:url('index/login/loginout')}"><i class="far fa-edit"></i>新建文章</a>-->
|
||||||
<!-- </li>-->
|
<!-- </li>-->
|
||||||
<li>
|
<li>
|
||||||
<a href="{:url('index/login/logout')}"><i class="fas fa-sign-out-alt"></i> 退出登录</a>
|
<a href="{:url('index/user/logout')}"><i class="fas fa-sign-out-alt"></i> 退出登录</a>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue