public function put_verification() { // get parameters and set to local variables $mycode = utility::post('code'); $mymobile = utility::post('mobile', 'filter'); $myuserid = $this->sql()->table('users')->field('id')->where('user_mobile', $mymobile)->select()->assoc('id'); // check for mobile exist $tmp_result = $this->sql()->table('logs')->where('user_id', $myuserid)->and('log_data', $mycode)->and('log_status', 'enable')->select(); if ($tmp_result->num()) { // mobile and code exist update the record and verify $qry = $this->sql()->table('logs')->set('log_status', 'expire')->where('user_id', $myuserid)->and('log_data', $mycode)->and('log_status', 'enable'); $sql = $qry->update(); $sql_users = $this->sql()->table('users')->where('id', $myuserid)->set('user_status', 'active')->update(); // ====================================================== // 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 ($_mobile, $_userid) { $myfrom = utility\Cookie::read('from'); if ($myfrom == 'signup') { // login user to system $this->model()->setLogin($_userid); //Send SMS \lib\utility\Sms::send($_mobile, 'verification'); debug::true(T_("verify successfully.")); } else { // login user to system $this->model()->setLogin($_userid, false); $this->redirector()->set_url('changepass'); $myreferer = utility\Cookie::write('mobile', $_mobile, 60 * 5); $myreferer = utility\Cookie::write('from', 'verification', 60 * 5); debug::true(T_("verify successfully.") . ' ' . T_("please Input your new password")); } }, $mymobile, $myuserid); // if a query has error or any error occour in any part of codes, run roolback $this->rollback(function () { debug::error(T_("verify failed!")); }); } elseif ($tmp_result->num() == 0) { debug::error(T_("this data is incorrect")); } else { debug::error(T_("please forward this message to administrator")); } }
public function post_recovery() { // get parameters and set to local variables $mymobile = utility::post('mobile', 'filter'); // check for mobile exist $tmp_result = $this->sql()->table('users')->where('user_mobile', $mymobile)->select(); if ($tmp_result->num() == 1) { $myuserid = $tmp_result->assoc('id'); $mylogitem = $this->sql()->table('logitems')->field('id')->where('logitem_title', 'account/recovery')->select()->assoc('id'); if (!isset($mylogitem)) { return; } $mycode = utility::randomCode(); $qry = $this->sql()->table('logs')->set('logitem_id', $mylogitem)->set('user_id', $myuserid)->set('log_data', $mycode)->set('log_status', 'enable')->set('log_createdate', date('Y-m-d H:i:s')); // var_dump($qry->insertString()); // return; $sql = $qry->insert(); // ====================================================== // 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 ($_mobile, $_code) { $myreferer = utility\Cookie::read('referer'); //Send SMS \lib\utility\Sms::send($_mobile, 'recovery', $_code); debug::true(T_("we send a verification code for you")); $myreferer = utility\Cookie::write('mobile', $_mobile, 60 * 5); $myreferer = utility\Cookie::write('from', 'recovery', 60 * 5); $this->redirector()->set_url('verification?from=recovery&mobile=' . $_mobile . '&referer=' . $myreferer); }, $mymobile, $mycode); // if a query has error or any error occour in any part of codes, run roolback $this->rollback(function () { debug::error(T_("recovery failed!")); }); } elseif ($tmp_result->num() == 0) { debug::error(T_("Mobile number is incorrect")); } else { debug::error(T_("please forward this message to administrator")); } }