Skip to content
This repository was archived by the owner on Nov 13, 2023. It is now read-only.

Commit 64db93e

Browse files
committed
version 001
1 parent c269464 commit 64db93e

File tree

18 files changed

+536
-99
lines changed

18 files changed

+536
-99
lines changed

app/controllers/IngredientsController.php

+50-10
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,59 @@ public function create()
3131
*/
3232
public function store()
3333
{
34-
$validation = Validator::make(Input::all(),Ingredient::$rules);
35-
if ($validation->fails())
34+
//check if its our form
35+
if ( Session::token() !== Input::get( '_token' ) ) {
36+
return Response::json( array(
37+
'msg' => 'Unauthorized attempt to create setting'
38+
) );
39+
}
40+
41+
$name = Input::get( 'name' );
42+
$quantity = Input::get( 'quantity' );
43+
$unit = Input::get( 'unit' );
44+
45+
//validate data
46+
$validator = Validator::make(
47+
array( 'name' => $name,
48+
'quantity' => $quantity,
49+
'unit' => $unit),
50+
array( 'name' => array('required', 'min:2'),
51+
'quantity' => array('required','numeric','min:1'),
52+
'unit' => array('required', 'min:1'))
53+
);
54+
55+
// save to database or sent error based on validation
56+
if ($validator->fails())
3657
{
37-
return Redirect::back()->withInput()->withErrors($validation->messages());
58+
$response = array(
59+
'status' => 'failed',
60+
'errorMsgName' => $validator->messages()->first('name'),
61+
'errorMsgQuantity' => $validator->messages()->first('quantity'),
62+
'errorMsgUnit' => $validator->messages()->first('unit'),
63+
);
64+
65+
}else{
66+
$ingredient = new Ingredient();
67+
$ingredient->name = $name;
68+
$ingredient->quantity = $quantity;
69+
$ingredient->unit = $unit;
70+
$recipe = Recipe::where('id',Input::get('id'))->first();
71+
$recipe->ingredients()->save($ingredient);
72+
73+
$response = array(
74+
'status' => 'success',
75+
'name' => $name,
76+
'quantity' => $quantity,
77+
'unit' => $unit
78+
);
3879
}
3980

40-
$ingredient = new Ingredient();
41-
$ingredient->name = Input::get('name');
42-
$ingredient->quantity = Input::get('quantity');
43-
$ingredient->unit = Input::get('unit');
44-
$recipe = Recipe::where('id',Input::get('id'))->first();
45-
$recipe->ingredients()->save($ingredient);
46-
return Redirect::back();
81+
//handel return
82+
if(Input::get('ajax') == 1){
83+
return Response::json( $response );
84+
}else{
85+
return Redirect::back()->withInput()->withErrors($validator->messages());
86+
}
4787
}
4888

4989

app/controllers/StepsController.php

+41-10
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,50 @@ public function create()
3131
*/
3232
public function store()
3333
{
34-
$validation = Validator::make(Input::all(),Step::$rules);
35-
if ($validation->fails())
34+
//check if its our form
35+
if ( Session::token() !== Input::get( '_token' ) ) {
36+
return Response::json( array(
37+
'msg' => 'Unauthorized attempt to create setting'
38+
) );
39+
}
40+
41+
$description = Input::get( 'description' );
42+
43+
//validate data
44+
$validator = Validator::make(
45+
array('description' => $description),
46+
array('description' => array('required', 'min:10'))
47+
);
48+
49+
// save to database or sent error based on validation
50+
if ($validator->fails())
3651
{
37-
return Redirect::back()->withInput()->withErrors($validation->messages());
52+
$response = array(
53+
'status' => 'failed',
54+
'msg' => $validator->messages()->first('description')
55+
);
56+
57+
}else{
58+
$step = new Step();
59+
$step->description = $description;
60+
$step->image_url = "";
61+
$id =Input::get('id');
62+
$recipe = Recipe::where('id',$id)->first();
63+
$step->number = $recipe->steps()->count()+1;
64+
$recipe->steps()->save($step);
65+
$response = array(
66+
'status' => 'success',
67+
'msg' => $description,
68+
'nr' => $recipe->steps()->count()
69+
);
3870
}
3971

40-
$step = new Step();
41-
$step->description = Input::get('description');
42-
$step->number = Input::get('nr');
43-
$step->image_url = "";
44-
$recipe = Recipe::where('id',Input::get('id'))->first();
45-
$recipe->steps()->save($step);
46-
return Redirect::back();
72+
//handel return
73+
if(Input::get('ajax')==1){
74+
return Response::json( $response );
75+
}else{
76+
return Redirect::back()->withInput()->withErrors($validator->messages());
77+
}
4778
}
4879

