123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361 |
- <?php
- namespace app\admin\controller\csmadmin;
- use addons\csmadmin\library\CsmBackend;
- use addons\csmadmin\library\CsmContants;
- use addons\csmadmin\library\CsmadminUtils;
- use addons\csmadmin\library\WxUtils;
- use addons\csmadmin\library\service\AdminService;
- use fast\Random;
- use think\Session;
- /**
- * Tables
- * http://127.0.0.1/fastadmin_plugin_csmmeet/public/q3HJDu2RgE.php/csmadmin/csmadminregister/registerbywx
- * 注册相关
- */
- class Csmadminregister extends CsmBackend
- {
- protected $noNeedLogin = [
- '*'
- ];
- protected $noNeedRight = [
- '*'
- ];
- protected $layout = '';
- protected $ulmenu;
- public function _initialize()
- {
- parent::_initialize();
- if ($this->auth->isLogin()) {
- $this->success('您已经登录,请先退出后再注册帐号。', 'index/index');
- }
- $config = get_addon_config(CsmContants::$ADDONS);
- if ($config['canadminregister'] == 'N') {
- $this->error("功能未开启");
- }
- $this->ulmenu = [];
- $this->ulmenu[] = [
- 'name' => '邮箱注册',
- 'url' => 'registerbyemail'
- ];
- $config = get_addon_config(CsmContants::$ADDONS);
- //v2.1.3 适配fa.1.3.4增加手机号码调整
- $this->ulmenu[] = [
- 'name' => '手机注册',
- 'url' => 'registerbymobile'
- ];
- if ($config['haswxfield'] == 'Y') {
- $this->ulmenu[] = [
- 'name' => '微信注册',
- 'url' => 'registerbywx'
- ];
- }
- $this->assign('ulmenu', $this->ulmenu);
- $config = get_addon_config(CsmContants::$ADDONS);
- $this->assignconfig("registeragreement", $config["registeragreement"]);
- $this->assign('title', "用户登录");
- $this->view->engine->layout('csmadmin/layout/default');
- }
- public function registerbyemail()
- {
- if ($this->request->isPost()) {
- $event = "csmadmin_emailregister";
- $ccode = $this->csmreq("ccode", true);
- $email = $this->csmreq("email", true);
- $username = $this->csmreq("username", true);
- $nickname = $this->csmreq("nickname", true);
- $password = $this->csmreq("password", true);
- // 校验验证码
- $sendccode = Session::get(CsmadminUtils::getSessionKey($email, $event));
- if ($sendccode != $ccode) {
- $this->error('验证码错误!');
- }
- $this->_checkRegisterUsername($username);
- $this->_checkregisteremail($email);
- // 新增申请
- $param = [
- 'applytype' => 'email',
- 'email' => $email,
- 'username' => $username,
- 'nickname' => $nickname,
- 'password' => $password
- ];
- $this->_createApply($this->request, $param);
-
- $config = get_addon_config(CsmContants::$ADDONS);
- $is = $config["isregisterneedaudit"];
- if($is=='N'){
- $this->success('注册成功,请登录。');
- }else{
- $this->success('注册成功,请等待管理员审核。');
- }
- }
- return $this->view->fetch();
- }
- public function checkregisteremail()
- {
- $email = $this->csmreq("email", true);
- $this->_checkregisteremail($email);
- $this->success("");
- }
- private function _checkregisteremail($email)
- {
- // 检测手机是否在admin中存在
- $service = new AdminService();
- $row = $service->getRowByEmail($email);
- if ($row) {
- $this->error(__('邮箱已注册'));
- }
- // 检测申请是否存在
- $adminapplydao = new \app\admin\model\csmadmin\Adminapply();
- $apply = $adminapplydao->where("email", "=", strtolower($email))
- ->where("auditstatus", "=", "0")
- ->find();
- if ($apply != null) {
- $this->error(__('您的申请待审核中,请耐心等候'));
- }
- }
- public function registerbymobile()
- {
- if ($this->request->isPost()) {
- $event = "通过手机注册验证码";
- $ccode = $this->csmreq("ccode", true);
- $mobile = $this->csmreq("mobile", true);
- $username = $this->csmreq("username", true);
- $nickname = $this->csmreq("nickname", true);
- $password = $this->csmreq("password", true);
- // 校验验证码
- $sendccode = Session::get(CsmadminUtils::getSessionKey($mobile, $event));
- if ($sendccode != $ccode) {
- $this->error('验证码错误!');
- }
- $this->_checkRegisterUsername($username);
- $this->_checkregistermobile($mobile);
- // 新增申请
- $param = [
- 'applytype' => 'mobile',
- 'mobile' => $mobile,
- 'username' => $username,
- 'nickname' => $nickname,
- 'password' => $password
- ];
- $this->_createApply($this->request, $param);
- $config = get_addon_config(CsmContants::$ADDONS);
- $is = $config["isregisterneedaudit"];
- if($is=='N'){
- $this->success('注册成功,请登录。');
- }else{
- $this->success('注册成功,请等待管理员审核。');
- }
-
- }
- return $this->view->fetch();
- }
- public function checkregistermobile()
- {
- $mobile = $this->csmreq("mobile", true);
- $this->_checkregistermobile($mobile);
- $this->success("");
- }
- private function _checkregistermobile($mobile)
- {
- // 检测手机是否在admin中存在
- $service = new AdminService();
- $row = $service->getRowByMobile($mobile);
- if ($row) {
- $this->error(__('手机已注册'));
- }
- // 检测申请是否存在
- $adminapplydao = new \app\admin\model\csmadmin\Adminapply();
- $apply = $adminapplydao->where("lower(mobile)", "=", strtolower($mobile))
- ->where("auditstatus", "=", "0")
- ->find();
- if ($apply != null) {
- $this->error(__('您的申请待审核中,请耐心等候'));
- }
- }
- private function _checkRegisterUsername($username){
- $service = new AdminService();
- $row = $service->getRowByUsername($username);
- if ($row) {
- $this->error(__('用户名已经注册'));
- }
- }
- public function registerbydd()
- {
- if ($this->request->isPost()) {
- $dduserid = $this->csmreq("dduserid", true);
- $ddusername = $this->csmreq("ddusername", true);
- $nickname = $this->csmreq("nickname", true);
- $password = $this->csmreq("password", true);
- $this->_checkregisterdd($dduserid);
- // 新增申请
- $param = [
- 'applytype' => 'dd',
- 'dduserid' => $dduserid,
- 'ddusername' => $ddusername,
- 'nickname' => $nickname,
- 'password' => $password
- ];
- $this->_createApply($this->request, $param);
- $this->success();
- }
- return $this->view->fetch();
- }
- public function checkregisterdd()
- {
- $dduserid = $this->csmreq("dduserid", true);
- $this->_checkregisterdd($dduserid);
- $this->success("");
- }
- private function _checkregisterdd($dduserid)
- {
- // 检测weixin是否在admin中存在
- $service = new AdminService();
- $row = $service->getRowByDduserid($dduserid);
- if ($row) {
- $this->error(__('微信已注册'));
- }
- // 检测申请是否存在
- $adminapplydao = new \app\admin\model\csmadmin\Adminapply();
- $apply = $adminapplydao->where("dduserid", "=", $dduserid)
- ->where("auditstatus", "=", "0")
- ->find();
- if ($apply != null) {
- $this->error(__('您的申请待审核中,请耐心等候'));
- }
- }
- public function registerbywx()
- {
- if ($this->request->isPost()) {
- $wxuserid = $this->csmreq("wxuserid", true);
- $username = $this->csmreq("username", true);
- $nickname = $this->csmreq("nickname", true);
- $password = $this->csmreq("password", true);
- $this->_checkRegisterUsername($username);
- $wxuser = WxUtils::getInfoByOpenID($wxuserid);
- // $wxusername = $this->csmreq("wxusername", true);
- //$nickname = $this->csmreq("nickname", true);
- //$password = Random::alpha(6);
- $this->_checkregisterwx($wxuserid);
- // 新增申请
- $param = [
- 'applytype' => 'wx',
- 'wxuserid' => $wxuserid,
- 'wxusername' => $wxuser['nickname'],
- 'wxsex' => $wxuser['sex'],
- 'wxcountry' => $wxuser['country'],
- 'wxprovince' => $wxuser['province'],
- 'wxcity' => $wxuser['city'],
- 'wxheadimgurl' => $wxuser['headimgurl'],
- 'username' => $username,
- 'nickname' => $nickname,
- 'password' => $password
- ];
- $this->_createApply($this->request, $param);
- $config = get_addon_config(CsmContants::$ADDONS);
- $is = $config["isregisterneedaudit"];
- if($is=='N'){
- $this->success('注册成功,请登录。');
- }else{
- $this->success('注册成功,请等待管理员审核。');
- }
- }
- return $this->view->fetch();
- }
- public function checkregisterwx()
- {
- $wxuserid = $this->csmreq("wxuserid", true);
- $this->_checkregisterwx($wxuserid);
- $this->success("");
- }
- private function _checkregisterwx($wxuserid)
- {
- // 检测weixin是否在admin中存在
- $service = new AdminService();
- $row = $service->getRowByWx($wxuserid);
- if ($row) {
- $this->error(__('微信已注册'));
- }
- // 检测申请是否存在
- $adminapplydao = new \app\admin\model\csmadmin\Adminapply();
- $apply = $adminapplydao->where("wxuserid", "=", $wxuserid)
- ->where("auditstatus", "=", "0")
- ->find();
- if ($apply != null) {
- $this->error(__('您的申请待审核中,请耐心等候'));
- }
- }
- private function _createApply($request, $param)
- {
- $config = get_addon_config(CsmContants::$ADDONS);
- $adminapplydao = new \app\admin\model\csmadmin\Adminapply();
- $salt = Random::alnum();
- $mipassword = md5(md5($param['password']) . $salt);
- $ip = $request->ip();
- $oparam = [
- "auth_group_ids" => $config["registeradmindefaultroles"],
- "password" => $mipassword,
- "salt" => $salt,
- "applyip" => $ip,
- "auditstatus" => "0",
- "applytime" => time(),
- "createtime" => time()
- ];
- // 如果安装了csmip插件,则可以显示上次注册的地理位置
- $csmip = get_addon_info('csmip');
- if ($csmip && $csmip['state']) {
- $csmip = \addons\csmip\library\Csmip::getInstance();
- $region = $csmip->getRegion($request->ip());
- $oparam['applycountry'] = $region->country;
- $oparam['applyprovince'] = $region->province;
- $oparam['applycity'] = $region->city;
- }
- $adminapplydao->create(array_merge($param, $oparam));
- $id = $adminapplydao->getLastInsID();
-
- $is = $config["isregisterneedaudit"];
- if($is=='N'){
- CsmadminUtils::createAdminByApply($id, null,false);
- }
-
- }
-
-
-
- }
|