Ejemplo n.º 1
0
 function setPersonalInfo($firstName, $lastName, $birthDate)
 {
     $errors = [];
     if (empty($firstName)) {
         $errors[] = "FirstName is required";
     } else {
         if (strlen($firstName) < 2 || strlen($firstName) > 30) {
             $errors[] = "FirstName must be between 2 and 30";
         }
     }
     if (empty($lastName)) {
         $errors[] = "LastName is required";
     } else {
         if (strlen($lastName) < 2 || strlen($lastName) > 30) {
             $errors[] = "LastName must be between 2 and 30";
         }
     }
     if (empty($birthDate)) {
         $errors[] = "BirthDate is required";
     }
     if (!empty($errors)) {
         $ex = new SiteException('Personal info change failed');
         $ex->setErrors($errors);
         throw $ex;
     } else {
         $user = UsersPDO::get($this->userName);
         if ($user['PersonId'] == null) {
             $personId = PersonsPDO::add($firstName, $lastName, $birthDate);
             UsersPDO::setPersonId($this->userName, $personId);
         } else {
             $personId = $user['PersonId'];
             PersonsPDO::update($personId, $firstName, $lastName, $birthDate);
         }
     }
 }
Ejemplo n.º 2
0
 public static function changePassword($password, $confirm)
 {
     $errors = [];
     if (empty($password)) {
         $errors[] = 'Password is required';
     } else {
         if (strlen($password) < 4 || strlen($password) > 50) {
             $errors[] = 'Password length must me between 4 and 50';
         } else {
             if (empty($confirm)) {
                 $errors[] = 'Password confirmation is required';
             } else {
                 if ($confirm != $password) {
                     $errors[] = 'Password confirmation is wrong';
                 } else {
                     UsersPDO::setPassword(self::getUserName(), $password);
                 }
             }
         }
     }
     if (!empty($errors)) {
         $ex = new SiteException('Password Change Exception');
         $ex->setErrors($errors);
         throw $ex;
     }
 }