4980

app/controllers/UsersController.php

+41-3
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,48 @@ public function edit($id)
8181
* @param int $id
8282
* @return Response
8383
*/
84-
public function update($id)
84+
public function update()
8585
{
86-
//
86+
//check if its our form
87+
if ( Session::token() !== Input::get( '_token' ) ) {
88+
return Response::json( array(
89+
'msg' => 'Unauthorized attempt to create setting'
90+
) );
91+
}
92+
93+
$description = Input::get( 'description' );
94+
95+
//validate data
96+
$validator = Validator::make(
97+
array('description' => $description),
98+
array('description' => array('required', 'min:10'))
99+
);
100+
101+
// save to database or sent error based on validation
102+
if ($validator->fails())
103+
{
104+
$response = array(
105+
'status' => 'failed',
106+
'msg' => $validator->messages()->first('description'),
107+
);
108+
109+
}else{
110+
$user =Auth::user();
111+
$user->description = $description;
112+
$user->save();
113+
$response = array(
114+
'status' => 'success',
115+
'msg' => $description,
116+
);
117+
}
118+
119+
//handel return
120+
if(Input::get('ajax')==1){
121+
return Response::json( $response );
122+
}else{
123+
return Redirect::back()->withInput()->withErrors($validator->messages());
124+
}
125+
87126
}
88127

89128

@@ -98,5 +137,4 @@ public function destroy($id)
98137
//
99138
}
100139

101-
102140
}

app/routes.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
Route::get('login', 'SessionsController@create');
2020
Route::get('logout', 'SessionsController@destroy');
21-
Route::get('dashboard', 'SessionsController@show');
2221
Route::get('register', 'UsersController@create');
2322

2423
Route::resource('users', 'UsersController');
@@ -27,4 +26,4 @@
2726
Route::resource('recipes', 'RecipesController');
2827
Route::resource('ingredients', 'IngredientsController');
2928
Route::resource('steps', 'StepsController');
30-
Route::resource('comments', 'CommentsController');
29+
Route::resource('comments', 'CommentsController');

