Browse Source

Merge pull request #2040 from visuddhinanda/laravel

添加注册支持
visuddhinanda 2 years ago
parent
commit
cc5276bab5

+ 3 - 0
app/Http/Api/StudioApi.php

@@ -37,6 +37,9 @@ class StudioApi{
             'realName'=>$userInfo->username,
             'realName'=>$userInfo->username,
             'studioName'=>$userInfo->username,
             'studioName'=>$userInfo->username,
         ];
         ];
+        if(!empty($userInfo->role)){
+            $data['roles'] = json_decode($userInfo->role);
+        }
         if($userInfo->avatar){
         if($userInfo->avatar){
             $img = str_replace('.jpg','_s.jpg',$userInfo->avatar);
             $img = str_replace('.jpg','_s.jpg',$userInfo->avatar);
             if (App::environment('local')) {
             if (App::environment('local')) {

+ 3 - 0
app/Http/Api/UserApi.php

@@ -48,6 +48,9 @@ class UserApi{
                 'userName'=>$user['username'],
                 'userName'=>$user['username'],
                 'realName'=>$user['username'],
                 'realName'=>$user['username'],
             ];
             ];
+            if(!empty($user->role)){
+                $data['roles'] = json_decode($user->role);
+            }
             if($user->avatar){
             if($user->avatar){
                 $img = str_replace('.jpg','_s.jpg',$user->avatar);
                 $img = str_replace('.jpg','_s.jpg',$user->avatar);
                 if (App::environment('local')) {
                 if (App::environment('local')) {

+ 8 - 1
app/Http/Controllers/ChannelController.php

@@ -500,9 +500,11 @@ class ChannelController extends Controller
             return $this->error(__('auth.failed'),401,401);
             return $this->error(__('auth.failed'),401,401);
         }
         }
         //判断当前用户是否有指定的studio的权限
         //判断当前用户是否有指定的studio的权限
-        if($user['user_uid'] !== StudioApi::getIdByName($request->get('studio'))){
+        $studioId = StudioApi::getIdByName($request->get('studio'));
+        if($user['user_uid'] !== $studioId){
             return $this->error(__('auth.failed'),403,403);
             return $this->error(__('auth.failed'),403,403);
         }
         }
+        $studio = StudioApi::getById($studioId);
         //查询是否重复
         //查询是否重复
         if(Channel::where('name',$request->get('name'))
         if(Channel::where('name',$request->get('name'))
                   ->where('owner_uid',$user['user_uid'])
                   ->where('owner_uid',$user['user_uid'])
@@ -517,6 +519,11 @@ class ChannelController extends Controller
         $channel->type = $request->get('type');
         $channel->type = $request->get('type');
         $channel->lang = $request->get('lang');
         $channel->lang = $request->get('lang');
         $channel->editor_id = $user['user_id'];
         $channel->editor_id = $user['user_id'];
+        if(isset($studio['roles'])){
+            if(in_array('basic',$studio['roles'])){
+                $channel->status = 5;
+            }
+        }
         $channel->create_time = time()*1000;
         $channel->create_time = time()*1000;
         $channel->modify_time = time()*1000;
         $channel->modify_time = time()*1000;
         $channel->save();
         $channel->save();

+ 1 - 1
app/Http/Controllers/Controller.php

@@ -38,7 +38,7 @@ class Controller extends BaseController
 		return response()->json($response,$code);
 		return response()->json($response,$code);
 	}
 	}
 
 
-    public function error($error, $errorMessages=[], $code=404){
+    public function error($error, $errorMessages='', $code=404){
         return $this->sendError($error, $errorMessages, $code);
         return $this->sendError($error, $errorMessages, $code);
     }
     }
 }
 }

+ 30 - 13
app/Http/Controllers/InviteController.php

@@ -6,6 +6,7 @@ use App\Models\Invite;
 use App\Models\UserInfo;
 use App\Models\UserInfo;
 use Illuminate\Http\Request;
 use Illuminate\Http\Request;
 use App\Http\Api\AuthApi;
 use App\Http\Api\AuthApi;
+use App\Http\Api\UserApi;
 use App\Http\Api\StudioApi;
 use App\Http\Api\StudioApi;
 use App\Http\Resources\InviteResource;
 use App\Http\Resources\InviteResource;
 use Illuminate\Support\Str;
 use Illuminate\Support\Str;
@@ -22,12 +23,15 @@ class InviteController extends Controller
     public function index(Request $request)
     public function index(Request $request)
     {
     {
         //
         //
+        $user = AuthApi::current($request);
+        if(!$user){
+            return $this->error(__('auth.failed'));
+        }
         $table = Invite::select(['id','user_uid','email',
         $table = Invite::select(['id','user_uid','email',
                                  'status','created_at','updated_at']);
                                  'status','created_at','updated_at']);
         switch ($request->get('view')) {
         switch ($request->get('view')) {
             case 'studio':
             case 'studio':
-                $user = AuthApi::current($request);
-                if(!$user){
+                if(empty($request->get('studio'))){
                     return $this->error(__('auth.failed'));
                     return $this->error(__('auth.failed'));
                 }
                 }
                 //判断当前用户是否有指定的studio的权限
                 //判断当前用户是否有指定的studio的权限
@@ -36,6 +40,12 @@ class InviteController extends Controller
                 }
                 }
                 $table = $table->where('user_uid', $user["user_uid"]);
                 $table = $table->where('user_uid', $user["user_uid"]);
                 break;
                 break;
+            case 'all':
+                $user = UserApi::getByUuid($user['user_uid']);
+                if(!$user || !isset($user['roles']) || !in_array('administrator',$user['roles']) ){
+                    return $this->error(__('auth.failed'));
+                }
+                break;
         }
         }
         if($request->has('search')){
         if($request->has('search')){
             $table = $table->where('email', 'like', '%'.$request->get('search')."%");
             $table = $table->where('email', 'like', '%'.$request->get('search')."%");
@@ -60,31 +70,38 @@ class InviteController extends Controller
     public function store(Request $request)
     public function store(Request $request)
     {
     {
         //
         //
-        $user = AuthApi::current($request);
-        if(!$user){
-            return $this->error(__('auth.failed'));
-        }
-        //判断当前用户是否有指定的studio的权限
-        $studio_id = StudioApi::getIdByName($request->get('studio'));
-        if($user['user_uid'] !== $studio_id){
-            return $this->error(__('auth.failed'));
+        $sender = '';
+        if(!empty($request->get('studio'))){
+            $user = AuthApi::current($request);
+            if(!$user){
+                return $this->error(__('auth.failed'),401,401);
+            }
+            //判断当前用户是否有指定的studio的权限
+            $studio_id = StudioApi::getIdByName($request->get('studio'));
+            if($user['user_uid'] !== $studio_id){
+                return $this->error(__('auth.failed'));
+            }
+            $sender = $studio_id;
+        }else{
+            $sender = config("mint.admin.root_uuid");
         }
         }
+
         //查询是否重复
         //查询是否重复
         if(Invite::where('email',$request->get('email'))->exists() ||
         if(Invite::where('email',$request->get('email'))->exists() ||
             UserInfo::where('email',$request->get('email'))->exists()){
             UserInfo::where('email',$request->get('email'))->exists()){
-            return $this->error(__('validation.exists',['email']),[],200);
+            return $this->error('email.exists',__('validation.exists',['email']),200);
         }
         }
 
 
         $uuid = Str::uuid();
         $uuid = Str::uuid();
         Mail::to($request->get('email'))
         Mail::to($request->get('email'))
             ->send(new InviteMail($uuid,$request->get('lang'),$request->get('dashboard')));
             ->send(new InviteMail($uuid,$request->get('lang'),$request->get('dashboard')));
         if(Mail::failures()){
         if(Mail::failures()){
-            return $this->error('send email fail',[],200);
+            return $this->error('send email fail', '',200);
         }else{
         }else{
             $invite = new Invite;
             $invite = new Invite;
             $invite->id = $uuid;
             $invite->id = $uuid;
             $invite->email = $request->get('email');
             $invite->email = $request->get('email');
-            $invite->user_uid = $user['user_uid'];
+            $invite->user_uid = $sender;
             $invite->status = 'invited';
             $invite->status = 'invited';
             $invite->save();
             $invite->save();
         }
         }

+ 4 - 0
app/Http/Controllers/PageIndexController.php

@@ -28,6 +28,10 @@ class PageIndexController extends Controller
                     'title'=>'文集',
                     'title'=>'文集',
                     'link'=>config('mint.server.dashboard_base_path').'/anthology/list',
                     'link'=>config('mint.server.dashboard_base_path').'/anthology/list',
                 ],
                 ],
+                [
+                    'title'=>'注册/登录',
+                    'link'=>config('mint.server.dashboard_base_path').'/anonymous/users/sign-in',
+                ],
             ];
             ];
         $wish = [
         $wish = [
             [
             [

+ 48 - 40
app/Http/Controllers/SignUpController.php

@@ -6,8 +6,9 @@ use App\Models\UserInfo;
 use App\Models\Invite;
 use App\Models\Invite;
 use App\Models\Channel;
 use App\Models\Channel;
 use Illuminate\Support\Str;
 use Illuminate\Support\Str;
-
+use Illuminate\Support\Facades\DB;
 use Illuminate\Http\Request;
 use Illuminate\Http\Request;
+use Illuminate\Support\Facades\Log;
 
 
 class SignUpController extends Controller
 class SignUpController extends Controller
 {
 {
@@ -32,60 +33,67 @@ class SignUpController extends Controller
         //先查询invite核对uuid
         //先查询invite核对uuid
         if(!Invite::where('id',$request->get('token'))
         if(!Invite::where('id',$request->get('token'))
                   ->where('email',$request->get('email'))->exists()){
                   ->where('email',$request->get('email'))->exists()){
-            $this->error('error token',[],200);
+            $this->error('error token','',200);
         }
         }
         if(UserInfo::where('username',$request->get('name'))->exists()){
         if(UserInfo::where('username',$request->get('name'))->exists()){
-            $this->error('avoid user name',[],200);
+            $this->error('avoid user name','',200);
         }
         }
-        $user = new UserInfo;
-        $user->userid = Str::Uuid();
-        $user->username = $request->get('username');
-        $user->nickname = $request->get('nickname');
-        $user->email = $request->get('email');
-        $user->password = md5($request->get('password'));
-        $user->create_time = time()*1000;
-        $user->modify_time = time()*1000;
-        $user->save();
 
 
-        //标记invite
-        Invite::where('id',$request->get('token'))
-                  ->where('email',$request->get('email'))
-                  ->update(['status'=>'sign-up']);
-        //建立channel
-        $channel = new Channel;
-        $channel->id = app('snowflake')->id();
-        $channel->name = $request->get('username');
-        $channel->owner_uid = $user->userid;
-        $channel->type = "translation";
-        $channel->lang = $request->get('lang');
-        $channel->editor_id = $user->id;
-        $channel->status = 30;
-        $channel->create_time = time()*1000;
-        $channel->modify_time = time()*1000;
-        $channel->save();
+        try {
+            DB::transaction(function() use($request){
+                $user = new UserInfo;
+                $user->userid = Str::Uuid();
+                $user->username = $request->get('username');
+                $user->nickname = $request->get('nickname');
+                $user->email = $request->get('email');
+                $user->password = md5($request->get('password'));
+                $user->role = json_encode(['basic']);
+                $user->create_time = time()*1000;
+                $user->modify_time = time()*1000;
+                $user->save();
+
+                //标记invite
+                Invite::where('id',$request->get('token'))
+                        ->where('email',$request->get('email'))
+                        ->update(['status'=>'sign-up']);
+                //建立channel
 
 
-        $channel_draft = new Channel;
-        $channel_draft->id = app('snowflake')->id();
-        $channel_draft->name = 'draft';
-        $channel_draft->owner_uid = $user->userid;
-        $channel_draft->type = "translation";
-        $channel_draft->lang = $request->get('lang');
-        $channel_draft->editor_id = $user->id;
-        $channel_draft->create_time = time()*1000;
-        $channel_draft->modify_time = time()*1000;
-        $channel_draft->save();
+                $channel_draft = new Channel;
+                $channel_draft->id = app('snowflake')->id();
+                $channel_draft->name = 'draft';
+                $channel_draft->owner_uid = $user->userid;
+                $channel_draft->type = "translation";
+                $channel_draft->lang = $request->get('lang');
+                $channel_draft->status = 5;
+                $channel_draft->editor_id = $user->id;
+                $channel_draft->create_time = time()*1000;
+                $channel_draft->modify_time = time()*1000;
+                $channel_draft->save();
+            });
+        }catch(\Exception $e) {
+            Log::error('user create fail',['data'=>$e]);
+            return $this->error('user create fail',500,500);
+        }
         return $this->ok('ok');
         return $this->ok('ok');
     }
     }
 
 
     /**
     /**
      * Display the specified resource.
      * Display the specified resource.
      *
      *
-     * @param  \App\Models\UserInfo  $userInfo
+     * @param  string $username
      * @return \Illuminate\Http\Response
      * @return \Illuminate\Http\Response
      */
      */
-    public function show(UserInfo $userInfo)
+    public function show(Request $request,string $username)
     {
     {
         //
         //
+        $email = UserInfo::where('email',$request->get('email'))->exists();
+        $user = UserInfo::where('username',$username)->exists();
+        if($email && $user){
+            //send email
+            return $this->ok('ok');
+        }else{
+            return $this->error(['email'=>$email,'username'=>$user],[200],200);
+        }
     }
     }
 
 
     /**
     /**

+ 7 - 0
app/Http/Resources/CourseMemberResource.php

@@ -4,6 +4,7 @@ namespace App\Http\Resources;
 
 
 use Illuminate\Http\Resources\Json\JsonResource;
 use Illuminate\Http\Resources\Json\JsonResource;
 use App\Http\Api\UserApi;
 use App\Http\Api\UserApi;
+use App\Http\Api\ChannelApi;
 
 
 class CourseMemberResource extends JsonResource
 class CourseMemberResource extends JsonResource
 {
 {
@@ -27,6 +28,12 @@ class CourseMemberResource extends JsonResource
             "created_at"=> $this->created_at,
             "created_at"=> $this->created_at,
             "updated_at"=> $this->updated_at,
             "updated_at"=> $this->updated_at,
         ];
         ];
+        if($this->channel_id){
+            $channel = ChannelApi::getById($this->channel_id);
+            if($channel){
+               $data['channel'] =  $channel;
+            }
+        }
         return $data;
         return $data;
     }
     }
 }
 }

+ 5 - 5
resources/views/typhoon.blade.php

@@ -82,10 +82,7 @@ notification
         d="M1.532,37.339A1.531,1.531,0,0,1,0,35.808V1.532a1.532,1.532,0,0,1,3.064,0V35.809A1.533,1.533,0,0,1,1.532,37.339Z"
         d="M1.532,37.339A1.531,1.531,0,0,1,0,35.808V1.532a1.532,1.532,0,0,1,3.064,0V35.809A1.533,1.533,0,0,1,1.532,37.339Z"
         fill="#f1ca23" />
         fill="#f1ca23" />
     </g>
     </g>
-    <text id="studio" transform="translate(542 353.2)" fill="#fff" font-size="24"
-      font-family="NotoSans-ExtraLight, Noto Sans" font-weight="200">
-      <tspan x="0" y="0">Library</tspan>
-    </text>
+
   </g>
   </g>
 </svg>
 </svg>
 
 
@@ -102,10 +99,13 @@ notification
 </div>
 </div>
 </li>
 </li>
 @endforeach
 @endforeach
+
 <li class="flex ml-4 text-sm relative inline-flex items-center pt-1 border-b-2 font-medium leading-5 transition duration-150 ease-in-out  border-transparent text-gray-400 hover:text-primary hover:border-primary focus:outline-none focus:text-primary focus:border-gray-300  ">
 <li class="flex ml-4 text-sm relative inline-flex items-center pt-1 border-b-2 font-medium leading-5 transition duration-150 ease-in-out  border-transparent text-gray-400 hover:text-primary hover:border-primary focus:outline-none focus:text-primary focus:border-gray-300  ">
 <div class="flex w-full h-full">
 <div class="flex w-full h-full">
 <a class="w-full flex items-center h-full px-3" href="#contact">联络我们</a>
 <a class="w-full flex items-center h-full px-3" href="#contact">联络我们</a>
-</div> </li>
+</div>
+
+</li>
 </ul>
 </ul>
 </div>
 </div>
 </nav>
 </nav>