public function go()
 {
     $this->setViewTemplate('resetpw.tpl');
     if (isset($_GET['username'])) {
         $username = $_GET['username'];
     }
     if (isset($_GET['token'])) {
         $token = $_GET['token'];
     }
     if (!User::validateToken($username, $token)) {
         $this->addErrorMessage("The token is invalid");
     } else {
         if (isset($_POST['submit'])) {
             if ($_POST['newpassword'] == '') {
                 $this->addErrorMessage("Password should not be empty");
             } elseif ($_POST['confirmnewpassword'] == '') {
                 $this->addErrorMessage("Confirm password field should not be empty");
             } else {
                 $password = $_POST['newpassword'];
                 $confirmpassword = $_POST['confirmnewpassword'];
                 if (!($password == $confirmpassword)) {
                     $this->addErrorMessage("The two passwords dont match!");
                 } else {
                     if (!User::updatePassword($password, $username)) {
                         $this->addErrorMessage("An error occured while updating the password");
                     } else {
                         $this->addSuccessMessage("Password has been updated successfully!You can now login with your new password");
                     }
                 }
             }
         }
     }
     return $this->generateView();
 }
Example #2
0
 public function __construct($name, $label, $path)
 {
     parent::__construct($name, $label);
     $this->type = "upload";
     $id = uniqueID();
     $this->sessionKey = "manager_" . $this->type . $id;
     $this->updateURL = "fields/" . $this->type . $id;
     $this->limit = 1;
     $this->hasCaption = false;
     $this->path = $path;
     $this->defaultValue = array();
     $this->accepts = array();
     $this->acceptsMask = null;
     $that = $this;
     Router::register("POST", "manager/api/" . $this->updateURL . "/(:segment)/(:num)/(:segment)", function ($action, $id, $flag) use($that) {
         if (($token = User::validateToken()) !== true) {
             return $token;
         }
         $flag = Str::upper($flag);
         $that->module->flag = $flag;
         switch ($action) {
             default:
             case "update":
                 return Response::json($that->upload($flag, $id));
                 break;
             case "sort":
                 return Response::json($that->sort(Request::post("from", -1), Request::post("to", -1)));
                 break;
             case "caption":
                 return Response::json($that->setCaption((int) Request::post("index", -1), Request::post("caption")));
                 break;
             case "delete":
                 return Response::json($that->delete((int) Request::post("index", -1)));
                 break;
         }
         return Response::code(500);
     });
 }