app/views/comments/include/row.blade.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
</a>
1515
<p class="list-group-item-text"> {{{ $comment->comment }}} </p>
1616
@if(Auth::check())
17-
@if(Auth::user()->admin == 1)+
17+
@if(Auth::user()->admin == 1)
1818
<br/>
1919
{{ Form::open(array('route' => array('comments.destroy', $comment->id), 'method' => 'delete')) }}
2020
<button type="submit" href="{{ URL::route('comments.destroy', $comment->id) }}" class="btn btn-danger btn-sm">Delete comment</button>
+42-14
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,31 @@
11
@if(Auth::check())
22
@if(Auth::user()->id == $recipe->user->id)
33
<br/>
4-
{{ Form::open(['route' => 'ingredients.store', 'files' => true]) }}
4+
{{ Form::open(array(
5+
'route' => 'ingredients.store',
6+
'id' => 'form-add-ingredient',
7+
'class' => 'no-print'
8+
))
9+
}}
510
<div class="row">
611
<div class="col-sm-4">
712
<!-- Name -->
813
@if( $errors->first('name'))
914
<div class = "form-group has-error">
1015
{{ Form::text('name', '',array(
11-
'class'=>"form-control input-sm",
12-
'placeholder' => "Name")) }}
16+
'id' => 'name',
17+
'class'=>"form-control input-sm",
18+
'placeholder' => "Name"))
19+
}}
1320
<p class="text-danger" role="alert">{{$errors->first('name')}}</p>
1421
</div>
1522
@else
1623
<div class = "form-group">
1724
{{ Form::text('name', '',array(
18-
'class'=>"form-control input-sm",
19-
'placeholder' => "Name" )) }}
25+
'id' => 'name',
26+
'class'=>"form-control input-sm",
27+
'placeholder' => "Name" ))
28+
}}
2029
</div>
2130
@endif
2231
</div>
@@ -25,15 +34,19 @@
2534
@if( $errors->first('quantity'))
2635
<div class = "form-group has-error">
2736
{{ Form::number('quantity', '',array(
28-
'class'=>"form-control input-sm",
29-
'placeholder' => "Quantity")) }}
37+
'id' => 'quantity',
38+
'class'=>"form-control input-sm",
39+
'placeholder' => "Quantity"))
40+
}}
3041
<p class="text-danger" role="alert">{{$errors->first('quantity')}}</p>
3142
</div>
3243
@else
3344
<div class = "form-group">
3445
{{ Form::number('quantity', '',array(
35-
'class'=>"form-control input-sm",
36-
'placeholder' => "Quantity" )) }}
46+
'id' => 'quantity',
47+
'class'=>"form-control input-sm",
48+
'placeholder' => "Quantity" ))
49+
}}
3750
</div>
3851
@endif
3952
</div>
@@ -42,21 +55,36 @@
4255
@if( $errors->first('unit'))
4356
<div class = "form-group has-error">
4457
{{ Form::text('unit', '',array(
45-
'class'=>"form-control input-sm",
46-
'placeholder' => "Unit")) }}
58+
'id' => 'unit',
59+
'class'=>"form-control input-sm",
60+
'placeholder' => "Unit"))
61+
}}
4762
<p class="text-danger" role="alert">{{$errors->first('unit')}}</p>
4863
</div>
4964
@else
5065
<div class = "form-group">
5166
{{ Form::text('unit', '',array(
52-
'class'=>"form-control input-sm",
53-
'placeholder' => "Unit" )) }}
67+
'id' => 'unit',
68+
'class'=>"form-control input-sm",
69+
'placeholder' => "Unit" ))
70+
}}
5471
</div>
5572
@endif
5673
</div>
5774
</div>
5875
{{ Form::hidden('id' , $recipe->id)}}
59-
{{Form::submit('Add ingredient', array('class' => "btn btn-primary btn-sm btn-block"))}}
76+
@if(isset($error))
77+
{{ Form::submit('Add ingredient', array(
78+
'id' => "btn-add-ingredient",
79+
'class' => "btn btn-danger btn-sm btn-block"
80+
))}}
81+
@else
82+
{{ Form::submit('Add ingredient', array(
83+
'id' => "btn-add-ingredient",
84+
'class' => "btn btn-info btn-sm btn-block"))
85+
}}
86+
@endif
6087
{{ Form::close()}}
88+
<script src="/js/recipes/ingredient.js"></script>
6189
@endif
6290
@endif

app/views/layouts/master.blade.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
<html>
22
<head>
33
<meta charset="utf-8"/>
4-
<meta name="viewport" content="width=device-width, initial-scali=1"/>
4+
<meta name="viewport" content="width=device-width, initial-scale=1">
55
<link href="/css/bootstrap.min.css" rel="stylesheet">
66
<!-- Material css -->
77

88
<link href="/css/ripples.min.css" rel="stylesheet">
99
<link href="/css/material.css" rel="stylesheet">
1010

1111
<link rel= "stylesheet" href="/css/style.css"/>
12+
13+
<script src="/js/jquery-1.11.2.min.js"></script>
1214
<title>KitcheRPG</title>
1315
</head>
1416
<body>
@@ -60,8 +62,7 @@
6062
</div>
6163
</footer>
6264
<!-- Your site ends -->
63-
64-
<script src="/js/jquery-1.11.2.min.js"></script>
65+
6566
<script src="/js/bootstrap.min.js"></script>
6667

6768
<script src="/js/ripples.min.js"></script>

0 commit comments

Comments
 (0)