AuthController.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. namespace App\Http\Controllers\Auth;
  3. use App\Http\Controllers\Controller;
  4. use Illuminate\Http\Request;
  5. use App\Models\Login\AccountInfo;
  6. use App\Models\Login\GameVersion;
  7. use Response;
  8. use GuzzleHttp\Client;
  9. class AuthController extends Controller
  10. {
  11. public function LoginAccountActionPost(Request $request)
  12. {
  13. $validator = \Validator::make($request->all(), [
  14. 'Username' => 'required',
  15. 'Password' => 'required'
  16. ], [], [
  17. 'Username' => '',
  18. 'Password' => ''
  19. ]);
  20. if(!$validator->passes())
  21. return response()->json(['code' => -1, 'msg' => $validator->errors()->first() ], 400);
  22. $AccountInfo = AccountInfo::LoginAccount($request);
  23. return response()->json($AccountInfo, 200);
  24. }
  25. public function RegisterAccountActionPost(Request $request)
  26. {
  27. $request['UUID'] = vsprintf('%s%s-%s-4000-8%.3s-%s%s%s0',str_split(dechex( microtime(true) * 1000 ) . bin2hex( random_bytes(8) ),4));
  28. $validator = \Validator::make($request->all(), [
  29. 'Username' => 'required|min:5|max:30|unique:Login.AccountInfo,Username',
  30. 'Password' => 'required|min:5|max:30'
  31. ], [], [
  32. 'Username' => 'Nome de usuário',
  33. 'Password' => 'Senha'
  34. ]);
  35. if(!$validator->passes())
  36. return response()->json(['code' => -1, 'msg' => $validator->errors() ], 400);
  37. $saveAcc = AccountInfo::CreateAccount($request);
  38. if ($saveAcc == 0)
  39. return Response::json( ['code' => 0, 'msg' => 'Sucesso!' ] ,200 );
  40. dd($request);
  41. return Response::json( ['code' => -3, 'msg' => 'Falha ao criar a conta!' ] ,400 );
  42. }
  43. public function LoginAccountCheck(Request $request)
  44. {
  45. $client = new Client([
  46. 'verify' => false
  47. ]);
  48. return $client->request('get', 'http://192.168.1.73:8000/api/login', ['query' => $request->all()])->getBody()->getContents();
  49. $xml = 'null';
  50. if(isset($request['keyVal1']))
  51. $Account = AccountInfo::where('UUID', $request['keyVal1'])->first();
  52. if($Account){
  53. if($Account->Real_CERPass != $request['keyVal2'])
  54. return response()->xml($xml, $status = 400, $headers = [], $xmlRoot = 'root', $encoding = null);
  55. if($Account->IsBlocked == 1)
  56. return response()->xml($xml, $status = 400, $headers = [], $xmlRoot = 'root', $encoding = null);
  57. $xml = '<root>' .
  58. '<getParamInfo>' .
  59. '<keyVal1 value="' . $Account->UUID . '"/>' .
  60. '<keyVal2 value="'. $Account->Real_CERPass .'"/>' .
  61. '<m value="P"/>' .
  62. '</getParamInfo>' .
  63. '<getResultInfo>' .
  64. '<result value="101"/>' .
  65. '<resultMsg value="e"/>' .
  66. '<LoginID value="' . $Account->Username . '"/>' .
  67. '<Permission value="' . $Account->Permission . '"/>' .
  68. '<UserAge value="20"/>' .
  69. '<MakeCodeNo value="' . $Account->MakeCodeNo . '"/>' .
  70. '<UserType value="0"/>' .
  71. '<StateDetail value="0"/>' .
  72. '<PCRoomType value="1"/>' .
  73. '<PCRoomID value="1"/>' .
  74. '<UIDSEQ value="' . $Account->AccountDBID . '"/>' .
  75. '</getResultInfo>' .
  76. '</root>';
  77. //AccountInfo::UpdateUUID($Account->UUID);
  78. }
  79. return response()->xml($xml, $status = 200, $headers = [], $xmlRoot = '', $encoding = null);
  80. }
  81. }