个人博客系统开发-个人中心功能实现及其他

发布时间:2019-05-11 21:23:13 浏览量:1168 标签: 博客 thinkphp

今天我们继续开发个人博客系统,昨天我们做了登录功能,今天我们完善一下后台主页,并作出个人资料的修改功能。


说明:在登录页面我们做了小的优化,包括验证码点击更改,添加鼠标滑过成手状的css样式(已经同步至码云)。


一、创建个人主页模板


在admin模块view目录下创建Common文件夹,里面新建公共头文件header.html,在Index中新建index.html文件(后台首页文件),具体代码文件已经同步至码云。


二、创建个人中心模板


个人中心包含账户名称、密码及手机号这三者的修改和展示。


个人中心


三、个人中心功能实现


代码如下:

<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/5/9 0009
 * Time: 下午 9:38
 */

namespace app\admin\controller;

use app\common\model\User;
use think\captcha\Captcha;
use think\Controller;

class Login extends Controller
{
    protected $user_model;

    public function __construct()
    {
        parent::__construct();
        $this->user_model = new User();
    }

    /**
     * 登录页面
     * @return \think\response\View
     */
    public function index()
    {
        return view();
    }

    /**
     * 登录处理
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function getLogin()
    {
        $userName = input('post.userName'); //账户
        $userPass = input('post.userPass'); //密码
        $code     = input('post.code'); //验证码
        if (!captcha_check($code)) {
            // 验证失败
            $this->error('验证码错误');
        };
        if (!$userName || !$userPass) {
            //数据不完整
            $this->error('请填写账号或密码');
        }
        $res = $this->user_model->getDataOne(['user_name' => $userName], 'id,user_status,user_pass');
        if (!$res) {
            $this->error('账号或密码错误');
        }
        if ($res['user_pass'] !== md5($userPass)) {
            $this->error('账号或密码错误');
        }
        if ($res['user_status'] == 2) {
            $this->error('账户已冻结');
        }
        //记录session
        session('userName', $userName, 'thinkBlog');
        session('userId', $res['id'], 'thinkBlog');
        $this->success('登录成功', '/admin');
    }

    /**
     * 验证码
     * @return mixed
     */
    public function code()
    {
        $config  = [
            // 验证码字体大小
            'fontSize' => 30,
            // 验证码位数
            'length'   => 3,
            // 关闭验证码杂点
            'useNoise' => false,
        ];
        $captcha = new Captcha($config);
        return $captcha->entry();
    }

    /**
     * 退出登录
     */
    public function out()
    {
        session(null, 'thinkBlog');
        $this->success('成功退出');
    }
}


四、退出登录


代码见三中代码;


评论
登录后才可以进行评论哦! QQ登录
验证码
评论内容