Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function getMain() {
- $query_string = Input::all();
- if(isset($query_string['login'])) {
- if(!Auth::user())
- {
- $data = [
- 'title' => 'Login Page',
- 'subtitle' => 'Login Page'
- ];
- return view('index.login', $data);
- } else {
- return redirect('/');
- }
- }
- if(isset($query_string['logout'])) {
- Auth::logout();
- return redirect('/');
- }
- if(isset($query_string['auth'])) {
- if (Auth::attempt(['email' => $data['email'], 'password' => $data['password']]))
- {
- $user = Auth::user();
- if ($user->is_admin == 1) {
- return redirect('/');
- } else {
- return redirect('/?login');
- }
- } else {
- return redirect('/?login');
- }
- }
- if(isset($query_string['promo_string'])) {
- $s = Promo::find(1);
- $data = [
- 'code' => 200,
- 'body' => [
- 'data' => ['promo_string' => $s->promo_string],
- 'message' => 'Success'
- ]
- ];
- return response()->json($data, 200);
- }
- if(isset($query_string['promo_text'])) {
- $s = Promo::find(1);
- $data = [
- 'code' => 200,
- 'body' => [
- 'data' => ['promo_string' => $s->promo_text],
- 'message' => 'Success'
- ]
- ];
- return response()->json($data,200);
- }
- if(isset($query_string['createAdmin'])) {
- $admin_exists = 0;
- $users = User::all();
- foreach ($users as $user) {
- if ($user->is_admin == 1) $admin_exists = 1;
- }
- if ($admin_exists == 0) {
- $name = 'admin';
- $email = 'a@a.ru';
- $password = Hash::make('asryfuee^W!@#SAJRrqw');
- User::create(['name' => $name, 'email' => $email, 'password' => $password, 'is_admin' => 1]);
- return 'Admin created';
- } else {
- return 'Admin already exist';
- }
- }
- if(count($query_string) == 0) {
- if(!Auth::user()) {
- return redirect('/?login');
- } else {
- if (Promo::all()->count() == 0) {
- Promo::create(['promo_string' => 'test', 'promo_text' => 'test_text']);
- return redirect('/');
- } else {
- $data['promo'] = Promo::find(1);
- return view('index.main', $data);
- }
- }
- } else {
- if(isset($_POST['email']) && isset($_POST['pass'])) {
- $data = $_POST;
- if (Auth::attempt(['email' => $data['email'], 'password' => $data['pass']]))
- {
- $user = Auth::user();
- if ($user->is_admin == 1) {
- $data = [
- 'code' => 200,
- 'body' => [
- 'data' => ['user' => $user],
- 'message' => 'Success admin login'
- ]
- ];
- return response()->json($data, 200);
- } else {
- $data = [
- 'code' => 400,
- 'body' => [
- 'data' => ['user' => $user],
- 'message' => 'User is not admin'
- ]
- ];
- return response()->json($data, 200);
- }
- } else {
- $data = [
- 'code' => 400,
- 'body' => [
- 'data' => $_POST,
- 'message' => 'Auth error'
- ]
- ];
- return response()->json($data, 200);
- }
- }
- if(isset($_POST['change'])) {
- switch($_POST['change']) {
- case 'promo_string':
- $ps = $_POST['ps'];
- $s = Promo::find(1);
- $s->promo_string = $ps;
- $s->save();
- $data = [
- 'code' => 200,
- 'body' => [
- 'data' => ['promo_string' => $s->promo_string],
- 'message' => 'Success promo string update'
- ]
- ];
- return response()->json($data, 200);
- break;
- case 'promo_text':
- $pt = $_POST['pt'];
- $t = Promo::find(1);
- $t->promo_text = $pt;
- $t->save();
- $data = [
- 'code' => 200,
- 'body' => [
- 'data' => ['promo_text' => $t->promo_text],
- 'message' => 'Success promo text update'
- ]
- ];
- return response()->json($data, 200);
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement