From: Matteo Nastasi (mop) Date: Tue, 26 Feb 2013 17:43:52 +0000 (+0100) Subject: POST management working, preferences managed (room only) X-Git-Tag: v4.7.1~9 X-Git-Url: http://mop.ddnsfree.com/gitweb/?p=brisk.git;a=commitdiff_plain;h=3dc6d58fd477565017745b33c752232166a0b508 POST management working, preferences managed (room only) --- diff --git a/web/Obj/brisk.phh b/web/Obj/brisk.phh index b9f305a..803d28b 100644 --- a/web/Obj/brisk.phh +++ b/web/Obj/brisk.phh @@ -699,9 +699,60 @@ class Delay_Manager class Client_prefs { var $listen; - function Client_prefs($listen) + function Client_prefs() { - $this->listen = $listen; + } + + static function from_user($user) + { + $thiz = new Client_prefs(); + $thiz->user_load($user); + + return ($thiz); + } + + static function from_json($json) + { + $thiz = new Client_prefs(); + if ($thiz->json_load($json) == FALSE) { + return (FALSE); + } + + return ($thiz); + } + + function user_load($user) + { + fprintf(STDERR, "QQ %s: %x\n", __FUNCTION__, $user->flags); + $this->listen = ($user->flags & USER_FLAG_MAP_AUTH) >> 2; + + fprintf(STDERR, "QQ %s: LISTEN: %d\n", __FUNCTION__, $this->listen); + } + + function json_load($json_s) + { + if (gettype($json_s) == "string") { + if (($json = json_decode($json_s)) == FALSE) + return FALSE; + } + else { + $json = $json_s; + } + $this->listen = $json->listen; + + return TRUE; + } + + function store($user, $is_save) + { + // save into DB + fprintf(STDERR, "QQ %s::%s PRE: %x\n", __CLASS__, __FUNCTION__, + $user->flags & (~USER_FLAG_S_ALL & ~USER_FLAG_AUTH)); + $user->flags_set(($this->listen << 2), USER_FLAG_MAP_AUTH); + fprintf(STDERR, "QQ %s::%s %x\n", __CLASS__, __FUNCTION__, + $user->flags); + if ($is_save) + $user->store_set(); } } @@ -927,8 +978,7 @@ class Room $ret = sprintf('gst.st = %d; ', $user_step); - // for test: $prefs = new Client_prefs(USER_FLAG_LISTAUTH >> 2); - $prefs = new Client_prefs(($user->flags & USER_FLAG_MAP_AUTH) >> 2); + $prefs = Client_prefs::from_user($user); $ret .= sprintf('prefs_load(\'%s\', false, false);', json_encode($prefs)); if(false) { @@ -1829,27 +1879,33 @@ class Room $this->user[$idx]->flags |= ($authenticate != FALSE ? USER_FLAG_AUTH : 0x00); $this->user[$idx]->flags |= ( ($pass != FALSE && $bdb == FALSE) ? USER_FLAG_DBFAILED : 0x00); log_auth("XXX", sprintf("FLAGS: [%x]", $this->user[$idx]->flags)); - if ($authenticate != FALSE) { - $this->user[$idx]->code = $authenticate->code_get(); - $this->user[$idx]->flags |= USER_FLAG_LISTAUTH; - - if (isset($cookie['CO_list'])) { - if (strcmp($cookie['CO_list'], "auth") == 0) { - $this->user[$idx]->flags &= ~USER_FLAG_MAP_AUTH; - $this->user[$idx]->flags |= USER_FLAG_LISTAUTH; - } - if (strcmp($cookie['CO_list'], "isolation") == 0) { - $this->user[$idx]->flags &= ~USER_FLAG_MAP_AUTH; - $this->user[$idx]->flags |= USER_FLAG_ISOLAUTH; + $this->user[$idx]->code = $authenticate->code_get(); + if (0 == 1) { + // all this part is included in the db server + $this->user[$idx]->flags |= USER_FLAG_LISTAUTH; + + if (isset($cookie['CO_list'])) { + fprintf(STDERR, "QQ: %s CO_list: [%s]\n", __FUNCTION__, $cookie['CO_list']); + if (strcmp($cookie['CO_list'], "auth") == 0) { + $this->user[$idx]->flags &= ~USER_FLAG_MAP_AUTH; + $this->user[$idx]->flags |= USER_FLAG_LISTAUTH; + } + if (strcmp($cookie['CO_list'], "isolation") == 0) { + $this->user[$idx]->flags &= ~USER_FLAG_MAP_AUTH; + $this->user[$idx]->flags |= USER_FLAG_ISOLAUTH; + } + else { + $this->user[$idx]->flags &= ~USER_FLAG_MAP_AUTH; + } + } } else { - $this->user[$idx]->flags &= ~USER_FLAG_MAP_AUTH; + fprintf(STDERR, "QQ: CO_list not set flags: %x\n", __FUNCTION__, $this->user[$idx]->flags); } - } } - + fprintf(STDERR, "QQ %s: flag %x\n", __FUNCTION__, $this->user[$idx]->flags); if ($ghost > -1) { log_main("ghost: rename!"); $ghost_user = $this->user[$ghost]; @@ -2216,7 +2272,7 @@ class Room $content = ob_get_contents(); ob_end_clean(); - fprintf(STDERR, "\n\nCONTENT [%s]\n\n", $content); + // fprintf(STDERR, "\n\nCONTENT [%s]\n\n", $content); $s_a_p->pendpage_try_addflush($new_socket, 20, $enc, $header_out, $content); return TRUE; diff --git a/web/Obj/dbase_base.phh b/web/Obj/dbase_base.phh index d82de62..345b06f 100644 --- a/web/Obj/dbase_base.phh +++ b/web/Obj/dbase_base.phh @@ -36,6 +36,7 @@ class LoginDBItem { $this->login = $login; $this->pass = $pass; $this->email = $email; + fprintf(STDERR, "QQ: %s: %x\n", __FUNCTION__, $type); $this->type = $type; } @@ -69,6 +70,7 @@ class LoginDBItem { function type_get() { + fprintf(STDERR, "TYPE GET: %d\n", $this->type); return $this->type; } diff --git a/web/Obj/dbase_pgsql.phh b/web/Obj/dbase_pgsql.phh index 3e7a731..3c72851 100644 --- a/web/Obj/dbase_pgsql.phh +++ b/web/Obj/dbase_pgsql.phh @@ -157,11 +157,11 @@ class BriskDB return ($user_obj); } - function user_update_login_time($id, $lintm) + function user_update_login_time($code, $lintm) { GLOBAL $G_dbpfx; - $user_sql = sprintf("UPDATE %susers SET (lintm) = (date 'epoch' + %d * INTERVAL '1 second') WHERE code = %d;", $G_dbpfx, $lintm, $id); + $user_sql = sprintf("UPDATE %susers SET (lintm) = (date 'epoch' + %d * INTERVAL '1 second') WHERE code = %d;", $G_dbpfx, $lintm, $code); // $user_pg = $this->query($user_sql); // $row_n = pg_affected_rows($user_pg); @@ -172,6 +172,20 @@ class BriskDB return TRUE; } + + function user_update_flags($code, $flags) + { + GLOBAL $G_dbpfx; + + $user_sql = sprintf("UPDATE %susers SET (type) = (%d) WHERE code = %d;", $G_dbpfx, $flags, $code); + fprintf(STDERR, "REQUEST [%s]\n", $user_sql); + if ( ! (($user_pg = $this->query($user_sql)) != FALSE && pg_affected_rows($user_pg) == 1) ) { + return FALSE; + } + fprintf(STDERR, "REQUEST GOOD [%s]\n", $user_sql); + + return TRUE; + } function login_verify($login, $pass) { diff --git a/web/Obj/sac-a-push.phh b/web/Obj/sac-a-push.phh index c71cdf1..cea6419 100644 --- a/web/Obj/sac-a-push.phh +++ b/web/Obj/sac-a-push.phh @@ -266,7 +266,7 @@ function chunked_content($zls, $content) $cont_comp = $content; } $cont_comp_l = mb_strlen($cont_comp, "ASCII"); - printf("CHUNK: [%s]\n", $content); + // printf("CHUNK: [%s]\n", $content); return (sprintf("%X\r\n", $cont_comp_l).$cont_comp."\r\n"); } @@ -637,7 +637,7 @@ class Sac_a_push { } $write = NULL; $except = NULL; - $num_changed_sockets = @stream_select($read, $write, $except, 5, 500000); + $num_changed_sockets = @stream_select($read, $write, $except, 0, 500000); if ($num_changed_sockets == 0) { printf(" no data in 5 secs, splash [%d]\n", $G_with_splash); @@ -855,7 +855,7 @@ class Sac_a_push { if ($response != "") { // echo "SPIA: [".substr($response, 0, 60)."...]\n"; - echo "SPIA: [".$response."]\n"; + // echo "SPIA: [".$response."]\n"; $response_l = mb_strlen($response, "ASCII"); $wret = @fwrite($sock, $response); if ($wret < $response_l) { diff --git a/web/Obj/user.phh b/web/Obj/user.phh index f388603..f31d78b 100644 --- a/web/Obj/user.phh +++ b/web/Obj/user.phh @@ -135,7 +135,7 @@ class User { function User() { } - function create(&$room, $idx, $name, $sess, $stat = "", $subst = "", $table = -1, $ip="0.0.0.0") { + static function create(&$room, $idx, $name, $sess, $stat = "", $subst = "", $table = -1, $ip="0.0.0.0") { if (($thiz = new User()) == FALSE) return (FALSE); @@ -237,7 +237,7 @@ class User { } - function myclone($from) + static function myclone($from) { if (($thiz = new User()) == FALSE) return (FALSE); @@ -247,7 +247,7 @@ class User { return ($thiz); } - function spawn($from, $table, $table_pos) + static function spawn($from, $table, $table_pos) { if (($thiz = new User()) == FALSE) return (FALSE); @@ -299,6 +299,20 @@ class User { return ($thiz); } + function flags_set($flags, $mask) + { + $flags_old = $this->flags & (~$mask); + $this->flags = ($flags_old | ($flags & $mask)); + } + + function store_set() + { + if (($bdb = BriskDB::create()) == FALSE) { + return FALSE; + } + return ($bdb->user_update_flags($this->code, ($this->flags & (USER_FLAG_TY_ALL | USER_FLAG_MAP_AUTH)))); + } + function rd_data_set($curtime, $transp, $enc, $stat, $subst, $step, $from) { $this->rd_endtime = $curtime + RD_ENDTIME_DELTA; diff --git a/web/briskin5/Obj/briskin5.phh b/web/briskin5/Obj/briskin5.phh index cda8768..d7dc0df 100644 --- a/web/briskin5/Obj/briskin5.phh +++ b/web/briskin5/Obj/briskin5.phh @@ -503,7 +503,7 @@ class Bin5_user extends User { } */ - function spawn($from, &$bri, $table, $table_pos, $get, $post, $cookie) + static function spawn($from, &$bri, $table, $table_pos, $get, $post, $cookie) { if (($thiz = new Bin5_user()) == FALSE) return (FALSE); diff --git a/web/index.php b/web/index.php index 118c8d8..0b16ecd 100644 --- a/web/index.php +++ b/web/index.php @@ -1225,13 +1225,10 @@ type="submit" class="button" onclick="this.form.elements['realsub'].value = 'chi -
- -


