示例#1
0
 function post_changepass()
 {
     $myid = $this->login('id');
     $newpass = utility::post('password-new', 'hash');
     $oldpass = utility::post('password-old');
     $tmp_result = $this->sql()->tableUsers()->where('id', $myid)->and('user_status', 'active')->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($oldpass, $myhashedPassword)) {
             $newpass = utility::post('password-new', 'hash');
             $qry = $this->sql()->table('users')->where('id', $myid)->set('user_pass', $newpass);
             $sql = $qry->update();
             $this->commit(function () {
                 debug::true(T_("change password successfully"));
                 $this->redirector()->set_domain()->set_url();
                 // \lib\utility\Sms::send($_mobile, 'changepass');
             });
             // if a query has error or any error occour in any part of codes, run roolback
             $this->rollback(function () {
                 debug::error(T_("change password failed!"));
             });
         } else {
             debug::error(T_("Password is incorrect"));
         }
     } elseif ($tmp_result->num() == 0) {
         debug::error(T_("user is incorrect"));
     } else {
         debug::error(T_("Please forward this message to administrator"));
     }
     sleep(0.1);
 }
示例#2
0
 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);
 }
示例#3
0
 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_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"));
                 $referer = \lib\router::urlParser('referer', 'host');
                 /**
                  * temporary: after fix permissions below line must be delete
                  */
                 if ($referer == 'archiver.dev' || $referer == 'irancamera.ir') {
                     $this->redirector()->set_domain()->set_sub_domain('files')->set_url();
                 } elseif (\lib\router::get_storage('CMS')) {
                     $this->redirector()->set_domain()->set_sub_domain(\lib\router::get_storage('CMS'))->set_url();
                 } else {
                     $this->redirector()->set_domain()->set_url();
                 }
             });
             $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);
 }
示例#4
0
 /**
  * check signup and if can add new user
  * @return [type] [description]
  */
 public static function signup($_mobile, $_pass, $_perm = null, $_name = null, $_ref = null)
 {
     // first if perm is true get default permission from db
     if ($_perm === true) {
         // if use true fill it with default value
         $_perm = \lib\utility\option::get('account');
         // default value not set in database
         if ($_perm == '') {
             $_perm = null;
         }
     } else {
         $_perm = null;
     }
     $query = "\n\t\t\tSELECT\n\t\t\t\tid\n\t\t\tFROM\n\t\t\t\tusers\n\t\t\tWHERE\n\t\t\t\tuser_mobile = '{$_mobile}'\n\t\t\tLIMIT 1\n\t\t";
     $result = \lib\db::get($query, 'id', true);
     if ($result) {
         // signup called and the mobile exist
         return false;
     } else {
         $ref = null;
         // get the ref and set in users_parent
         if (isset($_SESSION['user']['ref'])) {
             $ref = $_SESSION['user']['ref'];
         } elseif ($_ref) {
             $ref = $_ref;
         }
         // signup up users
         $args = ['user_mobile' => $_mobile, 'user_pass' => \lib\utility::hasher($_pass), 'user_displayname' => $_name, 'user_permission' => $_perm, 'user_parent' => $ref, 'user_createdate' => date('Y-m-d H:i:s')];
         $insert_new = self::insert($args);
         $insert_id = \lib\db::insert_id();
         self::$user_id = $insert_id;
         // save ref in dashboard
         if ($ref && $insert_id) {
             self::dashboard_ref($ref, "user_referred");
         }
         return $insert_id;
     }
 }