国内外多语言版盲盒网站开发建设 第二篇

哄哄 -
国内外多语言版盲盒网站开发建设 第二篇


接着前面的第一篇,往下面写,这个是国内外多语言版盲盒网站系统开发建设 第二篇,直接进入正题了。

退出登录

public function logout()

{
    //退出本站
    $this->auth->logout();
    $this->success(__('Logout successful'), url('user/index'));
}

/**
     * 个人信息
     */
    public function profile()
    {
        $this->view->assign('title', __('Profile'));
        return $this->view->fetch();
    }

修改密码

public function changepwd()

{
    if ($this->request->isPost()) {
        $oldpassword = $this->request->post("oldpassword");
        $newpassword = $this->request->post("newpassword");
        $renewpassword = $this->request->post("renewpassword");
        $token = $this->request->post('__token__');
        $rule = [
            'oldpassword'   => 'require|length:6,30',
            'newpassword'   => 'require|length:6,30',
            'renewpassword' => 'require|length:6,30|confirm:newpassword',
            '__token__'     => 'token',
        ];

        $msg = [
            'renewpassword.confirm' => __('Password and confirm password don\'t match')
        ];
        $data = [
            'oldpassword'   => $oldpassword,
            'newpassword'   => $newpassword,
            'renewpassword' => $renewpassword,
            '__token__'     => $token,
        ];
        $field = [
            'oldpassword'   => __('Old password'),
            'newpassword'   => __('New password'),
            'renewpassword' => __('Renew password')
        ];
        $validate = new Validate($rule, $msg, $field);
        $result = $validate->check($data);
        if (!$result) {
            $this->error(__($validate->getError()), null, ['token' => $this->request->token()]);
            return false;
        }

        $ret = $this->auth->changepwd($newpassword, $oldpassword);
        if ($ret) {
            $this->success(__('Reset password successful'), url('user/login'));
        } else {
            $this->error($this->auth->getError(), null, ['token' => $this->request->token()]);
        }
    }
    $this->view->assign('title', __('Change password'));
    return $this->view->fetch();
}

设置过滤方法

public function attachment()

{
    //设置过滤方法
    $this->request->filter(['strip_tags']);
    if ($this->request->isAjax()) {
        $mimetypeQuery = [];
        $where = [];
        $filter = $this->request->request('filter');
        $filterArr = (array)json_decode($filter, true);
        if (isset($filterArr['mimetype']) && preg_match("/[]\,|\*]/", $filterArr['mimetype'])) {
            $this->request->get(['filter' => json_encode(array_diff_key($filterArr, ['mimetype' => '']))]);
            $mimetypeQuery = function ($query) use ($filterArr) {
                $mimetypeArr = explode(',', $filterArr['mimetype']);
                foreach ($mimetypeArr as $index => $item) {
                    if (stripos($item, "/*") !== false) {
                        $query->whereOr('mimetype', 'like', str_replace("/*", "/", $item) . '%');
                    } else {
                        $query->whereOr('mimetype', 'like', '%' . $item . '%');
                    }
                }
            };
        } elseif (isset($filterArr['mimetype'])) {
            $where['mimetype'] = ['like', '%' . $filterArr['mimetype'] . '%'];
        }

        if (isset($filterArr['filename'])) {
            $where['filename'] = ['like', '%' . $filterArr['filename'] . '%'];
        }

        if (isset($filterArr['createtime'])) {
            $timeArr = explode(' - ', $filterArr['createtime']);
            $where['createtime'] = ['between', [strtotime($timeArr[0]), strtotime($timeArr[1])]];
        }

        $model = new Attachment();
        $offset = $this->request->get("offset", 0);
        $limit = $this->request->get("limit", 0);
        $total = $model
            ->where($where)
            ->where($mimetypeQuery)
            ->where('user_id', $this->auth->id)
            ->order("id", "DESC")
            ->count();

        $list = $model
            ->where($where)
            ->where($mimetypeQuery)
            ->where('user_id', $this->auth->id)
            ->order("id", "DESC")
            ->limit($offset, $limit)
            ->select();
        $cdnurl = preg_replace("/\/(\w+)\.php$/i", '', $this->request->root());
        foreach ($list as $k => &$v) {
            $v['fullurl'] = ($v['storage'] == 'local' ? $cdnurl : $this->view->config['upload']['cdnurl']) . $v['url'];
        }
        unset($v);
        $result = array("total" => $total, "rows" => $list);

        return json($result);
    }
    $this->view->assign("mimetypeList", \app\common\model\Attachment::getMimetypeList());
    return $this->view->fetch();
}

}

Ajax异步请求接口

class Ajax extends Frontend
{

protected $noNeedLogin = ['lang', 'upload'];
protected $noNeedRight = ['*'];
protected $layout = '';

加载语言包

public function lang()

{
    header('Content-Type: application/javascript');
    header("Cache-Control: public");
    header("Pragma: cache");

    $offset = 30 * 60 * 60 * 24; // 缓存一个月
    header("Expires: " . gmdate("D, d M Y H:i:s", time() + $offset) . " GMT");

    $controllername = input("controllername");
    $this->loadlang($controllername);
    //强制输出JSON Object
    $result = jsonp(Lang::get(), 200, [], ['json_encode_param' => JSON_FORCE_OBJECT | JSON_UNESCAPED_UNICODE]);
    return $result;
}

 上传文件
 
   

public function upload()
    {
        return action('api/common/upload');
    }

}

特别申明:本文内容来源网络,版权归原作者所有,如有侵权请立即与我们联系(cy198701067573@163.com),我们将及时处理。

php介绍

PHP即“超文本预处理器”,是一种通用开源脚本语言。PHP是在服务器端执行的脚本语言,与C语言类似,是常用的网站编程语言。PHP独特的语法混合了C、Java、Perl以及 PHP 自创的语法。利于学习,使用广泛,主要适用于Web开发领域。

Tags 标签

phpmysql

扩展阅读

加个好友,技术交流

1628738909466805.jpg