前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >个人博客系统开发-个人中心功能实现及其他

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

作者头像
申霖
发布2019-12-27 15:28:16
9890
发布2019-12-27 15:28:16
举报
文章被收录于专栏:小白程序猿

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

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

一、创建个人主页模板

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

二、创建个人中心模板

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

个人中心
个人中心

三、个人中心功能实现

代码如下:

代码语言:javascript
复制
<?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('成功退出');
    }
}

四、退出登录

代码见三中代码;

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2019-05-11,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
验证码
腾讯云新一代行为验证码(Captcha),基于十道安全栅栏, 为网页、App、小程序开发者打造立体、全面的人机验证。最大程度保护注册登录、活动秒杀、点赞发帖、数据保护等各大场景下业务安全的同时,提供更精细化的用户体验。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档