Exemple #1
0
 public static function updatePassword($token, $oldPassword, $newPassword)
 {
     if ($oldPassword == $newPassword) {
         throw new \Exception("Please insert different password with old password");
     } else {
         if ($token == null or $token == "") {
             throw new \Exception("Session expired, please re-login");
         } else {
             if ($oldPassword == null or $oldPassword == "") {
                 throw new \Exception("Invalid old password");
             } else {
                 if ($newPassword == null or $newPassword == "") {
                     throw new \Exception("New password must be not empty!");
                 }
             }
         }
     }
     $user = User::query()->where('token', '=', $token)->where('password', '=', md5($oldPassword))->first();
     if ($user == null) {
         throw new \Exception("Invalid password");
     } else {
         $user->password = md5($newPassword);
         $user->save();
         return "Password updated.";
     }
 }
 public static function del($token, $id)
 {
     if ($token == null or $token == "") {
         throw new \Exception("Session expired, please re-login");
     }
     $userId = User::query()->where('token', '=', $token)->first()->id;
     if ($userId == null or $userId == "") {
         throw new \Exception("Session expired, please re-login");
     }
     $comment = Comment::find($id);
     if ($comment == null) {
         throw new \Exception("Invalid comment item");
     }
     if ($comment->delete()) {
         return "Comment item has ben deleted";
     } else {
         return "Error while deleting comment";
     }
 }