AB преди 5 години
родител
ревизия
3dfafc1ed0

+ 8 - 0
app/Http/Controllers/HomeController.php

@@ -25,4 +25,12 @@ class HomeController extends Controller
     {
         return view('home');
     }
+     public function needauth()
+    {
+        return view('needauth');
+    }
+    public function authneed()
+    {
+        return view('authneed');
+    }
 }

+ 63 - 1
app/Http/Controllers/PostsController.php

@@ -3,11 +3,40 @@
 namespace App\Http\Controllers;
 
 use Illuminate\Http\Request;
+use Illuminate\Foundation\Auth;
+use App\Services\moneyService;
+use Illuminate\Support\Facades\Validator;
 
 class PostsController extends Controller
 {
-    public function index()
+    public function index(Request $request)
     {
+    	 $validatedData = $request->validate([
+            'email' => 'required|email',
+            'num' => 'required|numeric'
+        ]);
+    	session()->flash('status', 'Thanks for funding your acc!');
+    	if (auth()->check()) {
+	    	$bank= new \App\bank;
+	    	$vs=$bank::where('user_id', auth()->user()->id)->count();
+	    	if($vs==0){
+		    	$bank->user_id=auth()->user()->id;
+		    	$bank->money=$request->num;
+		    	$bank->email=$request->email;
+		    	$bank->save();
+	    	}
+	    	else{
+	    		$mon=$request->num;
+	    		$cal=\App\bank::where('user_id', auth()->user()->id)->get('money');
+	    		$res = json_decode($cal, true);
+	    		$upd=$res[0]['money'];
+	    		$bank::where('user_id', auth()->user()->id)->update(['money' => $upd+$mon]);
+	    	}
+	    }
+    	return view('posts.index');
+    }
+
+    public function indexx(){
     	return view('posts.index');
     }
 
@@ -15,4 +44,37 @@ class PostsController extends Controller
     {
     	return view('posts.daily');
     }
+
+   public function casino(){
+   	return view('posts.casino');
+   }
+
+   public function post_casino(Request $request){
+   	$validator = Validator::make($request->all(), [
+            'num' => 'required|numeric'
+        ]);
+   	if ($validator->fails()) {
+            return redirect('casino')
+                        ->withErrors($validator)
+                        ->withInput();
+        }
+   	$mon = $request->num;
+   	$cal=\App\bank::where('user_id', auth()->user()->id)->get('money');
+	$res = json_decode($cal, true);
+	$upd=$res[0]['money'];
+	if($mon>$upd){
+			echo "You dont have enough money!";
+			$validator->errors()->add('num', 'You dont have enough money!');
+		}	
+	else{
+		$bank= new \App\bank;
+		$bank::where('user_id', auth()->user()->id)->update(['money' => $upd-$mon]);
+	   	$mS=new moneyService;
+	   	$newmon=$mS->multiply2($mon);
+	   	$bank::where('user_id', auth()->user()->id)->update(['money' => $upd-$mon+$newmon]);
+	   	return view('posts.casino', 
+	   		['mon'=>$mon,
+	   		 'newmon'=>$newmon]);
+	   }
+   }
 }

+ 19 - 0
app/Services/moneyService.php

@@ -0,0 +1,19 @@
+<?php
+
+namespace App\Services;
+
+use Illuminate\Support\Str;
+
+class moneyService
+{
+    public function multiply2($money){
+        $random =  rand(1, 10);
+        if($random % 2 == 0){
+            $money=$money*2;
+        }
+        else{
+            $money=0;
+        }
+        return $money;
+    }
+}

+ 10 - 0
app/bank.php

@@ -0,0 +1,10 @@
+<?php
+
+namespace App;
+
+use Illuminate\Database\Eloquent\Model;
+
+class bank extends Model
+{
+    protected $table = 'bank';
+}

+ 1 - 1
database/migrations/2014_10_12_000000_create_users_table.php

@@ -11,7 +11,7 @@ class CreateUsersTable extends Migration
      *
      * @return void
      */
-    public function up()
+    public function up()        
     {
         Schema::create('users', function (Blueprint $table) {
             $table->bigIncrements('id');

+ 34 - 0
database/migrations/2019_12_19_103617_moneybank.php

@@ -0,0 +1,34 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class Moneybank extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+         Schema::create('bank', function (Blueprint $table) {
+            $table->bigIncrements('id');
+            $table->integer('user_id');
+            $table->string('email');
+            $table->integer('money');
+            $table->timestamps();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('bank');
+    }
+}

+ 19 - 0
public/css/app.css

@@ -1120,6 +1120,12 @@ pre code {
     max-width: 33.3333333333%;
   }
 
+  .mycol-md-4{
+    margin-left: 35%;
+    flex: 0 0 33.3333333333%;
+    max-width: 33.3333333333%;
+  }
+
   .col-md-5 {
     flex: 0 0 41.6666666667%;
     max-width: 41.6666666667%;
@@ -1301,6 +1307,12 @@ pre code {
     flex: 0 0 33.3333333333%;
     max-width: 33.3333333333%;
   }
+  .mycol-lg-4 {
+
+    margin-left: 8%;
+    flex: 0 0 41.6666666667%;
+    max-width: 41.6666666667%;
+  }
 
   .col-lg-5 {
     flex: 0 0 41.6666666667%;
@@ -5535,6 +5547,13 @@ a.badge-dark.focus {
   margin-bottom: 0;
 }
 
+.my_flash{
+  position: absolute;
+  bottom: 20px;
+  right: 20px;
+  sz-index: 10;
+}
+
 .list-group-item-action {
   width: 100%;
   color: #495057;

+ 11 - 0
public/css/form-validation.css

@@ -0,0 +1,11 @@
+.container {
+    max-width: 960px;
+  }
+  
+  .border-top { border-top: 1px solid #e5e5e5; }
+  .border-bottom { border-bottom: 1px solid #e5e5e5; }
+  .border-top-gray { border-top-color: #adb5bd; }
+  
+  .box-shadow { box-shadow: 0 .25rem .75rem rgba(0, 0, 0, .05); }
+  
+  .lh-condensed { line-height: 1.25; }

+ 28 - 0
resources/views/authneed.blade.php

@@ -0,0 +1,28 @@
+@extends('layouts.app')
+
+@section('content1')
+<div style="margin-top: 6rem;">
+<div class="container">
+    <div class="row justify-content-center">
+        <div class="col-md-8">
+            <div class="card">
+                <div class="card-header">Dashboard</div>
+
+                <div class="card-body">
+                    @if (session('status'))
+                        <div class="alert alert-success" role="alert">
+                            {{ session('status') }}
+                        </div>
+                    @endif
+
+                    You are logged in!
+                </div>
+            </div>
+        </div>
+    </div>
+</div>
+</div>
+<?php
+header("refresh: 1; url=/casino");
+?>
+@endsection

+ 1 - 1
resources/views/home.blade.php

@@ -23,6 +23,6 @@
 </div>
 </div>
 <?php
-header("refresh: 3; url=/");
+header("refresh: 1; url=/");
 ?>
 @endsection

+ 10 - 0
resources/views/layouts/app.blade.php

@@ -55,6 +55,16 @@
                                     </form>
                                 </div>
                             </li>
+                            <li>
+                            <?php
+                            if(\App\bank::where('user_id', auth()->user()->id)->count()>0){
+                                $cal=\App\bank::where('user_id', auth()->user()->id)->get('money');
+                                $res = json_decode($cal, true);
+                                $upd=$res[0]['money'];
+                                echo "<p class='nav-link'>".$upd."</p>";
+                            }
+                                ?>
+                            </li>
                         @endguest
                     </ul>
                 </div>

+ 28 - 0
resources/views/needauth.blade.php

@@ -0,0 +1,28 @@
+@extends('layouts.app')
+
+@section('content1')
+<div style="margin-top: 6rem;">
+<div class="container">
+    <div class="row justify-content-center">
+        <div class="col-md-8">
+            <div class="card">
+                <div class="card-header">Dashboard</div>
+
+                <div class="card-body">
+                    @if (session('status'))
+                        <div class="alert alert-success" role="alert">
+                            {{ session('status') }}
+                        </div>
+                    @endif
+
+                    You are logged in!
+                </div>
+            </div>
+        </div>
+    </div>
+</div>
+</div>
+<?php
+header("refresh: 1; url=/daily");
+?>
+@endsection

+ 53 - 0
resources/views/posts/casino.blade.php

@@ -0,0 +1,53 @@
+@extends('layout')
+@section('content')
+    <style>
+      .bd-placeholder-img {
+        font-size: 1.125rem;
+        text-anchor: middle;
+      }
+
+      @media (min-width: 768px) {
+        .bd-placeholder-img-lg {
+          font-size: 3.5rem;
+        }
+      }
+    </style>
+    <!-- Custom styles for this template -->
+    <link href="css/form-validation.css" rel="stylesheet">
+</head>
+<body class="bg-light">
+<div class="container">
+  <div class="py-5 text-center">
+    <img class="d-block mx-auto mb-4" src="/docs/4.3.1/assets/brand/bootstrap-solid.svg" alt="" width="72" height="72" alt="bootstrap">
+    <h1>Try your luck</h1>
+    <p class="lead">Enter your email and the amount of money you want to bet</p>
+    <?php
+      if(!empty($_POST)){
+        if($newmon!=0){
+          echo "<div class='alert alert-success'><p class='lead'>You won ".$newmon."!</p></div>";
+        }
+        else{
+          echo "<div class='alert alert-danger'><p class='lead'>You lost ".$mon."!</p></div>";
+        }
+      }
+      ?>
+      </div>
+  <form method="POST" class="needs-validation" novalidate="" action="{{url('casino')}}">
+  	{{csrf_field()}}
+        <div class="mycol-md-4" >
+          <label for="firstName">Enter the amount of money</label>
+          @if($errors->has('num')) has-danger @endif
+          <input type="text" name="num" class="form-control" id="num" @if($errors->has('num')) is-invalid @endif>
+         
+          @error('num')
+            @foreach ($errors->all() as $error)
+                <li>{{ $error }}</li>
+            @endforeach
+          @enderror
+        <hr class="mb-4">
+        <button class="btn btn-primary btn-lg btn-block" type="submit">Continue to checkout</button>
+      </div>
+      </form>
+</body>
+</html>
+@endsection

+ 61 - 0
resources/views/posts/daily.blade.php

@@ -1,3 +1,64 @@
 @extends('layout')
 @section('content')
+    <style>
+      .bd-placeholder-img {
+        font-size: 1.125rem;
+        text-anchor: middle;
+      }
+
+      @media (min-width: 768px) {
+        .bd-placeholder-img-lg {
+          font-size: 3.5rem;
+        }
+      }
+    </style>
+    <!-- Custom styles for this template -->
+    <link href="css/form-validation.css" rel="stylesheet">
+</head>
+ 
+<body class="bg-light">
+<div class="container">
+  <div class="py-5 text-center">
+    <img class="d-block mx-auto mb-4" src="/docs/4.3.1/assets/brand/bootstrap-solid.svg" alt="" width="72" height="72" alt="bootstrap">
+    <h1>Top up account</h1>
+    <p class="lead">Enter your email and the amount of money you want to add</p>
+  </div>
+
+   @if($errors->any())
+        <ul>
+            @foreach ($errors->all() as $error)
+                <li>{{ $error }}</li>
+            @endforeach
+        </ul>
+   @endif
+   
+        
+  <form method="POST" class="needs-validation" novalidate="" action="{{action('PostsController@index')}}">
+  	{{csrf_field()}}
+        <div class="row">
+          <div class="col-md-6 mb-3">
+          	<label for="email">Email <span class="text-muted"></span></label>
+          	@if($errors->has('email')) has-danger @endif
+            <input type="email" name="email" class="form-control" id="email" placeholder="you@example.com" value="" @if($errors->has('email')) is-invalid @endif>
+             @error('email')
+            <div class="invalid-feedback">
+            Please enter a valid email address for shipping updates.
+          	</div>
+          	@enderror
+          </div>
+        <div class="col-md-6 mb-3">
+          <label for="num">Enter the amount of money</label>
+          @if($errors->has('num')) has-danger @endif
+          <input type="text" name="num" class="form-control" id="num" @if($errors->has('num')) is-invalid @endif>
+          @error('num')
+          <div class="invalid-feedback">
+            Enter the number.
+          </div>
+          @enderror
+        </div>
+        <hr class="mb-4">
+        <button class="btn btn-primary btn-lg btn-block" type="submit">Continue to checkout</button>
+      </form>
+</body>
+</html>
 @endsection

+ 12 - 10
resources/views/posts/index.blade.php

@@ -1,4 +1,9 @@
 @extends('layout')
+@if($flash=session('status'))
+    <div class="my_flash alert alert-success">
+        {{ $flash}}
+    </div>
+@endif
 @section('content')
 <main role="main">
   <div class="wrapper">
@@ -47,23 +52,20 @@
     </a>
   </div>
 </div>
+
 <div class="content">
   <div class="container marketing">
     <div class="row">
-      <div class="col-lg-4">
+      <div class="mycol-lg-4">
         <img class="bd-placeholder-img rounded-circle" width="200" height="200"  src="images/coin.svg">
-        <h2>Каждый день</h2>
-        <p><a class="btn btn-secondary" href="/daily" role="button">Перейти &raquo;</a></p>
+        <h2>Top up account</h2>
+        <p><a class="btn btn-secondary"  @if(auth()->check()) href="/daily" @else href ="/needauth" @endif role="button">Перейти &raquo;</a></p>
       </div>
-      <div class="col-lg-4">
+      <div class="col-lg-5" align="right">
        <img class="bd-placeholder-img rounded-circle" width="200" height="200"  src="images/coins.svg">
-        <h2>Каждую неделю</h2>
-        <p><a class="btn btn-secondary" href="#" role="button">Перейти &raquo;</a></p>
+        <h2>Try your luck</h2>
+        <p><a class="btn btn-secondary" @if(auth()->check()) href="/casino" @else href ="/authneed" @endif role="button">Перейти &raquo;</a></p>
       </div>
-      <div class="col-lg-4">
-        <img class="bd-placeholder-img rounded-circle" width="200" height="200"  src="images/coinss.svg">
-        <h2>Каждый месяц</h2>
-        <p><a class="btn btn-secondary" href="#" role="button">Перейти &raquo;</a></p>
       </div>
     </div>
   </div>

+ 6 - 1
routes/web.php

@@ -11,11 +11,16 @@
 |
 */
 
-Route::get('/', 'PostsController@index');
+Route::get('/', 'PostsController@indexx');
+Route::post('/', 'PostsController@index');
 Route::get('/daily', 'PostsController@daily');
+Route::get('/casino', 'PostsController@casino');
+Route::post('/casino', 'PostsController@post_casino');
 
 Auth::routes();
 
 Route::get('/home', 'HomeController@index')->name('home');
+Route::get('/needauth', 'HomeController@needauth');
+Route::get('/authneed', 'HomeController@authneed');