コード例 #1
0
 public function addEntity($entity)
 {
     $type = $entity->type;
     $entity = strcasecmp($type, 'govt-entity') == 0 ? new GovernmentEntity($entity->data) : new ExtractiveCompany($entity->data);
     $user = func_num_args() == 2 ? func_get_arg(1) : false;
     if (count($entity->getErrors()) == 0) {
         try {
             $this->getConnection()->beginTransaction();
             if (strcasecmp($type, 'govt-entity') == 0) {
                 $sql = "INSERT INTO governmententity (entityName, entityID, dateOfEstablishment, contactAddress) " . "VALUES(:name, :id, :date, :contact) " . "ON DUPLICATE KEY UPDATE " . "entityName=VALUES(entityName), dateOfEstablishment=VALUES(dateOfEstablishment), contactAddress=VALUES(contactAddress), " . "entityID=LAST_INSERT_ID(entityID);";
             } else {
                 $sql = "INSERT INTO extractivecompany (companyName, TPIN, dateOfEstablishment, contactAddress, companyCapital, primaryBusiness, secondaryBusiness) " . "VALUES(:name, :id, :date, :contact, :capital, :primary, :secondary) " . "ON DUPLICATE KEY UPDATE " . "companyName=VALUES(companyName), dateOfEstablishment=VALUES(dateOfEstablishment), " . "companyCapital=VALUES(companyCapital), primaryBusiness=VALUES(primaryBusiness),  secondaryBusiness=VALUES(secondaryBusiness)";
             }
             $query = $this->getConnection()->prepare($sql);
             $query->bindValue(":id", $entity->getID(), PDO::PARAM_INT);
             $query->bindValue(":name", $entity->getName(), PDO::PARAM_STR);
             $query->bindValue(":date", strval($entity->getDate()), PDO::PARAM_STR);
             $query->bindValue(":contact", $entity->getAddress(), PDO::PARAM_STR);
             if (strcasecmp($type, 'extractive-company') == 0) {
                 $query->bindValue(":capital", $entity->getCapital(), PDO::PARAM_INT);
                 $query->bindValue(":primary", $entity->getPrimaryBusiness(), PDO::PARAM_STR);
                 $query->bindValue(":secondary", $entity->getSecondaryBusiness(), PDO::PARAM_STR);
             }
             if ($query->execute()) {
                 if (strcasecmp($type, 'govt-entity') == 0) {
                     $entityID = $this->getConnection()->lastInsertId();
                     $tpin = null;
                     $sql = "DELETE t FROM goventity_templates t WHERE t.entityID = {$entityID};";
                     $stmt = $this->getConnection()->prepare($sql);
                     //return $stmt;
                     $stmt->execute();
                     if ($this->setEntityTemplates($entity->getTemplates(), $entityID, "gov_entity") && ($groupID = $this->addDefaultGroups($entityID, "gov_entity"))) {
                         $this->getConnection()->commit();
                         if ($user) {
                             $user->groupID = $groupID;
                             $user->entityID = $entityID;
                             $user->TPIN = $tpin;
                             $user = (new MUDBAccess())->addUser($user);
                             if (!$user['success']) {
                                 return $user;
                             }
                         }
                         return $this->getEntities();
                     }
                 } else {
                     $entityID = null;
                     $tpin = $entity->getID();
                     $sql = "DELETE t FROM extractivecomp_templates t WHERE t.TPIN = {$tpin};";
                     $stmt = $this->getConnection()->prepare($sql);
                     //return $stmt;
                     if ($stmt->execute() && $this->setEntityTemplates($entity->getTemplates(), $tpin, "extractive") && ($groupID = $this->addDefaultGroups($tpin, "extractive"))) {
                         $this->getConnection()->commit();
                         if ($user) {
                             $user->groupID = $groupID;
                             $user->entityID = $entityID;
                             $user->TPIN = $tpin;
                             $user->password = "******";
                             $user->validatePassword = "******";
                             $user = (new MUDBAccess())->addUser($user);
                             if (!$user['success']) {
                                 $url = ZP::$url;
                                 Mail::send(['name' => $user->name, 'email' => $user->email], "<p>ZEITI User Account Created</p>", "<p>Your user account has been created.</p>" . "<p>Your login detail are as follows;</p>" . "<p>Email Address: {$user->email}</p>" . "<p>Password: P@55word!</p>" . "<p><br/><a href='{$url}'>Login to the portal here</a></p>");
                                 return $user;
                             }
                         }
                         return $this->getEntities();
                     }
                 }
             }
             return ['success' => false, 'entity' => $entity, "exception" => "Could not add entity"];
         } catch (\PDOException $e) {
             $this->getConnection()->rollBack();
             return ['success' => false, "exception" => $e];
         }
     } else {
         return ['success' => false, "errors" => $entity->getErrors()];
     }
 }
コード例 #2
0
ファイル: index_old.php プロジェクト: ZeitiPortal/ZeitiPortal
<?php

require "core/Mail.php";
//\ZP\Mail::send("*****@*****.**", "CC Message", "Hi William, This is a test message", "*****@*****.**");
$code = "abcde";
$url = \ZP\ZP::$url;
$email = "*****@*****.**";
$message = "<p>Please click on the link below to reset your password.</p>" . "<p><a href='{$url}/core/loginfacade.php?auth=true&action=changepassword&code={$code}'>Reset Password</a> </p><br/>" . "<p style='font-weight: bold;'>If you did not request a password reset, please just ignore this message.</p>";
\ZP\Mail::send($email, 'Password Reset', $message);
コード例 #3
0
 public function resetPassword($password, $re_enter, $code)
 {
     if (!ZP::isPassword($password)) {
         return (object) ['success' => false, 'exception' => 'Please specify a strong password.'];
     } else {
         if (strcmp($password, $re_enter) != 0) {
             return (object) ['success' => false, 'exception' => 'Passwords do not match.'];
         }
     }
     try {
         $query = $this->getConnection()->prepare("CALL reset_password(:password, :code)");
         $query->bindValue(":password", password_hash($password, PASSWORD_BCRYPT));
         $query->bindValue(":code", $code, PDO::PARAM_INT);
         if ($query->execute()) {
             // send email to $email that password has been changed
             $result = $query->fetch(PDO::FETCH_OBJ);
             if ($result->success) {
                 unset($_SESSION['code']);
                 $url = ZP::$url;
                 $message = "<p>Your password has been successfully been reset. Please click on the link below login to the portal.</p>" . "<p><a href='{$url}'>ZEITI Portal</a> </p><br/>";
                 //. "<p style='font-weight: bold;'>If you did not request a password reset, please just ignore this message.</p>";
                 Mail::send($result->email, 'Password Reset Successful', $message);
                 unset($result->email);
             } else {
                 $url = ZP::$url;
                 $message = "<p>{$result->message}.</p>" . "<p><a href='{$url}/core/reset.php'>Reset Password</a> </p><br/>" . "<p style='font-weight: bold;'>If you did not request a password reset, please just ignore this message.</p>";
                 Mail::send($result->email, 'Password Reset', $message);
             }
             //print_r($result);
             //exit(json_encode($result));
             return $result;
         }
         return (object) ["success" => false, 'exception' => "Password not changed."];
     } catch (\PDOException $e) {
         return (object) ['success' => false, 'exception' => $e];
     }
 }