Controller.php 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Services\AccessToken;
  4. use App\Services\CookieService;
  5. use App\Services\UserService;
  6. use Illuminate\Http\Request;
  7. use Illuminate\Support\Facades\Log;
  8. use Laravel\Lumen\Routing\Controller as BaseController;
  9. class Controller extends BaseController
  10. {
  11. protected $userId;
  12. protected $activityId;
  13. protected $corpId;
  14. protected $user;
  15. public function __construct(Request $request)
  16. {
  17. try{
  18. $this->activityId = $request->get("activity_id");
  19. $userData = CookieService::getBsAuthUser();
  20. Log::info($userData);
  21. if ($userData){
  22. $user = UserService::getInstance()->getUser($userData["user_id"]);
  23. if($user){
  24. if($this->activityId==$userData["activity_id"]){
  25. if(AccessToken::getInstance()->getAccessToken($user["user_id"])!=CookieService::getBsAccessToken()){
  26. $accessToken = AccessToken::getInstance()->create($user);
  27. setcookie("bs_access_token", $accessToken,null,"/",env("COOKIE_DOMAIN"));
  28. }
  29. $this->userId = $userData["user_id"];
  30. $this->user = $user;
  31. $this->corpId = $user["corp_id"];
  32. }else{
  33. Log::info("activity_id not correct");
  34. die(json_encode(["error"=>302,"message"=>config("errMsg.not_oauth"),"redirect"=>env("WEB_URL")."/frontend?activity_id=".$this->activityId]));
  35. }
  36. }else{
  37. Log::info("user not found");
  38. die(json_encode(["error"=>302,"message"=>config("errMsg.not_oauth"),"redirect"=>env("WEB_URL")."/frontend?activity_id=".$this->activityId]));
  39. }
  40. }else{
  41. Log::info("not auth");
  42. die(json_encode(["error"=>302,"message"=>config("errMsg.not_oauth"),"redirect"=>env("WEB_URL")."/frontend?activity_id=".$this->activityId]));
  43. }
  44. }catch (\Exception $exception){
  45. Log::info($exception->getTraceAsString());
  46. die(json_encode(["error"=>302,"message"=>config("errMsg.not_oauth"),"redirect"=>env("WEB_URL")."/frontend?activity_id=".$this->activityId]));
  47. }
  48. }
  49. }