routes.php 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. <?php
  2. /*
  3. |--------------------------------------------------------------------------
  4. | Application Routes
  5. |--------------------------------------------------------------------------
  6. |
  7. | Here is where you can register all of the routes for an application.
  8. | It's a breeze. Simply tell Laravel the URIs it should respond to
  9. | and give it the Closure to execute when that URI is requested.
  10. |
  11. */
  12. Route::get('/', function()
  13. {
  14. $gesehen = Film::zuletztGesehen()->get();
  15. $vorgeschlagen = Film::neuesteVorschlage()->get();
  16. return View::make('index')
  17. ->with('gesehen', $gesehen)
  18. ->with('vorgeschlagen', $vorgeschlagen);
  19. });
  20. Route::get('film/{id}', array('as' => 'film', function($id) {
  21. $film = Film::findOrFail($id);
  22. $tmdb = new TMDb('b187f8d9c5e72b1faecb741d5d04239a', 'de', TRUE);
  23. $tmovie = $tmdb->getMovie($film->tvdbid);
  24. $tcast = $tmdb->getMovieCast($film->tvdbid);
  25. $ttrail = $tmdb->getMovieTrailers($film->tvdbid);
  26. $image = $tmdb->getImageUrl($tmovie['poster_path'], TMDb::IMAGE_POSTER, 'w342');
  27. $votes = $film->votes()->count();
  28. $vposi = $film->votes()->where('stimme', true)->count();
  29. $pv = "";
  30. foreach($film->votes()->where('stimme', true)->get() as $v) {
  31. $pv .= $v->voter->name . "<br> ";
  32. }
  33. $nv = "";
  34. foreach($film->votes()->where('stimme', false)->get() as $v) {
  35. $nv = $v->voter->name . "<br> ";
  36. }
  37. if(!is_null(Auth::user()) && $film->votes()->where('user', Auth::user()->id)->count() > 0) {
  38. $uvote[0] = true;
  39. $uvote[1] = $film->votes()->where('user', Auth::user()->id)->first()->stimme;
  40. } else {
  41. $uvote[0] = false;
  42. }
  43. $comments = $film->comments()->orderBy('id', 'DESC')->get();
  44. return View::make('film')
  45. ->with('film', $film)
  46. ->with('tfilm', $tmovie)
  47. ->with('poster', $image)
  48. ->with('comments', $comments)
  49. ->with('cast', $tcast)
  50. ->with('trail', $ttrail)
  51. ->with('votes', $votes)
  52. ->with('uvote', $uvote)
  53. ->with('pv', $pv)
  54. ->with('nv', $nv)
  55. ->with('vposi', $vposi)
  56. ->with('tmdb', $tmdb);
  57. }));
  58. Route::get('vote/{stimme}/{user}/{film}', function($stimme, $user, $film) {
  59. $v = Vote::where('user', $user)->where('film', $film)->first();
  60. if(!is_null($v)) {
  61. $v->stimme = $stimme == "yes" ? true : false;
  62. } else {
  63. $v = new Vote();
  64. $v->user = $user;
  65. $v->film = $film;
  66. $v->stimme = $stimme == "yes" ? true : false;
  67. }
  68. $v->save();
  69. return Redirect::to('film/' . $film);
  70. });
  71. Route::post('comment', array('as' => 'comment', function() {
  72. $c = new Comment();
  73. $c->film = Input::get('film');
  74. $c->user = Input::get('user');
  75. $c->text = Input::get('text');
  76. $c->save();
  77. return Redirect::to('film/' . Input::get('film'));
  78. }));
  79. Route::post('comment/edit', array('as'=> 'modcomment', function () {
  80. $c = Comment::findOrFail(Input::get('id'));
  81. $c->text = Input::get('text');
  82. $c->save();
  83. return Redirect::to('film/' . $c->film);
  84. }));
  85. Route::get('login', array('as' => 'login', function() {
  86. return View::make('login');
  87. }));
  88. Route::post('login', function() {
  89. $userdata = array(
  90. 'name' => Input::get('user'),
  91. 'password' => Input::get('password'));
  92. if(Auth::attempt($userdata)) {
  93. return Redirect::intended('/');
  94. } else {
  95. echo "Login gescheitert.";
  96. var_dump($userdata);
  97. return Redirect::to('login')
  98. ->with('login_errors', true);
  99. }
  100. });
  101. Route::get('logout', array('as' => 'logout', function() {
  102. Auth::logout();
  103. return Redirect::to('/');
  104. }));
  105. Route::get('vorgeschlagen/{field?}/{order?}', function($field = "vorgeschlagen", $order = "desc") {
  106. $filme = Film::whereNull('gesehen')->orderBy($field, $order)->paginate();
  107. return View::make('suggest')
  108. ->with('filme', $filme);
  109. })->where(array('field' => '[a-z]+', 'order' => 'asc|desc'));
  110. Route::get('gesehen/{field?}/{order?}', function($field = "gesehen", $order = "desc") {
  111. $filme = Film::whereNotNull('gesehen')->orderBy($field, $order)->paginate();
  112. return View::make('seen')
  113. ->with('filme', $filme);
  114. })->where(array('field' => '[a-z]+', 'order' => 'asc|desc'));
  115. Route::get('neu', array('before' => 'auth', function() {
  116. return View::make('new');
  117. }));
  118. Route::post('neu', array('before' => 'auth', function() {
  119. $tmdb = new TMDb('b187f8d9c5e72b1faecb741d5d04239a', 'de', TRUE);
  120. $r = $tmdb->searchMovie(Input::get('search'));
  121. return View::make('new')->with('result', $r)->with('tmdb', $tmdb);
  122. }));
  123. Route::get('vorschlag/{id}', array('before' => 'auth', function($id) {
  124. $tmdb = new TMDb('b187f8d9c5e72b1faecb741d5d04239a', 'de', TRUE);
  125. $f = $tmdb->getMovie($id);
  126. $film = new Film();
  127. $film ->name = $f['title'];
  128. $film->tvdbid = $id;
  129. $film->vorgeschlagen = \Carbon\Carbon::today();
  130. $film->user = Auth::user()->id;
  131. $film->save();
  132. return Redirect::to('film/' . $film->id);
  133. }));
  134. Route::get('mark-read/{id}', array('before' => 'auth', function($id) {
  135. $film = Film::findOrFail($id);
  136. $film->gesehen = \Carbon\Carbon::today();
  137. $film->save();
  138. return Redirect::to('film/' . $film->id);
  139. }));
  140. Route::get('register', function() {
  141. return View::make('register');
  142. });
  143. Route::post('register', function() {
  144. $vrules = array(
  145. 'name' => 'required|unique:users',
  146. 'email' => 'required|email',
  147. 'password' => 'required|confirmed',
  148. 'fire' => array('required', 'regex:/^Kreis$/i')
  149. );
  150. $vfields = array(
  151. 'name' => Input::get('user'),
  152. 'email' => Input::get('email'),
  153. 'password' => Input::get('password'),
  154. 'password_confirmation' => Input::get('pw-confirm'),
  155. 'fire' => Input::get('fire')
  156. );
  157. $val = Validator::make($vfields, $vrules);
  158. if($val->fails()) {
  159. return View::make('register')->with('errors', $val->messages());
  160. } else {
  161. $u = new User();
  162. $u->name = Input::get('user');
  163. $u->email = Input::get('email');
  164. $u->password = Hash::make(Input::get('password'));
  165. $u->save();
  166. return Redirect::to('/')->with('message', 'Registriert!');
  167. }
  168. });
  169. Route::get('settings', array('before' => 'auth', function() {
  170. return View::make('settings');
  171. }));
  172. Route::post('settings/{mode}', array('before' => 'auth', function($mode) {
  173. Validator::extend('pass', function($attribute, $value, $parameters) {
  174. return Hash::check($value, Auth::user()->password);
  175. });
  176. if($mode == 'password') {
  177. var_dump(Hash::check(Input::get('oldpw'), Auth::user()->password));
  178. $vfields = array('oldpw' => Input::get('oldpw'), 'newpw' => Input::get('newpw'), 'newpw_confirmation' => Input::get('newpw2'));
  179. $vrules = array( 'oldpw' => 'required|pass', 'newpw' => 'required|confirmed' );
  180. $val = Validator::make($vfields, $vrules);
  181. if($val->passes()) {
  182. $u = Auth::user();
  183. $u->password = Hash::make(Input::get('newpw'));
  184. $u->save();
  185. return View::make('settings')->with('message', 'Passwort geändert.');
  186. } else {
  187. return View::make('settings')->with('errors', $val->messages());
  188. }
  189. }
  190. if($mode == 'email') {
  191. $vfields = array('pw' => Input::get('pw'), 'email' => Input::get('email'), 'email_confirmation' => Input::get('email2'));
  192. $vrules = array('pw' => 'required|pass', 'email' => 'required|confirmed');
  193. $val = Validator::make($vfields, $vrules);
  194. if($val->passes()) {
  195. $u = Auth::user();
  196. $u->email = Input::get('email');
  197. $u->save();
  198. return View::make('settings')->with('message', 'Email geändert.');
  199. } else {
  200. return View::make('settings')->with('errors', $val->messages());
  201. }
  202. }
  203. }));
  204. Route::get('users', array('before' => 'auth', function() {
  205. if(Auth::user()->admin) {
  206. $u = User::orderBy('name')->paginate();
  207. return View::make('users')->with('users', $u);
  208. } else {
  209. App::abort(401, 'Diese Seite ist nicht für Dich.');
  210. }
  211. }));
  212. Route::get('users/{operation}/{id}', array('before' => 'auth', function($operation, $id) {
  213. if(!Auth::user()->admin) App::abort(401, 'Diese Seite ist nicht für Dich.');
  214. $u = User::findOrFail($id);
  215. switch($operation) {
  216. case 'mkadm':
  217. $u->admin = true;
  218. $u->save();
  219. $msg = $u->name . " ist jetzt ein Admin.";
  220. break;
  221. case 'rmadm':
  222. $u->admin = false;
  223. $u->save();
  224. $msg = $u->name . " ist kein Admin mehr.";
  225. break;
  226. case 'rmusr':
  227. $msg = $u->name . " wurde gelöscht.";
  228. $u->delete();
  229. break;
  230. }
  231. return Redirect::to('users')->with('message', $msg);
  232. }));