Csmadminregister.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. <?php
  2. namespace app\admin\controller\csmadmin;
  3. use addons\csmadmin\library\CsmBackend;
  4. use addons\csmadmin\library\CsmContants;
  5. use addons\csmadmin\library\CsmadminUtils;
  6. use addons\csmadmin\library\WxUtils;
  7. use addons\csmadmin\library\service\AdminService;
  8. use fast\Random;
  9. use think\Session;
  10. /**
  11. * Tables
  12. * http://127.0.0.1/fastadmin_plugin_csmmeet/public/q3HJDu2RgE.php/csmadmin/csmadminregister/registerbywx
  13. * 注册相关
  14. */
  15. class Csmadminregister extends CsmBackend
  16. {
  17. protected $noNeedLogin = [
  18. '*'
  19. ];
  20. protected $noNeedRight = [
  21. '*'
  22. ];
  23. protected $layout = '';
  24. protected $ulmenu;
  25. public function _initialize()
  26. {
  27. parent::_initialize();
  28. if ($this->auth->isLogin()) {
  29. $this->success('您已经登录,请先退出后再注册帐号。', 'index/index');
  30. }
  31. $config = get_addon_config(CsmContants::$ADDONS);
  32. if ($config['canadminregister'] == 'N') {
  33. $this->error("功能未开启");
  34. }
  35. $this->ulmenu = [];
  36. $this->ulmenu[] = [
  37. 'name' => '邮箱注册',
  38. 'url' => 'registerbyemail'
  39. ];
  40. $config = get_addon_config(CsmContants::$ADDONS);
  41. //v2.1.3 适配fa.1.3.4增加手机号码调整
  42. $this->ulmenu[] = [
  43. 'name' => '手机注册',
  44. 'url' => 'registerbymobile'
  45. ];
  46. if ($config['haswxfield'] == 'Y') {
  47. $this->ulmenu[] = [
  48. 'name' => '微信注册',
  49. 'url' => 'registerbywx'
  50. ];
  51. }
  52. $this->assign('ulmenu', $this->ulmenu);
  53. $config = get_addon_config(CsmContants::$ADDONS);
  54. $this->assignconfig("registeragreement", $config["registeragreement"]);
  55. $this->assign('title', "用户登录");
  56. $this->view->engine->layout('csmadmin/layout/default');
  57. }
  58. public function registerbyemail()
  59. {
  60. if ($this->request->isPost()) {
  61. $event = "csmadmin_emailregister";
  62. $ccode = $this->csmreq("ccode", true);
  63. $email = $this->csmreq("email", true);
  64. $username = $this->csmreq("username", true);
  65. $nickname = $this->csmreq("nickname", true);
  66. $password = $this->csmreq("password", true);
  67. // 校验验证码
  68. $sendccode = Session::get(CsmadminUtils::getSessionKey($email, $event));
  69. if ($sendccode != $ccode) {
  70. $this->error('验证码错误!');
  71. }
  72. $this->_checkRegisterUsername($username);
  73. $this->_checkregisteremail($email);
  74. // 新增申请
  75. $param = [
  76. 'applytype' => 'email',
  77. 'email' => $email,
  78. 'username' => $username,
  79. 'nickname' => $nickname,
  80. 'password' => $password
  81. ];
  82. $this->_createApply($this->request, $param);
  83. $config = get_addon_config(CsmContants::$ADDONS);
  84. $is = $config["isregisterneedaudit"];
  85. if($is=='N'){
  86. $this->success('注册成功,请登录。');
  87. }else{
  88. $this->success('注册成功,请等待管理员审核。');
  89. }
  90. }
  91. return $this->view->fetch();
  92. }
  93. public function checkregisteremail()
  94. {
  95. $email = $this->csmreq("email", true);
  96. $this->_checkregisteremail($email);
  97. $this->success("");
  98. }
  99. private function _checkregisteremail($email)
  100. {
  101. // 检测手机是否在admin中存在
  102. $service = new AdminService();
  103. $row = $service->getRowByEmail($email);
  104. if ($row) {
  105. $this->error(__('邮箱已注册'));
  106. }
  107. // 检测申请是否存在
  108. $adminapplydao = new \app\admin\model\csmadmin\Adminapply();
  109. $apply = $adminapplydao->where("email", "=", strtolower($email))
  110. ->where("auditstatus", "=", "0")
  111. ->find();
  112. if ($apply != null) {
  113. $this->error(__('您的申请待审核中,请耐心等候'));
  114. }
  115. }
  116. public function registerbymobile()
  117. {
  118. if ($this->request->isPost()) {
  119. $event = "通过手机注册验证码";
  120. $ccode = $this->csmreq("ccode", true);
  121. $mobile = $this->csmreq("mobile", true);
  122. $username = $this->csmreq("username", true);
  123. $nickname = $this->csmreq("nickname", true);
  124. $password = $this->csmreq("password", true);
  125. // 校验验证码
  126. $sendccode = Session::get(CsmadminUtils::getSessionKey($mobile, $event));
  127. if ($sendccode != $ccode) {
  128. $this->error('验证码错误!');
  129. }
  130. $this->_checkRegisterUsername($username);
  131. $this->_checkregistermobile($mobile);
  132. // 新增申请
  133. $param = [
  134. 'applytype' => 'mobile',
  135. 'mobile' => $mobile,
  136. 'username' => $username,
  137. 'nickname' => $nickname,
  138. 'password' => $password
  139. ];
  140. $this->_createApply($this->request, $param);
  141. $config = get_addon_config(CsmContants::$ADDONS);
  142. $is = $config["isregisterneedaudit"];
  143. if($is=='N'){
  144. $this->success('注册成功,请登录。');
  145. }else{
  146. $this->success('注册成功,请等待管理员审核。');
  147. }
  148. }
  149. return $this->view->fetch();
  150. }
  151. public function checkregistermobile()
  152. {
  153. $mobile = $this->csmreq("mobile", true);
  154. $this->_checkregistermobile($mobile);
  155. $this->success("");
  156. }
  157. private function _checkregistermobile($mobile)
  158. {
  159. // 检测手机是否在admin中存在
  160. $service = new AdminService();
  161. $row = $service->getRowByMobile($mobile);
  162. if ($row) {
  163. $this->error(__('手机已注册'));
  164. }
  165. // 检测申请是否存在
  166. $adminapplydao = new \app\admin\model\csmadmin\Adminapply();
  167. $apply = $adminapplydao->where("lower(mobile)", "=", strtolower($mobile))
  168. ->where("auditstatus", "=", "0")
  169. ->find();
  170. if ($apply != null) {
  171. $this->error(__('您的申请待审核中,请耐心等候'));
  172. }
  173. }
  174. private function _checkRegisterUsername($username){
  175. $service = new AdminService();
  176. $row = $service->getRowByUsername($username);
  177. if ($row) {
  178. $this->error(__('用户名已经注册'));
  179. }
  180. }
  181. public function registerbydd()
  182. {
  183. if ($this->request->isPost()) {
  184. $dduserid = $this->csmreq("dduserid", true);
  185. $ddusername = $this->csmreq("ddusername", true);
  186. $nickname = $this->csmreq("nickname", true);
  187. $password = $this->csmreq("password", true);
  188. $this->_checkregisterdd($dduserid);
  189. // 新增申请
  190. $param = [
  191. 'applytype' => 'dd',
  192. 'dduserid' => $dduserid,
  193. 'ddusername' => $ddusername,
  194. 'nickname' => $nickname,
  195. 'password' => $password
  196. ];
  197. $this->_createApply($this->request, $param);
  198. $this->success();
  199. }
  200. return $this->view->fetch();
  201. }
  202. public function checkregisterdd()
  203. {
  204. $dduserid = $this->csmreq("dduserid", true);
  205. $this->_checkregisterdd($dduserid);
  206. $this->success("");
  207. }
  208. private function _checkregisterdd($dduserid)
  209. {
  210. // 检测weixin是否在admin中存在
  211. $service = new AdminService();
  212. $row = $service->getRowByDduserid($dduserid);
  213. if ($row) {
  214. $this->error(__('微信已注册'));
  215. }
  216. // 检测申请是否存在
  217. $adminapplydao = new \app\admin\model\csmadmin\Adminapply();
  218. $apply = $adminapplydao->where("dduserid", "=", $dduserid)
  219. ->where("auditstatus", "=", "0")
  220. ->find();
  221. if ($apply != null) {
  222. $this->error(__('您的申请待审核中,请耐心等候'));
  223. }
  224. }
  225. public function registerbywx()
  226. {
  227. if ($this->request->isPost()) {
  228. $wxuserid = $this->csmreq("wxuserid", true);
  229. $username = $this->csmreq("username", true);
  230. $nickname = $this->csmreq("nickname", true);
  231. $password = $this->csmreq("password", true);
  232. $this->_checkRegisterUsername($username);
  233. $wxuser = WxUtils::getInfoByOpenID($wxuserid);
  234. // $wxusername = $this->csmreq("wxusername", true);
  235. //$nickname = $this->csmreq("nickname", true);
  236. //$password = Random::alpha(6);
  237. $this->_checkregisterwx($wxuserid);
  238. // 新增申请
  239. $param = [
  240. 'applytype' => 'wx',
  241. 'wxuserid' => $wxuserid,
  242. 'wxusername' => $wxuser['nickname'],
  243. 'wxsex' => $wxuser['sex'],
  244. 'wxcountry' => $wxuser['country'],
  245. 'wxprovince' => $wxuser['province'],
  246. 'wxcity' => $wxuser['city'],
  247. 'wxheadimgurl' => $wxuser['headimgurl'],
  248. 'username' => $username,
  249. 'nickname' => $nickname,
  250. 'password' => $password
  251. ];
  252. $this->_createApply($this->request, $param);
  253. $config = get_addon_config(CsmContants::$ADDONS);
  254. $is = $config["isregisterneedaudit"];
  255. if($is=='N'){
  256. $this->success('注册成功,请登录。');
  257. }else{
  258. $this->success('注册成功,请等待管理员审核。');
  259. }
  260. }
  261. return $this->view->fetch();
  262. }
  263. public function checkregisterwx()
  264. {
  265. $wxuserid = $this->csmreq("wxuserid", true);
  266. $this->_checkregisterwx($wxuserid);
  267. $this->success("");
  268. }
  269. private function _checkregisterwx($wxuserid)
  270. {
  271. // 检测weixin是否在admin中存在
  272. $service = new AdminService();
  273. $row = $service->getRowByWx($wxuserid);
  274. if ($row) {
  275. $this->error(__('微信已注册'));
  276. }
  277. // 检测申请是否存在
  278. $adminapplydao = new \app\admin\model\csmadmin\Adminapply();
  279. $apply = $adminapplydao->where("wxuserid", "=", $wxuserid)
  280. ->where("auditstatus", "=", "0")
  281. ->find();
  282. if ($apply != null) {
  283. $this->error(__('您的申请待审核中,请耐心等候'));
  284. }
  285. }
  286. private function _createApply($request, $param)
  287. {
  288. $config = get_addon_config(CsmContants::$ADDONS);
  289. $adminapplydao = new \app\admin\model\csmadmin\Adminapply();
  290. $salt = Random::alnum();
  291. $mipassword = md5(md5($param['password']) . $salt);
  292. $ip = $request->ip();
  293. $oparam = [
  294. "auth_group_ids" => $config["registeradmindefaultroles"],
  295. "password" => $mipassword,
  296. "salt" => $salt,
  297. "applyip" => $ip,
  298. "auditstatus" => "0",
  299. "applytime" => time(),
  300. "createtime" => time()
  301. ];
  302. // 如果安装了csmip插件,则可以显示上次注册的地理位置
  303. $csmip = get_addon_info('csmip');
  304. if ($csmip && $csmip['state']) {
  305. $csmip = \addons\csmip\library\Csmip::getInstance();
  306. $region = $csmip->getRegion($request->ip());
  307. $oparam['applycountry'] = $region->country;
  308. $oparam['applyprovince'] = $region->province;
  309. $oparam['applycity'] = $region->city;
  310. }
  311. $adminapplydao->create(array_merge($param, $oparam));
  312. $id = $adminapplydao->getLastInsID();
  313. $is = $config["isregisterneedaudit"];
  314. if($is=='N'){
  315. CsmadminUtils::createAdminByApply($id, null,false);
  316. }
  317. }
  318. }