public function post_login() { // get parameters and set to local variables $mymobile = utility::post('mobile', 'filter'); $mypass = utility::post('password'); // check for mobile exist $tmp_result = $this->sql()->tableUsers()->whereUser_mobile($mymobile)->and('user_status', 'active')->select(); // $tmp_result = $this->sql()->tableUsers()->select(); // if exist if ($tmp_result->num() == 1) { $tmp_result = $tmp_result->assoc(); $myhashedPassword = $tmp_result['user_pass']; // if password is correct. go for login:) if (isset($myhashedPassword) && utility::hasher($mypass, $myhashedPassword)) { // you can change the code way easily at any time! // $qry = $this->sql()->tableUsers () // ->setUser_logincounter ($tmp_result['user_logincounter'] +1) // ->whereId ($tmp_result['id']); // $sql = $qry->update(); $myfields = array('id', 'user_displayname', 'user_mobile', 'user_meta', 'user_status'); $this->setLoginSession($tmp_result, $myfields); // ====================================================== // you can manage next event with one of these variables, // commit for successfull and rollback for failed // if query run without error means commit $this->commit(function () { // $this->logger('login'); // create code for pass with get to service home page debug::true(T_("Login Successfully")); \lib\utility\session::save(); $referer = \lib\router::urlParser('referer', 'host'); // set redirect to homepage $this->redirector()->set_domain()->set_url(); if (\lib\utility\option::get('account', 'status')) { $_redirect_sub = \lib\utility\option::get('account', 'meta', 'redirect'); if ($_redirect_sub !== 'home') { if (\lib\utility\option::get('config', 'meta', 'fakeSub')) { $this->redirector()->set_url($_redirect_sub); } else { $this->redirector()->set_sub_domain($_redirect_sub); } } } // do not use pushstate and run link direct debug::msg('direct', true); }); $this->rollback(function () { debug::error(T_("Login failed!")); }); } else { debug::error(T_("Mobile or password is incorrect")); } } elseif ($tmp_result->num() == 0) { debug::error(T_("Mobile or password is incorrect")); } else { debug::error(T_("Please forward this message to administrator")); } // sleep(0.1); }
/** * Update options data * @return run update query and no return value */ function put_options() { $newOptions = null; if (\lib\utility::post('reset') === 'reset' || \lib\utility::get('action') === 'reset') { $newOptions = $this->getDefault(); \lib\debug::msg('direct', true); } else { $newOptions = $this->getOptions(); } foreach ($newOptions as $group => $record) { foreach ($record as $field => $value) { $meta = null; $status = 'enable'; $qry = $this->sql()->table('options')->where('option_cat', 'option_' . $group)->and('option_key', $field)->and('post_id', '#NULL')->and('user_id', '#NULL'); $fieldExist = $qry->select()->num(); // if exist more than 2 times remove all the properties if ($fieldExist > 1) { debug::true(T_("We find a problem and solve it!")); $qry->delete(); $fieldExist = 0; } // for array seperate it intro value and meta and encode it if (is_array($value)) { // set meta values if (isset($value['meta'])) { // do something in config if ($field === 'config') { $this->doConfig($value['meta']); } elseif ($field === 'telegram') { $this->doTelegram($value['meta']); } $meta = json_encode($value['meta'], JSON_FORCE_OBJECT | JSON_HEX_QUOT | JSON_HEX_APOS | JSON_UNESCAPED_UNICODE); // $meta = $value['meta']; } // set status if exist if (array_key_exists('status', $value)) { $status = $value['status'] ? 'enable' : 'disable'; } // set value if (array_key_exists('value', $value)) { $value = $value['value']; } else { $value = null; } } // if value is empty set it empty if (!$value) { $value = '#""'; } $qry = $qry->set('option_cat', 'option_' . $group)->set('option_status', $status)->set('option_key', $field)->set('option_value', $value); // if meta is not empty then add it to insert query if (isset($meta) && $meta !== '""') { $qry = $qry->set('option_meta', $meta); } // if exist update field if ($fieldExist == 1) { // var_dump($qry->updateString()); $qry->update(); } else { $qry->insert('IGNORE'); } } } $this->commit(function () { debug::true(T_("Update Successfully")); // $this->redirector()->set_url($_module.'/edit='.$_postId); }); // if a query has error or any error occour in any part of codes, run roolback $this->rollback(function () { debug::title(T_("Transaction error") . ': '); }); }
public function _corridor() { if (method_exists($this, 'corridor')) { $this->corridor(); } if (!$this->method) { $this->method = 'get'; } $processor_arg = false; if (isset($this->model_api_processor)) { $name = $this->model_api_processor->method; $args = $this->model_api_processor->args; $api_callback = call_user_func_array(array($this->model(), $name), array($args)); $this->api_callback = $api_callback; } if (saloos::is_json_accept()) { $this->display = false; } if (!\lib\router::get_storage('api') && $this->method == 'get' && $this->display) { $this->view(); if (isset($this->view_api_processor)) { $name = $this->view_api_processor->method; $args = $this->view_api_processor->args; if (isset($this->api_callback)) { $args->api_callback = $api_callback; } call_user_func_array(array($this->view(), $name), array($args)); } if ($this->display) { $this->view()->corridor(); } } elseif (router::get_storage('api') || !$this->display) { $mycallback = isset($this->api_callback) ? $this->api_callback : null; debug::msg('callback', $mycallback); $processor_arg = object(array('force_json' => true)); } if ($this->model) { $this->model()->_processor($processor_arg); } }
/** * [_processor description] * @param boolean $options [description] * @return [type] [description] */ public function _processor($options = false) { if (is_array($options)) { $options = (object) $options; } $force_json = gettype($options) == 'object' && isset($options->force_json) && $options->force_json ? true : false; $force_stop = gettype($options) == 'object' && isset($options->force_stop) && $options->force_stop ? true : false; $not_redirect = gettype($options) == 'object' && isset($options->not_redirect) && $options->not_redirect ? true : false; if ($not_redirect) { $this->controller()->redirector = false; } if (\saloos::is_json_accept() || $force_json) { header('Content-Type: application/json'); if (isset($this->controller()->redirector) && $this->controller()->redirector) { $_SESSION['debug'][md5(strtok($this->redirector()->redirect(true), '?'))] = debug::compile(); debug::msg("redirect", $this->redirector()->redirect(true)); } echo debug::compile(true); } elseif (!\lib\router::get_storage('api') && strtolower($_SERVER['REQUEST_METHOD']) == "post") { $this->redirector(); } if (isset($this->controller()->redirector) && $this->controller()->redirector && !\saloos::is_json_accept()) { $_SESSION['debug'][md5(strtok($this->redirector()->redirect(true), '?'))] = debug::compile(); $this->redirector()->redirect(); } if ($force_stop) { exit; } }