Advertisement
Guest User

Untitled

a guest
Apr 6th, 2017
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.03 KB | None | 0 0
  1. Route::post('channel_pass', 'PagesController@channel_pass');
  2.  
  3. <script>
  4. $('.room').on('click',function(){
  5. var passwordTemp = $('.password', this).text();
  6. var password = $.trim(passwordTemp);
  7. var id = $('.channel-id', this).text();
  8. if (password == 'Nie'){
  9. $('#loader-wrap').show();
  10. var passVal = '0';
  11. $.ajax({
  12. type : 'POST',
  13. url : 'channel_pass',
  14. data : {
  15. 'id': id,
  16. 'pass': passVal
  17. },
  18. success: function(msg){
  19. window.location.href = msg;
  20. },
  21. error: function(){
  22. $('#loader-wrap').hide();
  23. }
  24. });
  25. } else{
  26. $('.password-wrap').show()
  27. var id = $('.channel-id', this).text();
  28. $('.password-wrap #room-id').attr('value', id);
  29. }
  30. });
  31.  
  32. $('.password-wrap i').on('click',function(){
  33. $('.password-wrap').hide()
  34. $('.password-wrap #room-id').val('');
  35. $('.password-wrap #pass').val('');
  36. });
  37. </script>
  38.  
  39.  
  40. public function channel_pass(){
  41. $user = Auth::user()->login;
  42. $user_id = Auth::user()->id;
  43. $channel_id = $_POST['id'];
  44. $password = $_POST['pass'];
  45. $channel_pass = DB::table('channel')
  46. ->where('id', $channel_id)
  47. ->pluck('password');
  48. $cut = str_replace('"', '', $channel_pass);
  49. $cut1 = str_replace('[', '', $cut);
  50. $cut2 = str_replace(']', '', $cut1);
  51. $url = DB::table('channel')
  52. ->where('id', $channel_id)
  53. ->pluck('page');
  54. $urlCut = str_replace('"', '', $url);
  55. $urlCut2 = str_replace('[', '', $urlCut);
  56. $urlCut3 = str_replace(']', '', $urlCut2);
  57. $dostep = '/room='.$urlCut3;
  58. $channel_ban = DB::table('channel_ban')
  59. ->where('channel_id', $channel_id)
  60. ->pluck('user_id');
  61. $banCut = str_replace('[','', $channel_ban);
  62. $banCut2 = str_replace(']','', $banCut);
  63. $count = DB::table('users')
  64. ->where('channel_id', $channel_id)
  65. ->count();
  66. $count_max = DB::table('channel')
  67. ->where('id', $channel_id)
  68. ->pluck('number_people');
  69. $count_maxCut = str_replace('[','', $count_max);
  70. $count_maxCut2 = str_replace(']','', $count_maxCut);
  71. if($count >= $count_maxCut2){
  72. Session::flash('status', 'Ten pokój jest pełny.');
  73. return redirect()->intended('rooms');
  74. }else if($banCut2 == $user_id){
  75. Session::flash('status', 'Nie możesz tutaj wejść ponieważ zostałeś wcześniej wyrzucony z tego pokoju.');
  76. return redirect()->intended('rooms');
  77. }else if ($cut2 == '0'){
  78. DB::table('users')
  79. ->where('login', $user)
  80. ->update(['channel_id' => $channel_id]);
  81. return $dostep;
  82. }else if($password == $cut2){
  83. DB::table('users')
  84. ->where('login', $user)
  85. ->update(['channel_id' => $channel_id]);
  86. return redirect()->intended($dostep);
  87. }else{
  88. Session::flash('status', 'Błędne hasło do pokoju.');
  89. return redirect()->intended('rooms');
  90. }
  91.  
  92.  
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement