request->get('tourl', 'index/index'); $admin = Admin::get($this->auth->id); if ($this->request->isPost()) { $oldpassword = $this->csmreq("oldpassword", true); $newpassword = $this->csmreq("newpassword", true); if ($admin->password != md5(md5($oldpassword) . $admin->salt)) { $this->error("当前登录密码错误,请重新输入!"); } else { $params = [ 'password' => $newpassword ]; $params['salt'] = Random::alnum(); $params['password'] = md5(md5($params['password']) . $params['salt']); $admin->save($params); $param = [ 'faadmin_id' => $this->auth->id, 'updatepsdtime' => time() ]; $service = new CsmAdminService(); $service->insertOrUpdateByByAdminId($param, $this->auth->id); $this->success('', '', array( 'tourl' => $tourl )); } } // 获取最近一次密码修改时间 $dao = new \app\admin\model\csmadmin\Admin(); $row = $dao->where('status', '=', 'normal') ->where('faadmin_id', '=', $this->auth->id) ->find(); // 是否第一次登录;如果否,计算上次密码修改时间 $lastupdatpsdtime = $admin->createtime; $isfirst = '0'; $lastupdatepsdd = 0; $lastlogintime = Session::get("csmadmin_lastlogintime"); if ($lastlogintime == null) { $isfirst = '1'; } else { // 如果没有密码修改时间,则以创建时间为准 if ($row != null && ($row->updatepsdtime != null || $row->updatepsdtime != 0)) { $lastupdatpsdtime = $row->updatepsdtime; } // 如果0天算1天 $lastupdatepsdd = (time() - $lastupdatpsdtime) / 7200; $lastupdatepsdd = (int) $lastupdatepsdd; $lastupdatepsdd = ($lastupdatepsdd == 0) ? 1 : $lastupdatepsdd; } $this->view->assign('title', "设置密码"); $this->view->assign('tourl', $tourl); $this->view->assign('admin', $admin); $this->view->assign('csmadmin', $row ? $row : []); $this->view->assign('isfirst', $isfirst); // 是否首次登录:1、0 $this->view->assign('lastupdatepsdd', $lastupdatepsdd); // 距离上次修改密码的时间(天) $this->view->assign('lastupdatpsdtime', $lastupdatpsdtime);//上级密码修改时间 return $this->view->fetch(); } }