Browse Source

追加 匿名注册

彭俊 6 years ago
parent
commit
20cb30a8b4
3 changed files with 51 additions and 1 deletions
  1. 31 0
      app/Http/Controllers/Sys/UserController.php
  2. 0 1
      app/Models/Member.php
  3. 20 0
      public/function.php

+ 31 - 0
app/Http/Controllers/Sys/UserController.php

@@ -5,9 +5,40 @@ namespace App\Http\Controllers\Sys;
 use Illuminate\Http\Request;
 use App\Http\Controllers\Controller;
 use PHPMailer\PHPMailer\Exception;
+use Illuminate\Support\Facades\DB;
+
 
 class UserController extends Controller
 {
+
+    //匿名注册
+    public function hideRegister(){
+        $ip = GETIP();
+
+        //生成随机用户
+        $seed = time();
+        $name = rand(0,$seed);
+        $pwd = '123456';
+        $uuid = getUUID();
+        $userData = [
+            'name' =>'youke_'.$name,
+//            'phone' =>18000000002,
+            'uuid' =>$uuid,
+            'password' =>createPasswd(trim($pwd),$uuid),
+            'status' => 2,
+            'user_ip' =>$ip,
+            'created_at' =>date('Y-m-d H:i:s'),
+            'updated_at' =>date('Y-m-d H:i:s'),
+        ];
+
+        try{
+            $ret = DB::table('members')->insert($userData);
+        }catch(Exception $ex){
+            return toJson(-20001);
+        }
+
+        return toJson(1);
+    }
     public function register(Request $req)
     {
         $user=[];

+ 0 - 1
app/Models/Member.php

@@ -13,5 +13,4 @@ class Member extends Authenticatable
     protected $fillable = ['phone','name','password','avatar','remember_token','uuid'];
     protected $hidden = ['password','remember_token'];
 
-
 }

+ 20 - 0
public/function.php

@@ -88,4 +88,24 @@ function randcode($num=6)
 
 function createPasswd($passwd,$solt){
     return md5(md5($solt.$passwd));
+}
+
+/**
+ * 获取客户端真实IP
+ */
+function GETIP() {
+    global $ip;
+
+    if (getenv("HTTP_CLIENT_IP")) {
+        $ip = getenv("HTTP_CLIENT_IP");
+    } else if (getenv("HTTP_X_FORWARDED_FOR")) {
+        $ip = getenv("HTTP_X_FORWARDED_FOR");
+    } else if (getenv("REMOTE_ADDR")) {
+        $ip = getenv("REMOTE_ADDR");
+    } else {
+        $ip = "Unknow";
+    }
+
+    return $ip;
+
 }