- +
diff --git a/web/index_wr.php b/web/index_wr.php index e2f67ea..7cb9c35 100644 --- a/web/index_wr.php +++ b/web/index_wr.php @@ -110,13 +110,13 @@ function index_wr_main(&$room, $remote_addr_full, $get, $post, $cookie) } $is_spawn = FALSE; - + log_wr(0, 'index_wr.php: COMM: '.xcapemesg($mesg)); log_wr('COMM: '.xcapemesg($mesg)); - + $curtime = time(); $dt = date("H:i ", $curtime); - + if (($user = $room->get_user($sess, &$idx)) == FALSE) { $argz = explode('|', xcapemesg($mesg)); @@ -184,9 +184,6 @@ function index_wr_main(&$room, $remote_addr_full, $get, $post, $cookie) else if ($argz[0] == 'whysupport') { echo show_notify(str_replace("\n", " ", $G_room_whysupport[$G_lang]), 0, $mlang_indwr['btn_close'][$G_lng], 400, 200); } - else if ($argz[0] == 'prefs') { - fprintf(STDERR, "\n\n PREFS \n\n"); - } else { log_wr("Get User Error"); echo "Get User Error:" + $argz[0]; @@ -195,8 +192,6 @@ function index_wr_main(&$room, $remote_addr_full, $get, $post, $cookie) return TRUE; } - - $argz = explode('|', xcapemesg($mesg)); log_wr('POSTSPLIT: '.$argz[0]); @@ -207,6 +202,24 @@ function index_wr_main(&$room, $remote_addr_full, $get, $post, $cookie) if ($argz[0] == 'ping') { log_wr("PING RECEIVED"); } + else if ($argz[0] == 'prefs') { + fprintf(STDERR, "\n\n PREFS pre\n\n"); + if (!isset($post['prefs'])) { + return FALSE; + } + + $prefs = Client_prefs::from_json($post['prefs']); + fprintf(STDERR, "\n\n PREFS [%s]\n\n", print_r($prefs, TRUE)); + + $prefs->store($user, TRUE); + + $user->comm[$user->step % COMM_N] = "gst.st = ".($user->step+1)."; "; + $user->comm[$user->step % COMM_N] .= sprintf('prefs_load(\'%s\', true, %s);', json_encode($prefs), + 'false'); + $user->step_inc(); + echo "1"; + return TRUE; + } else if ($argz[0] == 'shutdown') { log_auth($user->sess, "Shutdown session."); diff --git a/web/room.js b/web/room.js index 8456ecf..2572555 100644 --- a/web/room.js +++ b/web/room.js @@ -725,9 +725,8 @@ function prefs_apply(prefs_new, is_update, is_volat) if (typeof(g_prefs) == 'undefined') return false; - /* listen management */ - if (g_prefs.listen != prefs_new.listen) { + if (g_prefs.listen != prefs_new.listen || is_update) { for (i = 0 ; i < prefs_list_idx.length ; i++) { set_checked_value($('ra_listen_'+prefs_list_id[i]), prefs_new.listen); if (prefs_new.listen == prefs_list_idx[i]) { @@ -791,12 +790,15 @@ function prefs_load(content, is_update, is_volat) function prefs_save() { + var ret; + if (typeof(g_prefs) == 'undefined') return false; - console.log(server_request('mesg', 'prefs', '__POST__', 'prefs', JSON.stringify(g_prefs))); - // close the win: - // $('preferences').style.visibility = 'hidden'; + ret = server_request('mesg', 'prefs','__POST__', 'prefs', JSON.stringify(g_prefs)); + + if (ret == 1) + $('preferences').style.visibility = 'hidden'; } function prefs_update() @@ -817,9 +819,7 @@ function prefs_update() break; } - /* TODO SAVE TEMPORARY */ /* from form to struct */ - console.log("Prefs_update"); prefs_apply(prefs_new, true, true); }