Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Route::post('channel_pass', 'PagesController@channel_pass');
- <script>
- $('.room').on('click',function(){
- var passwordTemp = $('.password', this).text();
- var password = $.trim(passwordTemp);
- var id = $('.channel-id', this).text();
- if (password == 'Nie'){
- $('#loader-wrap').show();
- var passVal = '0';
- $.ajax({
- type : 'POST',
- url : 'channel_pass',
- data : {
- 'id': id,
- 'pass': passVal
- },
- success: function(msg){
- window.location.href = msg;
- },
- error: function(){
- $('#loader-wrap').hide();
- }
- });
- } else{
- $('.password-wrap').show()
- var id = $('.channel-id', this).text();
- $('.password-wrap #room-id').attr('value', id);
- }
- });
- $('.password-wrap i').on('click',function(){
- $('.password-wrap').hide()
- $('.password-wrap #room-id').val('');
- $('.password-wrap #pass').val('');
- });
- </script>
- public function channel_pass(){
- $user = Auth::user()->login;
- $user_id = Auth::user()->id;
- $channel_id = $_POST['id'];
- $password = $_POST['pass'];
- $channel_pass = DB::table('channel')
- ->where('id', $channel_id)
- ->pluck('password');
- $cut = str_replace('"', '', $channel_pass);
- $cut1 = str_replace('[', '', $cut);
- $cut2 = str_replace(']', '', $cut1);
- $url = DB::table('channel')
- ->where('id', $channel_id)
- ->pluck('page');
- $urlCut = str_replace('"', '', $url);
- $urlCut2 = str_replace('[', '', $urlCut);
- $urlCut3 = str_replace(']', '', $urlCut2);
- $dostep = '/room='.$urlCut3;
- $channel_ban = DB::table('channel_ban')
- ->where('channel_id', $channel_id)
- ->pluck('user_id');
- $banCut = str_replace('[','', $channel_ban);
- $banCut2 = str_replace(']','', $banCut);
- $count = DB::table('users')
- ->where('channel_id', $channel_id)
- ->count();
- $count_max = DB::table('channel')
- ->where('id', $channel_id)
- ->pluck('number_people');
- $count_maxCut = str_replace('[','', $count_max);
- $count_maxCut2 = str_replace(']','', $count_maxCut);
- if($count >= $count_maxCut2){
- Session::flash('status', 'Ten pokój jest pełny.');
- return redirect()->intended('rooms');
- }else if($banCut2 == $user_id){
- Session::flash('status', 'Nie możesz tutaj wejść ponieważ zostałeś wcześniej wyrzucony z tego pokoju.');
- return redirect()->intended('rooms');
- }else if ($cut2 == '0'){
- DB::table('users')
- ->where('login', $user)
- ->update(['channel_id' => $channel_id]);
- return $dostep;
- }else if($password == $cut2){
- DB::table('users')
- ->where('login', $user)
- ->update(['channel_id' => $channel_id]);
- return redirect()->intended($dostep);
- }else{
- Session::flash('status', 'Błędne hasło do pokoju.');
- return redirect()->intended('rooms');
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement