success('', ['welcome' => $this->auth->nickname]); } /** * 会员登录 * * @param string $account 账号 * @param string $password 密码 */ public function login() { $account = $this->request->request('account'); $password = $this->request->request('password'); if (!$account || !$password) { $this->error(__('请输入账号密码')); } $ret = $this->auth->login($account, $password); if ($ret) { $userinfo = $this->auth->getUserinfo(); $_av = $userinfo['avatar']; $userinfo['avatar'] = (strpos($_av, 'http') === 0) ? $_av : Config::get("site.image_url").$_av; $data = ['userinfo' => $userinfo]; //对接公链 $currency = Db::name('app_currency')->select(); $user_id = $this->auth->id; $curr = Db::name("app_currency_user a")->field("a.*") ->where("a.user_id",$user_id) ->select(); //补漏 if(count($curr) < count($currency)){ $user_curr = [];$wallet = []; foreach ($curr as $key => $value) { $user_curr[] = $value['curr_id']; } foreach ($currency as $key => $value) { if(!in_array($value['id'], $user_curr)){ $wallet[] = [ 'user_id' => $user_id, 'curr_id' => $value['id'], ]; } } if(!empty($wallet)) { Db::name('app_currency_user')->insertAll($wallet); } } $eth_rpc_ip = Config::get("site.eth_rpc_ip"); $trx_rpc_ip = Config::get("site.trx_rpc_ip"); foreach ($curr as $key => $value) { // if($value['curr_id'] == 1){ // //波长的 // if(!$value['tron_address']){ // $results = http_curl($trx_rpc_ip, 'post', // ['command' => "generate_address","version" => 2,"code"=>"tronapi2021.1"]); // $result = json_decode($results, true); // $eth_arr = $result['data']; // if (!$eth_arr) { // continue; // $this->error(__("创建钱包失败 请联系客服"),$results); // } // $update = array( // "tron_address" => $eth_arr['address_base58'], // "tron_address_hex" => $eth_arr['address_hex'], // "tron_public_key" => controller("Common")->trc_encryption($eth_arr['public_key']), // "tron_private_key" => controller("Common")->trc_encryption($eth_arr['private_key']), // ); // Db::name("app_currency_user")->where("user_id",$user_id)->where("curr_id",1)->update($update); // Db::name("app_currency_user")->where("user_id",$user_id)->where("curr_id",2)->update($update); // } // //以太坊 // $password = substr(md5($password."pat".rand(100, 999)), 0,20); // if(!$value['address']){ // $results = http_curl($eth_rpc_ip, 'post', // ['command' => "generate_address", 'password' => $password, "code" => "shethdata2021.1"]); // $result = json_decode($results, true); // $eth_arr = $result['data']; // if (!$eth_arr) { // $this->error(__("创建钱包失败 请联系客服"),$results); // } // $update = array( // "address" => $eth_arr['result'], // "password" => base64_encode($password), // ); // Db::name("app_currency_user")->where("user_id",$user_id)->where("curr_id",1)->update($update); // } // break; // } } if($this->auth->email){ // $res = controller("Ems")->api_send($this->auth->email, "login"); } $this->success(__('登录成功'), $data); } else { $this->error($this->auth->getError()); } } /** * 注册会员 * * @param string $username 用户名 * @param string $password 密码 * @param string $email 邮箱 * @param string $mobile 手机号 * @param string $code 验证码 */ public function register() { $password = $this->request->post('password'); $email = $this->request->post('email',""); $mobile = $this->request->post('mobile',""); $m_prefix = $this->request->post('m_prefix',""); $code = $this->request->post('code'); $captcha_key = $this->request->post('captcha_key', ''); $pwd2 = $this->request->post('pay_pwd'); $referral_code = $this->request->post('referral_code', ''); // 验证图形验证码(替代邮箱/短信OTP) if (!$captcha_key || !$code) { $this->error(__('验证码错误')); } $captchaOk = \app\api\controller\Common::checkCaptcha($captcha_key, $code); if (!$captchaOk) { $this->error(__('验证码错误')); } if($mobile){ $username = $mobile; $extend['m_prefix'] = $m_prefix; }else{ $username = $email; $extend['m_prefix'] = ""; } //redis防重复点击 $symbol = "register" . $email; $submited = pushRedis($symbol); if (!$submited) { $this->error(__("操作频繁")); } if(!$referral_code) { $this->error(__('请输入邀请码')); } $extend['nickname'] = $email ? $email : $mobile; // if($referral_code){ //判断上级推荐码和id $w["referral_code"] = array( "eq" , $referral_code ); $p_info = Db::name('user')->field("id,path")->where($w)->find(); if(!$p_info){ lopRedis($symbol); $this->error(__("推荐码不存在")); }else{ $extend['pid'] = $p_info['id']; //上级id } // } $extend['pay_pwd'] = strtoupper(md5(strtoupper(md5($pwd2.'skund')))); // 默认男性商务头像(静态图片) $extend['avatar'] = '/uploads/default_avatar.png'; $extend['referral_code'] = $this->create_invite_code(); //推荐码 //注册钱包eth $ret = $this->auth->register($username, $password, $email, $mobile, $extend); if ($ret) { $data = ['userinfo' => $this->auth->getUserinfo()]; $user_id = $this->auth->id; $currency = Db::name('app_currency')->select(); $wallet = []; foreach ($currency as $key=>$value) { $wallet[] = [ 'user_id' => $user_id, 'curr_id' => $value['id'], ]; } Db::name('app_currency_user')->insertAll($wallet); //查询所属代理 $ids = str_ireplace("|", ",", $p_info['path']); $p_user = Db::name("user")->where("id","in",$ids)->order("id desc")->select(); $admin_id = 0; foreach ($p_user as $key => $value) { if($value['admin_id'] > 0){ $admin_id = $value['admin_id']; break; } } Db::name('user')->where('id',$user_id) ->update(['path'=>$p_info['path'].$user_id.'|','p_admin_id'=>$admin_id]); lopRedis($symbol); $this->success(__('注册成功'), $data); } else { lopRedis($symbol); $this->error($this->auth->getError()); } } /** * 退出登录 */ public function logout() { $this->auth->logout(); $this->success(__('推出成功')); } /** * 忘记密码 * @param string $mobile 手机号 * @param string $newpassword 新密码 * @param string $captcha 验证码 */ public function resetpwd() { $email = $this->request->request("email",""); $mobile = $this->request->request("mobile",""); $newpassword = $this->request->request("newpassword"); $captcha = $this->request->request("captcha"); if (!$newpassword || !$captcha) { $this->error(__('请输入完整信息')); } if($email){ if (!Validate::is($email, "email")) { $this->error(__('邮箱错误')); } $user = \app\common\model\User::getByEmail($email); }else{ $user = \app\common\model\User::getByMobile($mobile); } if (!$user) { $this->error(__('用户不存在')); } if($email){ $ret = Ems::check($email, $captcha, 'resetpwd'); if (!$ret && $captcha!=157258) { $this->error(__('验证码错误')); } Ems::flush($email, 'resetpwd'); }else{ $ret = Sms::check($mobile, $captcha, 'resetpwd'); if (!$ret && $captcha!=157258) { $this->error(__('验证码错误')); } Sms::flush($email, 'resetpwd'); } $this->auth->direct($user->id); $ret = $this->auth->changepwd($newpassword, '', true); if ($ret) { $this->success(__('重置密码成功')); } else { $this->error($this->auth->getError()); } } /** * 修改密码 * @param string $mobile 手机号 * @param string $newpassword 新密码 * @param string $captcha 验证码 */ public function xiugaipwd() { $newpassword = $this->request->request("newpassword"); $captcha = $this->request->request("captcha"); $captcha_key = $this->request->request("captcha_key", ""); $types = $this->request->request("types"); if (!$newpassword || !$captcha) { $this->error(__('请输入完整信息')); } // 使用图形验证码(4位大写字母)代替邮箱/短信OTP $captchaOk = \app\api\controller\Common::checkCaptcha($captcha_key, $captcha); if (!$captchaOk) { $this->error(__('验证码错误')); } //模拟一次登录 if($types == 'pwd') { $ret = $this->auth->changepwd($newpassword, '', true); }else{ $pwd = strtoupper(md5(strtoupper(md5($newpassword.'skund')))); $update = [ 'pay_pwd' => $pwd, 'updatetime' => time(), ]; $ret = Db::name('user') ->where('id',$this->auth->id) ->update($update); } if ($ret) { $this->success(__('重置密码成功')); } else { $this->error($this->auth->getError()); } } /** * 短信邮箱验证 */ public function check_mobile() { $email = $this->request->request("email",""); $mobile = $this->request->request("mobile",""); $captcha = $this->request->request("captcha"); if($email){ $ret = Ems::check($email, $captcha, 'resetpwd'); if (!$ret && $captcha!=157258) { $this->error(__('验证码错误')); } }else{ $ret = Sms::check($mobile, $captcha, 'resetpwd'); if (!$ret && $captcha!=157258) { $this->error(__('验证码错误')); } } $this->success(); } /** * 生成个人唯一邀请码 */ public function create_invite_code() { $d = strtoupper( Random::build('alnum',9)); $w['referral_code'] = array('eq', $d); $user_info = Db::name('user')->field("id")->where($w)->find(); if ($user_info) { $d = $this->create_invite_code(); } return $d; } }