示例#1
0
 public function reset_pass()
 {
     $token = $_POST['reset_token'];
     $pass = $_POST['pass'];
     $constraints = new \CODOF\Constraints\User();
     $constraints->password($pass);
     $errors = $constraints->get_errors();
     if (empty($errors)) {
         $username = \DB::table(PREFIX . 'codo_users')->where('token', $token)->pluck('username');
         if ($username != null) {
             $parts = explode("&", $token);
             $expiry = $parts[1];
             if ($expiry > time()) {
                 $user = \CODOF\User\User::getByUsername($username);
                 if ($user) {
                     $user->updatePassword($pass);
                     \DB::table(PREFIX . 'codo_users')->where('token', $token)->update(array('token' => null));
                 }
             } else {
                 $errors[] = _t("Password reset token has expired");
             }
         } else {
             $errors[] = _t("Incorrect token");
         }
     }
     if (!empty($errors)) {
         $resp = array("status" => "fail", "msg" => $errors);
     } else {
         $resp = array("status" => "success", "msg" => _t("Password changed successfully...Redirecting to login page"));
     }
     echo json_encode($resp);
 }
 /**
  * 
  * Get different possible errors before registering an user
  * @return Array errors
  */
 public function get_errors()
 {
     $constraints = new \CODOF\Constraints\User();
     $constraints->username($this->username);
     $constraints->password($this->password);
     $constraints->mail($this->mail);
     $errors = $constraints->get_errors();
     if (\CODOF\Util::get_opt('captcha') == "enabled") {
         require_once ABSPATH . 'sys/Ext/recaptcha/recaptchalib.php';
         $privatekey = \CODOF\Util::get_opt("captcha_private_key");
         // your secret key
         $secret = $privatekey;
         // empty response
         $response = null;
         // check secret key
         $reCaptcha = new \ReCaptcha($secret);
         if ($_POST["g-recaptcha-response"]) {
             $response = $reCaptcha->verifyResponse($_SERVER["REMOTE_ADDR"], $_POST["g-recaptcha-response"]);
         }
         if (!($response != null && $response->success)) {
             $errors[] = _t("capcha entered was wrong");
         }
     }
     return $errors;
 }
示例#3
0
    if (Request::valid($_POST['token'])) {
        $tids = $_POST['tids'];
        $dest = $_POST['dest'];
        $topic = new Controller\Ajax\forum\topic();
        $topic->move($tids, $dest);
    }
});
dispatch_post('Ajax/user/edit/change_pass', function () {
    if (Request::valid($_POST['token'])) {
        $old_pass = $_POST['curr_pass'];
        $new_pass = $_POST['new_pass'];
        //$db = \DB::getPDO();
        $me = CODOF\User\User::get();
        $constraints = new CODOF\Constraints\User();
        $matched = $me->checkPassword($old_pass);
        if ($constraints->password($new_pass) && $matched) {
            $me->updatePassword($new_pass);
            $ret = array("status" => "success", "msg" => _t("Password updated successfully"));
        } else {
            $errors = $constraints->get_errors();
            if (!$matched) {
                $errors = array_merge($errors, array(_t("The current password given is incorrect")));
            }
            $ret = array("status" => "fail", "msg" => $errors);
        }
        echo json_encode($ret);
    }
});
dispatch_get('Ajax/cron/run', function () {
    if (Request::valid($_GET['token']) && \CODOF\User\CurrentUser\CurrentUser::loggedIn()) {
        $cron = new \CODOF\Cron\Cron();