/** * signup to system * @return [type] [description] */ public function post_signup() { // get parameters and set to local variables $mymobile = utility::post('mobile', 'filter'); $mypass = utility::post('password', 'hash'); $myperm = $this->option('account'); if (!$myperm) { $myperm = 'NULL'; } $user_id = \lib\db\users::signup($mymobile, $mypass, $myperm); if ($user_id) { // generate verification code // save in logs table // set SESSION verification_mobile $code = \lib\utility\filter::generate_verification_code($user_id, $mymobile); if ($code) { \lib\utility\sms::send($mymobile, 'signup', $code); debug::true(T_("Register successfully")); $this->redirector()->set_url('verification?from=signup&mobile=' . $mymobile); // $this->redirector()->set_url('login?from=signup&cp=1&mobile='.$mymobile); } else { debug::error(T_("Please contact to administrator!")); } } elseif ($user_id === false) { debug::error(T_("Mobile number exist!")); } else { debug::error(T_("Please contact to administrator!")); } }
public function put_verification() { // get parameters and set to local variables $mycode = utility::post('code'); $mymobile = utility::post('mobile', 'filter'); if ($mymobile == '' && isset($_SESSION['verification_mobile'])) { $mymobile = $_SESSION['verification_mobile']; } $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")); } }