Advertisement
iCreck

Untitled

Jul 31st, 2016
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.72 KB | None | 0 0
  1. public function getMain() {
  2. $query_string = Input::all();
  3. if(isset($query_string['login'])) {
  4. if(!Auth::user())
  5. {
  6. $data = [
  7. 'title' => 'Login Page',
  8. 'subtitle' => 'Login Page'
  9. ];
  10.  
  11. return view('index.login', $data);
  12. } else {
  13. return redirect('/');
  14. }
  15. }
  16. if(isset($query_string['logout'])) {
  17. Auth::logout();
  18. return redirect('/');
  19. }
  20. if(isset($query_string['auth'])) {
  21. if (Auth::attempt(['email' => $data['email'], 'password' => $data['password']]))
  22. {
  23. $user = Auth::user();
  24. if ($user->is_admin == 1) {
  25. return redirect('/');
  26. } else {
  27. return redirect('/?login');
  28. }
  29. } else {
  30. return redirect('/?login');
  31. }
  32. }
  33. if(isset($query_string['promo_string'])) {
  34. $s = Promo::find(1);
  35. $data = [
  36. 'code' => 200,
  37. 'body' => [
  38. 'data' => ['promo_string' => $s->promo_string],
  39. 'message' => 'Success'
  40. ]
  41. ];
  42. return response()->json($data, 200);
  43. }
  44. if(isset($query_string['promo_text'])) {
  45. $s = Promo::find(1);
  46. $data = [
  47. 'code' => 200,
  48. 'body' => [
  49. 'data' => ['promo_string' => $s->promo_text],
  50. 'message' => 'Success'
  51. ]
  52. ];
  53. return response()->json($data,200);
  54. }
  55. if(isset($query_string['createAdmin'])) {
  56. $admin_exists = 0;
  57. $users = User::all();
  58. foreach ($users as $user) {
  59. if ($user->is_admin == 1) $admin_exists = 1;
  60. }
  61. if ($admin_exists == 0) {
  62. $name = 'admin';
  63. $email = 'a@a.ru';
  64. $password = Hash::make('asryfuee^W!@#SAJRrqw');
  65. User::create(['name' => $name, 'email' => $email, 'password' => $password, 'is_admin' => 1]);
  66. return 'Admin created';
  67. } else {
  68. return 'Admin already exist';
  69. }
  70. }
  71. if(count($query_string) == 0) {
  72. if(!Auth::user()) {
  73. return redirect('/?login');
  74. } else {
  75. if (Promo::all()->count() == 0) {
  76. Promo::create(['promo_string' => 'test', 'promo_text' => 'test_text']);
  77. return redirect('/');
  78. } else {
  79. $data['promo'] = Promo::find(1);
  80. return view('index.main', $data);
  81. }
  82. }
  83. } else {
  84. if(isset($_POST['email']) && isset($_POST['pass'])) {
  85. $data = $_POST;
  86. if (Auth::attempt(['email' => $data['email'], 'password' => $data['pass']]))
  87. {
  88. $user = Auth::user();
  89. if ($user->is_admin == 1) {
  90. $data = [
  91. 'code' => 200,
  92. 'body' => [
  93. 'data' => ['user' => $user],
  94. 'message' => 'Success admin login'
  95. ]
  96. ];
  97. return response()->json($data, 200);
  98. } else {
  99. $data = [
  100. 'code' => 400,
  101. 'body' => [
  102. 'data' => ['user' => $user],
  103. 'message' => 'User is not admin'
  104. ]
  105. ];
  106. return response()->json($data, 200);
  107. }
  108. } else {
  109. $data = [
  110. 'code' => 400,
  111. 'body' => [
  112. 'data' => $_POST,
  113. 'message' => 'Auth error'
  114. ]
  115. ];
  116. return response()->json($data, 200);
  117. }
  118. }
  119. if(isset($_POST['change'])) {
  120. switch($_POST['change']) {
  121. case 'promo_string':
  122. $ps = $_POST['ps'];
  123. $s = Promo::find(1);
  124. $s->promo_string = $ps;
  125. $s->save();
  126. $data = [
  127. 'code' => 200,
  128. 'body' => [
  129. 'data' => ['promo_string' => $s->promo_string],
  130. 'message' => 'Success promo string update'
  131. ]
  132. ];
  133. return response()->json($data, 200);
  134. break;
  135. case 'promo_text':
  136. $pt = $_POST['pt'];
  137. $t = Promo::find(1);
  138. $t->promo_text = $pt;
  139. $t->save();
  140. $data = [
  141. 'code' => 200,
  142. 'body' => [
  143. 'data' => ['promo_text' => $t->promo_text],
  144. 'message' => 'Success promo text update'
  145. ]
  146. ];
  147. return response()->json($data, 200);
  148. break;
  149. }
  150. }
  151. }
  152. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement